| 1 | package SVG::Graph::Glyph::bezier; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base SVG::Graph::Glyph; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Math::Spline; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | =head2 draw | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | Title : draw | ||||||||||||||||||||||||||||||||
| 10 | Usage : | ||||||||||||||||||||||||||||||||
| 11 | Function: | ||||||||||||||||||||||||||||||||
| 12 | Example : | ||||||||||||||||||||||||||||||||
| 13 | Returns : | ||||||||||||||||||||||||||||||||
| 14 | Args : | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub draw{ | ||||||||||||||||||||||||||||||
|
Subroutine
draw: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 1 | my ($self,@args) = @_; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 1 | my $id = 'n'.sprintf("%07d",int(rand(9999999))); | |||||||||||||||||||||||||||||||
| 23 | 1 | my $group = $self->svg->group(id=>"bezier$id"); | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 1 | my $xscale = $self->xsize / $self->group->xrange; | |||||||||||||||||||||||||||||||
| 26 | 1 | my $yscale = $self->ysize / $self->group->yrange; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | my @p = map {[$_->x,$_->y]} sort {$a->x <=> $b->x} $self->group->data; | |||||||||||||||||||||||||||||||
| 30 | 1 | my $c = spline_generate(@p); | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 1 | my @c; | |||||||||||||||||||||||||||||||
| 33 | 1 | foreach my $i (1..$#p){ | |||||||||||||||||||||||||||||||
| 34 | 19 | my($x1,$y1) = @{$p[$i-1]}; | |||||||||||||||||||||||||||||||
| 35 | 19 | my($x2,$y2) = @{$p[$i] }; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 19 | my $e = 0; | |||||||||||||||||||||||||||||||
| 38 | 19 | my($cx,$cy,$cx_sum,$cy_sum); | |||||||||||||||||||||||||||||||
| 39 | 19 | ▶ | for(my $d = 2; $d <= 100 ; $d += 2){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 950 | ▶ | next if $d == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 950 | my $delta = ($x2 - $x1) / $d; | |||||||||||||||||||||||||||||||
| 42 | 950 | my $y1d = spline_evaluate($x1+$delta,$c,@p); | |||||||||||||||||||||||||||||||
| 43 | 950 | my $y2d = spline_evaluate($x2-$delta,$c,@p); | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 950 | my($int,$t1,$t2) = Intersection(Segment([$x1,$y1],[$x1+$delta,$y1d]),Segment([$x2-$delta,$y2d],[$x2,$y2])); | |||||||||||||||||||||||||||||||
| 46 | 950 | ▶ | next unless ref($int); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | 44 | ▶ | next unless $x1 <= $int->[0] and $x2 >= $int->[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$x1 <= $int->[0] and $x2 >= $int->[0]
MC/DC50%1/2
$x1 <= $int->[0] and $x2 >= $int->[0]
$x1 <= $int->[0]
$x2 >= $int->[0]
Truth table66%2/3
A and B
A= $x1 <= $int->[0]B= $x2 >= $int->[0]
| |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 30 | $e++; | |||||||||||||||||||||||||||||||
| 50 | 30 | $cx_sum += $int->[0]; | |||||||||||||||||||||||||||||||
| 51 | 30 | $cy_sum += $int->[1]; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 19 | $x1 = (($x1 - $self->group->xmin) * $xscale) + $self->xoffset; | |||||||||||||||||||||||||||||||
| 55 | 19 | $y1 = ($self->ysize - ($y1 - $self->group->ymin) * $yscale) + $self->yoffset; | |||||||||||||||||||||||||||||||
| 56 | 19 | $x2 = (($x2 - $self->group->xmin) * $xscale) + $self->xoffset; | |||||||||||||||||||||||||||||||
| 57 | 19 | $y2 = ($self->ysize - ($y2 - $self->group->ymin) * $yscale) + $self->yoffset; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | #warn $cx_sum,"\t",$e; | ||||||||||||||||||||||||||||||||
| 60 | #next unless $e; | ||||||||||||||||||||||||||||||||
| 61 | 19 | ▶ | if($e){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 1 | $cx = $cx_sum / $e; | |||||||||||||||||||||||||||||||
| 63 | 1 | $cy = $cy_sum / $e; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 1 | $cx = (($cx - $self->group->xmin) * $xscale) + $self->xoffset; | |||||||||||||||||||||||||||||||
| 66 | 1 | $cy = ($self->ysize - ($cy - $self->group->ymin) * $yscale) + $self->yoffset; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 1 | $group->path(d=>"M$x1,$y1 Q$cx,$cy $x2,$y2", | |||||||||||||||||||||||||||||||
| 69 | style=>{$self->_style}, | ||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||
| 72 | 18 | $group->line(x1=>$x1,y1=>$y1,x2=>$x2,y2=>$y2,style=>{$self->_style}); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =head2 spline_generate | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | Title : spline_generate | ||||||||||||||||||||||||||||||||
| 82 | Usage : | ||||||||||||||||||||||||||||||||
| 83 | Function: | ||||||||||||||||||||||||||||||||
| 84 | Example : | ||||||||||||||||||||||||||||||||
| 85 | Returns : | ||||||||||||||||||||||||||||||||
| 86 | Args : | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | sub spline_generate{ | ||||||||||||||||||||||||||||||
|
Subroutine
spline_generate: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 92 | 1 | my (@points) = @_; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 1 | my ($i, $delta, $temp, @factors, @coeffs); | |||||||||||||||||||||||||||||||
| 95 | 1 | $coeffs[0] = $factors[0] = 0; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # Decomposition phase of the tridiagonal system of equations | ||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | for ($i = 1; $i < @points - 1; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | #ad | ||||||||||||||||||||||||||||||||
| 101 | 18 | ▶ | next unless ($points[$i+1][0] - $points[$i-1][0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 2 | $delta = ($points[$i][0] - $points[$i-1][0]) / (($points[$i+1][0] - $points[$i-1][0])); | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | $temp = $delta * ($coeffs[$i-1] || 0) + 2; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$coeffs[$i - 1] || 0
MC/DC100%1/1
$coeffs[$i - 1] || 0
$coeffs[$i - 1]
Truth table100%2/2
A
A= $coeffs[$i - 1]
| |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 2 | $coeffs[$i] = ($delta - 1) / @points; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | #ad | ||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | next unless ($points[$i+1][0] - $points[$i][0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | next unless ($points[$i][0] - $points[$i-1][0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 0 | $factors[$i] = ($points[$i+1][1] - $points[$i][1]) / (($points[$i+1][0] - $points[$i][0])) | |||||||||||||||||||||||||||||||
| 116 | - | ||||||||||||||||||||||||||||||||
| 117 | ($points[$i][1] - $points[$i-1][1]) / (($points[$i][0] - $points[$i-1][0])); | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 0 | $factors[$i] = ( 6 * $factors[$i] / (($points[$i+1][0] - $points[$i-1][0])) | |||||||||||||||||||||||||||||||
| 121 | - | ||||||||||||||||||||||||||||||||
| 122 | $delta * $factors[$i-1] ) / $temp; | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | # Backsubstitution phase of the tridiagonal system | ||||||||||||||||||||||||||||||||
| 126 | # | ||||||||||||||||||||||||||||||||
| 127 | 1 | $coeffs[$#points] = 0; | |||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | for ($i = @points - 2; $i >= 0; $i--) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 19 | ▶ | $coeffs[$i] = ($coeffs[$i] || 0) * ($coeffs[$i+1] || 0) + ($factors[$i] || 0); | ||||||||||||||||||||||||||||||
|
Condition66%4/6
$coeffs[$i] || 0
$coeffs[$i + 1] || 0
$factors[$i] || 0
MC/DC100%1/1
$coeffs[$i] || 0
$coeffs[$i]
MC/DC0%0/1
$coeffs[$i + 1] || 0
$coeffs[$i + 1]
MC/DC0%0/1
$factors[$i] || 0
$factors[$i]
Truth table100%2/2
A
A= $coeffs[$i]
Truth table50%1/2
A
A= $coeffs[$i + 1]
Truth table50%1/2
A
A= $factors[$i]
| |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | 1 | return \@coeffs; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =head2 spline_evaluate | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | Title : spline_evaluate | ||||||||||||||||||||||||||||||||
| 137 | Usage : | ||||||||||||||||||||||||||||||||
| 138 | Function: | ||||||||||||||||||||||||||||||||
| 139 | Example : | ||||||||||||||||||||||||||||||||
| 140 | Returns : | ||||||||||||||||||||||||||||||||
| 141 | Args : | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 1900 | ▶ | sub spline_evaluate{ | ||||||||||||||||||||||||||||||
|
Subroutine
spline_evaluate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 147 | 1900 | my ($x, $coeffs, @points) = @_; | |||||||||||||||||||||||||||||||
| 148 | 1900 | my ($i, $delta, $mult); | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | # Which section of the spline are we in? | ||||||||||||||||||||||||||||||||
| 151 | # | ||||||||||||||||||||||||||||||||
| 152 | 1900 | ▶ | for ($i = @points - 2; $i >= 1; $i--) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 10900 | ▶ | last if $x >= $points[$i][0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 1900 | $delta = $points[$i+1][0] - $points[$i][0]; | |||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | #ad | ||||||||||||||||||||||||||||||||
| 159 | 1900 | ▶ | return 0 unless $delta; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 1000 | $mult = ( $coeffs->[$i]/2 ) + ($x - $points[$i][0]) * ($coeffs->[$i+1] - $coeffs->[$i]) / (6 * $delta); | |||||||||||||||||||||||||||||||
| 162 | 1000 | $mult *= $x - $points[$i][0]; | |||||||||||||||||||||||||||||||
| 163 | 1000 | $mult += ($points[$i+1][1] - $points[$i][1]) / ($delta); | |||||||||||||||||||||||||||||||
| 164 | 1000 | $mult -= ($coeffs->[$i+1] + 2 * $coeffs->[$i]) * $delta / 6; | |||||||||||||||||||||||||||||||
| 165 | 1000 | return $points[$i][1] + $mult * ($x - $points[$i][0]); | |||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | =head2 Segment | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | Title : Segment | ||||||||||||||||||||||||||||||||
| 171 | Usage : | ||||||||||||||||||||||||||||||||
| 172 | Function: | ||||||||||||||||||||||||||||||||
| 173 | Example : | ||||||||||||||||||||||||||||||||
| 174 | Returns : | ||||||||||||||||||||||||||||||||
| 175 | Args : | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 1900 | ▶ | sub Segment { | ||||||||||||||||||||||||||||||
|
Subroutine
Segment: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 181 | 1900 | [ $_[0], $_[1] ]; | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | =head2 VectorSum | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | Title : VectorSum | ||||||||||||||||||||||||||||||||
| 187 | Usage : | ||||||||||||||||||||||||||||||||
| 188 | Function: | ||||||||||||||||||||||||||||||||
| 189 | Example : | ||||||||||||||||||||||||||||||||
| 190 | Returns : | ||||||||||||||||||||||||||||||||
| 191 | Args : | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 1944 | ▶ | sub VectorSum { | ||||||||||||||||||||||||||||||
|
Subroutine
VectorSum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 197 | 1944 | my ($x, $y) = (0, 0); | |||||||||||||||||||||||||||||||
| 198 | 1944 | for (@_) { | |||||||||||||||||||||||||||||||
| 199 | 3888 | $x += $_->[0]; | |||||||||||||||||||||||||||||||
| 200 | 3888 | $y += $_->[1]; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | 1944 | [ $x, $y ]; | |||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | =head2 ScalarProd | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | Title : ScalarProd | ||||||||||||||||||||||||||||||||
| 208 | Usage : | ||||||||||||||||||||||||||||||||
| 209 | Function: | ||||||||||||||||||||||||||||||||
| 210 | Example : | ||||||||||||||||||||||||||||||||
| 211 | Returns : | ||||||||||||||||||||||||||||||||
| 212 | Args : | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | 44 | ▶ | sub ScalarProd { | ||||||||||||||||||||||||||||||
|
Subroutine
ScalarProd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 218 | 44 | my $s = shift; | |||||||||||||||||||||||||||||||
| 219 | 44 | my $v = shift; | |||||||||||||||||||||||||||||||
| 220 | 44 | [ $v->[0] * $s, $v->[1] * $s ]; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | =head2 Minus | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | Title : Minus | ||||||||||||||||||||||||||||||||
| 226 | Usage : | ||||||||||||||||||||||||||||||||
| 227 | Function: | ||||||||||||||||||||||||||||||||
| 228 | Example : | ||||||||||||||||||||||||||||||||
| 229 | Returns : | ||||||||||||||||||||||||||||||||
| 230 | Args : | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 1900 | ▶ | sub Minus { | ||||||||||||||||||||||||||||||
|
Subroutine
Minus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 236 | 1900 | my $v = shift; | |||||||||||||||||||||||||||||||
| 237 | 1900 | [ - $v->[0], - $v->[1] ]; | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | =head2 Intersection | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | Title : Intersection | ||||||||||||||||||||||||||||||||
| 243 | Usage : | ||||||||||||||||||||||||||||||||
| 244 | Function: | ||||||||||||||||||||||||||||||||
| 245 | Example : | ||||||||||||||||||||||||||||||||
| 246 | Returns : | ||||||||||||||||||||||||||||||||
| 247 | Args : | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | =cut | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 950 | ▶ | sub Intersection { | ||||||||||||||||||||||||||||||
|
Subroutine
Intersection: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 253 | 950 | my $l1 = shift; | |||||||||||||||||||||||||||||||
| 254 | 950 | my $l2 = shift; | |||||||||||||||||||||||||||||||
| 255 | 950 | my ($bp1, $op1) = @$l1; | |||||||||||||||||||||||||||||||
| 256 | 950 | my ($bp2, $op2) = @$l2; | |||||||||||||||||||||||||||||||
| 257 | 950 | my $v1 = VectorSum($op1, Minus($bp1)); | |||||||||||||||||||||||||||||||
| 258 | 950 | my $v2 = VectorSum($op2, Minus($bp2)); | |||||||||||||||||||||||||||||||
| 259 | 950 | my ($x1, $y1) = @$v1; | |||||||||||||||||||||||||||||||
| 260 | 950 | my ($x2, $y2) = @$v2; | |||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 950 | my $DEN = $x1 * $y2 - $x2 * $y1; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | # Lines are parallel. | ||||||||||||||||||||||||||||||||
| 265 | 950 | ▶ | return undef if $DEN == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | 44 | my ($bx1, $by1) = @$bp1; | |||||||||||||||||||||||||||||||
| 268 | 44 | my ($bx2, $by2) = @$bp2; | |||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 44 | my $t1 = (($bx2 - $bx1) * $y2 - ($by2 - $by1) * $x2) / $DEN; | |||||||||||||||||||||||||||||||
| 271 | 44 | my $t2 = (($bx2 - $bx1) * $y1 - ($by2 - $by1) * $x1) / $DEN; | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 44 | my $RESULT = VectorSum($bp1, ScalarProd($t1, $v1)); | |||||||||||||||||||||||||||||||
| 274 | 44 | ($RESULT, $t1, $t2); | |||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 1 | 1; | |||||||||||||||||||||||||||||||