line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Intersection::StraightLine; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20481
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
113
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1288
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new{ |
9
|
1
|
|
|
1
|
1
|
404
|
my ($class) = @_; |
10
|
1
|
|
|
|
|
3
|
my $self = {}; |
11
|
1
|
|
|
|
|
4
|
bless $self,$class; |
12
|
1
|
|
|
|
|
3
|
return $self; |
13
|
|
|
|
|
|
|
}# new |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub functions{ |
16
|
1
|
|
|
1
|
1
|
393
|
my ($self,$f_one,$f_two) = @_; |
17
|
1
|
|
|
|
|
2
|
my $factor = 3; |
18
|
1
|
|
|
|
|
6
|
my $line_one = [ |
19
|
|
|
|
|
|
|
[0,$f_one->[1]], |
20
|
|
|
|
|
|
|
[$factor,($f_one->[0] * $factor) + $f_one->[1]], |
21
|
|
|
|
|
|
|
]; |
22
|
1
|
|
|
|
|
4
|
my $line_two = [ |
23
|
|
|
|
|
|
|
[0,$f_two->[1]], |
24
|
|
|
|
|
|
|
[$factor,($f_two->[0] * $factor) + $f_two->[1]], |
25
|
|
|
|
|
|
|
]; |
26
|
1
|
|
|
|
|
3
|
return $self->points($line_one,$line_two); |
27
|
|
|
|
|
|
|
}# function |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub vectors{ |
30
|
10
|
|
|
10
|
1
|
646
|
my ($self,$vector_one,$vector_two) = @_; |
31
|
10
|
|
|
|
|
33
|
my @equation_one = ($vector_one->[0]->[0],$vector_one->[1]->[0], |
32
|
|
|
|
|
|
|
$vector_two->[0]->[0],$vector_two->[1]->[0],); |
33
|
10
|
|
|
|
|
31
|
my @equation_two = ($vector_one->[0]->[1],$vector_one->[1]->[1], |
34
|
|
|
|
|
|
|
$vector_two->[0]->[1],$vector_two->[1]->[1],); |
35
|
10
|
|
|
|
|
32
|
my $factor_one = $vector_two->[1]->[1]; |
36
|
10
|
|
|
|
|
17
|
my $factor_two = $vector_two->[1]->[0]; |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
21
|
for(@equation_one){ |
39
|
40
|
|
|
|
|
72
|
$_ *= $factor_one; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
10
|
|
|
|
|
22
|
for(@equation_two){ |
43
|
40
|
|
|
|
|
150
|
$_ *= $factor_two; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
15
|
my @result_equation; |
47
|
10
|
|
|
|
|
22
|
for(0..3){ |
48
|
40
|
|
|
|
|
79
|
push(@result_equation,$equation_one[$_] - $equation_two[$_]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
10
|
|
|
|
|
14
|
my $point = undef; |
52
|
|
|
|
|
|
|
|
53
|
10
|
100
|
|
|
|
28
|
if($result_equation[1] != 0){ |
54
|
6
|
|
|
|
|
8
|
my $constant = $result_equation[2] - $result_equation[0]; |
55
|
6
|
|
|
|
|
13
|
my $lambda = $constant / $result_equation[1]; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
31
|
$point = [$vector_one->[0]->[0] + ($vector_one->[1]->[0] * $lambda), |
58
|
|
|
|
|
|
|
$vector_one->[0]->[1] + ($vector_one->[1]->[1] * $lambda),]; |
59
|
|
|
|
|
|
|
} |
60
|
10
|
100
|
|
|
|
25
|
if(_check_parallel_vectors($vector_one,$vector_two)){ |
61
|
4
|
100
|
|
|
|
11
|
if(defined _check_point_on_vector($vector_one,$vector_two->[0])){ |
62
|
1
|
|
|
|
|
2
|
$point = -1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else{ |
65
|
3
|
|
|
|
|
5
|
$point = 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
10
|
|
|
|
|
36
|
return $point; |
69
|
|
|
|
|
|
|
}# vectors |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub point_limited{ |
72
|
5
|
|
|
5
|
1
|
2980
|
my ($self,$line_one,$line_two) = @_; |
73
|
5
|
|
|
|
|
12
|
my @coords_one = @$line_one; |
74
|
5
|
|
|
|
|
10
|
my @coords_two = @$line_two; |
75
|
5
|
|
|
|
|
25
|
my $vector_one = [$coords_one[0],[$coords_one[0]->[0] - $coords_one[1]->[0], |
76
|
|
|
|
|
|
|
$coords_one[0]->[1] - $coords_one[1]->[1]]]; |
77
|
5
|
|
|
|
|
20
|
my $vector_two = [$coords_two[0],[$coords_two[0]->[0] - $coords_two[1]->[0], |
78
|
|
|
|
|
|
|
$coords_two[0]->[1] - $coords_two[1]->[1]]]; |
79
|
5
|
|
|
|
|
14
|
my $result = $self->vectors($vector_one,$vector_two); |
80
|
5
|
|
|
|
|
8
|
my $return = 0; |
81
|
5
|
100
|
66
|
|
|
47
|
if(defined $result && ref($result) eq 'ARRAY' && |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
82
|
|
|
|
|
|
|
_check_point_on_line($vector_one,$result) && |
83
|
|
|
|
|
|
|
_check_point_on_line($vector_two,$result)){ |
84
|
2
|
|
|
|
|
5
|
$return = $result; |
85
|
|
|
|
|
|
|
} |
86
|
5
|
50
|
|
|
|
13
|
if(_check_overlapping_lines($line_one,$line_two,$vector_one,$vector_two)){ |
87
|
0
|
|
|
|
|
0
|
$return = -1; |
88
|
|
|
|
|
|
|
} |
89
|
5
|
|
|
|
|
27
|
return $return; |
90
|
|
|
|
|
|
|
}# point_limited |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub points{ |
94
|
2
|
|
|
2
|
1
|
286
|
my ($self,$line_one,$line_two) = @_; |
95
|
2
|
|
|
|
|
6
|
my @coords_one = @$line_one; |
96
|
2
|
|
|
|
|
5
|
my @coords_two = @$line_two; |
97
|
2
|
|
|
|
|
9
|
my $vector_one = [$coords_one[0],[$coords_one[0]->[0] - $coords_one[1]->[0], |
98
|
|
|
|
|
|
|
$coords_one[0]->[1] - $coords_one[1]->[1]]]; |
99
|
2
|
|
|
|
|
8
|
my $vector_two = [$coords_two[0],[$coords_two[0]->[0] - $coords_two[1]->[0], |
100
|
|
|
|
|
|
|
$coords_two[0]->[1] - $coords_two[1]->[1]]]; |
101
|
2
|
|
|
|
|
658
|
my $result = $self->vectors($vector_one,$vector_two); |
102
|
2
|
|
|
|
|
3
|
my $return = 0; |
103
|
2
|
50
|
33
|
|
|
14
|
if(defined $result && ref($result) eq 'ARRAY'){ |
104
|
2
|
|
|
|
|
3
|
$return = $result; |
105
|
|
|
|
|
|
|
} |
106
|
2
|
50
|
|
|
|
5
|
if(_check_overlapping_lines($line_one,$line_two,$vector_one,$vector_two)){ |
107
|
0
|
|
|
|
|
0
|
$return = -1; |
108
|
|
|
|
|
|
|
} |
109
|
2
|
|
|
|
|
13
|
return $return; |
110
|
|
|
|
|
|
|
}# points |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _check_point_on_line{ |
113
|
33
|
|
|
33
|
|
49
|
my ($vector,$point) = @_; |
114
|
33
|
|
|
|
|
39
|
my $return = 1; |
115
|
|
|
|
|
|
|
|
116
|
33
|
|
|
|
|
62
|
my $check = _check_point_on_vector($vector,$point); |
117
|
33
|
100
|
66
|
|
|
121
|
if(!defined $check || $check > 0 || $check < -1){ |
|
|
|
100
|
|
|
|
|
118
|
29
|
|
|
|
|
41
|
$return = 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
33
|
|
|
|
|
232
|
return $return; |
122
|
|
|
|
|
|
|
}# _check_point_on_line |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _check_overlapping_lines{ |
125
|
7
|
|
|
7
|
|
15
|
my ($line_one,$line_two,$vector_one,$vector_two) = @_; |
126
|
7
|
|
|
|
|
10
|
my $return = 0; |
127
|
7
|
50
|
33
|
|
|
15
|
if(_check_point_on_line($vector_one,$line_two->[0]) || |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
128
|
|
|
|
|
|
|
_check_point_on_line($vector_one,$line_two->[1]) || |
129
|
|
|
|
|
|
|
_check_point_on_line($vector_two,$line_one->[0]) || |
130
|
|
|
|
|
|
|
_check_point_on_line($vector_two,$line_one->[1])){ |
131
|
0
|
|
|
|
|
0
|
$return = 1; |
132
|
|
|
|
|
|
|
} |
133
|
7
|
|
|
|
|
22
|
return $return; |
134
|
|
|
|
|
|
|
}# _check_overlapping_lines |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _check_parallel_vectors{ |
137
|
10
|
|
|
10
|
|
17
|
my ($vector_one,$vector_two) = @_; |
138
|
10
|
|
|
|
|
16
|
my $return = 0; |
139
|
10
|
|
|
|
|
19
|
for(0,1){ |
140
|
20
|
100
|
66
|
|
|
138
|
if(($vector_one->[1]->[0] == 0 && $vector_two->[1]->[0] == 0) || |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
141
|
|
|
|
|
|
|
($vector_one->[1]->[1] == 0 && $vector_two->[1]->[1] == 0)){ |
142
|
2
|
|
|
|
|
5
|
$return = 1; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else{ |
145
|
18
|
100
|
66
|
|
|
79
|
unless($vector_two->[1]->[0] == 0 || $vector_two->[1]->[1] == 0){ |
146
|
8
|
|
|
|
|
17
|
my $quot_one = $vector_one->[1]->[0] / $vector_two->[1]->[0]; |
147
|
8
|
|
|
|
|
16
|
my $quot_two = $vector_one->[1]->[1] / $vector_two->[1]->[1]; |
148
|
8
|
100
|
|
|
|
23
|
if($quot_one == $quot_two){ |
149
|
6
|
|
|
|
|
15
|
$return = 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
10
|
|
|
|
|
51
|
return $return; |
155
|
|
|
|
|
|
|
}# _check_parallel_vectors |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _check_point_on_vector{ |
158
|
37
|
|
|
37
|
|
51
|
my ($vector,$point) = @_; |
159
|
37
|
|
|
|
|
46
|
my $return = undef; |
160
|
37
|
|
|
|
|
42
|
my $tmp_check = undef; |
161
|
37
|
|
|
|
|
68
|
for(0,1){ |
162
|
61
|
100
|
100
|
|
|
266
|
if($vector->[1]->[$_] == 0 && ($point->[$_] != $vector->[0]->[$_])){ |
|
|
100
|
|
|
|
|
|
163
|
15
|
|
|
|
|
19
|
$return = 0; |
164
|
15
|
|
|
|
|
25
|
last; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
elsif($vector->[1]->[$_] != 0){ |
167
|
43
|
|
|
|
|
95
|
my $check = ($point->[$_] - $vector->[0]->[$_]) / $vector->[1]->[$_]; |
168
|
43
|
100
|
|
|
|
106
|
unless(defined $tmp_check){ |
|
|
100
|
|
|
|
|
|
169
|
24
|
|
|
|
|
66
|
$tmp_check = $check; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
elsif(abs($tmp_check - $check) > 0.00001){ |
172
|
16
|
|
|
|
|
42
|
$return = 0; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
37
|
100
|
66
|
|
|
158
|
if(defined $return && $return == 0){ |
|
|
50
|
|
|
|
|
|
177
|
31
|
|
|
|
|
44
|
$return = undef; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
elsif(! defined $return){ |
180
|
6
|
|
|
|
|
10
|
$return = $tmp_check; |
181
|
|
|
|
|
|
|
} |
182
|
37
|
|
|
|
|
298
|
return $return; |
183
|
|
|
|
|
|
|
}# _check_point_on_vector |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
__END__ |