line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::SpatialIndex; |
2
|
9
|
|
|
9
|
|
218571
|
use 5.008001; |
|
9
|
|
|
|
|
35
|
|
|
9
|
|
|
|
|
337
|
|
3
|
9
|
|
|
9
|
|
52
|
use strict; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
326
|
|
4
|
9
|
|
|
9
|
|
57
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
383
|
|
5
|
9
|
|
|
9
|
|
129
|
use Carp qw(croak); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
1307
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Module::Pluggable ( |
10
|
9
|
|
|
|
|
81
|
sub_name => 'strategies', |
11
|
|
|
|
|
|
|
search_path => [__PACKAGE__ . "::Strategy"], |
12
|
|
|
|
|
|
|
require => 1, |
13
|
|
|
|
|
|
|
inner => 0, |
14
|
9
|
|
|
9
|
|
8633
|
); |
|
9
|
|
|
|
|
130307
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Module::Pluggable ( |
17
|
9
|
|
|
|
|
49
|
sub_name => 'storage_backends', |
18
|
|
|
|
|
|
|
search_path => [__PACKAGE__ . "::Storage"], |
19
|
|
|
|
|
|
|
require => 1, |
20
|
|
|
|
|
|
|
inner => 0, |
21
|
9
|
|
|
9
|
|
1486
|
); |
|
9
|
|
|
|
|
23
|
|
22
|
|
|
|
|
|
|
|
23
|
9
|
|
|
9
|
|
7358
|
use Algorithm::SpatialIndex::Node; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
340
|
|
24
|
9
|
|
|
9
|
|
6487
|
use Algorithm::SpatialIndex::Bucket; |
|
9
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
330
|
|
25
|
9
|
|
|
9
|
|
5323
|
use Algorithm::SpatialIndex::Strategy; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
245
|
|
26
|
9
|
|
|
9
|
|
86
|
use Algorithm::SpatialIndex::Storage; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
297
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Class::XSAccessor { |
29
|
9
|
|
|
|
|
63
|
getters => [qw( |
30
|
|
|
|
|
|
|
strategy |
31
|
|
|
|
|
|
|
storage |
32
|
|
|
|
|
|
|
limit_x_low |
33
|
|
|
|
|
|
|
limit_x_up |
34
|
|
|
|
|
|
|
limit_y_low |
35
|
|
|
|
|
|
|
limit_y_up |
36
|
|
|
|
|
|
|
limit_z_low |
37
|
|
|
|
|
|
|
limit_z_up |
38
|
|
|
|
|
|
|
bucket_size |
39
|
|
|
|
|
|
|
max_depth |
40
|
|
|
|
|
|
|
)], |
41
|
9
|
|
|
9
|
|
45
|
}; |
|
9
|
|
|
|
|
13
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
5
|
|
|
5
|
1
|
104
|
my $class = shift; |
45
|
5
|
|
|
|
|
42
|
my %opt = @_; |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
70
|
my $self = bless { |
48
|
|
|
|
|
|
|
limit_x_low => -100, |
49
|
|
|
|
|
|
|
limit_x_up => 100, |
50
|
|
|
|
|
|
|
limit_y_low => -100, |
51
|
|
|
|
|
|
|
limit_y_up => 100, |
52
|
|
|
|
|
|
|
limit_z_low => -100, |
53
|
|
|
|
|
|
|
limit_z_up => 100, |
54
|
|
|
|
|
|
|
bucket_size => 100, |
55
|
|
|
|
|
|
|
max_depth => 20, |
56
|
|
|
|
|
|
|
%opt, |
57
|
|
|
|
|
|
|
} => $class; |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
30
|
$self->_init_strategy(\%opt); |
60
|
3
|
|
|
|
|
17
|
$self->_init_storage(\%opt); |
61
|
3
|
|
|
|
|
42
|
$self->strategy->_set_storage($self->storage); |
62
|
3
|
|
|
|
|
30
|
$self->strategy->_super_init_storage(); |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
12
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _init_strategy { |
68
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
69
|
5
|
|
|
|
|
11
|
my $opt = shift; |
70
|
5
|
|
|
|
|
16
|
my $strategy = $opt->{strategy}; |
71
|
|
|
|
|
|
|
|
72
|
5
|
50
|
|
|
|
19
|
croak("Need strategy") if not defined $strategy; |
73
|
5
|
|
|
|
|
37
|
my @strategies = grep /\b\Q$strategy\E$/, $self->strategies; |
74
|
5
|
100
|
|
|
|
1725
|
if (@strategies == 0) { |
|
|
50
|
|
|
|
|
|
75
|
2
|
|
|
|
|
889
|
croak("Could not find specified strategy '$strategy'. Available strategies: " . join(', ', @strategies)); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif (@strategies > 1) { |
78
|
0
|
|
|
|
|
0
|
croak("Found multiple matching strategy for '$strategy': " . join(', ', @strategies)); |
79
|
|
|
|
|
|
|
} |
80
|
3
|
|
|
|
|
8
|
$strategy = shift @strategies; |
81
|
3
|
|
|
|
|
51
|
$self->{strategy} = $strategy->new(%$opt, index => $self); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _init_storage { |
85
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
86
|
3
|
|
|
|
|
6
|
my $opt = shift; |
87
|
3
|
|
|
|
|
7
|
my $storage = $opt->{storage}; |
88
|
|
|
|
|
|
|
|
89
|
3
|
50
|
|
|
|
12
|
croak("Need storage") if not defined $storage; |
90
|
3
|
|
|
|
|
17
|
my @storage_backends = grep /\b\Q$storage\E$/, $self->storage_backends; |
91
|
3
|
50
|
|
|
|
620
|
if (@storage_backends == 0) { |
|
|
50
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
croak("Could not find specified storage backends '$storage'"); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif (@storage_backends > 1) { |
95
|
0
|
|
|
|
|
0
|
croak("Found multiple matching storage backends for '$storage': " . join(', ', @storage_backends)); |
96
|
|
|
|
|
|
|
} |
97
|
3
|
|
|
|
|
6
|
$storage = shift @storage_backends; |
98
|
3
|
|
|
|
|
39
|
$self->{storage} = $storage->new(index => $self, opt => $opt); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub insert { |
102
|
383
|
|
|
383
|
1
|
15167
|
my $self = shift; |
103
|
383
|
|
|
|
|
1217
|
return $self->{strategy}->insert(@_); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_items_in_rect { |
107
|
4
|
|
|
4
|
1
|
2490
|
my ($self, @rect) = @_; |
108
|
4
|
|
|
|
|
27
|
my $strategy = $self->strategy; |
109
|
4
|
|
|
|
|
17
|
return $strategy->filter_items_in_rect(@rect, $strategy->find_nodes_for(@rect)); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |