Math-Zap
view release on metacpan or search on metacpan
lib/Math/Zap/Line2.pm view on Meta::CPAN
=head3 accuracy
Get/Set accuracy for comparisons
=cut
my $accuracy = 1e-10;
sub accuracy
{return $accuracy unless scalar(@_);
$accuracy = shift();
}
=head3 short
Short line?
=cut
sub short($$)
{my $l = shift; # Line
my $a = 1e-4; # Accuracy
my $A = shift; # Action 0: return indicator, 1: confess
my $n =
($l->{a}{x}-$l->{b}{x})**2 + ($l->{a}{y}-$l->{b}{y})**2
< $a;
confess "Short line2" if $n and $A;
$n;
}
=head3 check
Check its a line
=cut
sub check(@)
{unless (debug)
{for my $l(@_)
{confess "$l is not a line" unless ref($l) eq __PACKAGE__;
}
}
@_;
}
=head3 is
Test its a line
=cut
sub is(@)
{for my $l(@_)
{return 0 unless ref($l) eq __PACKAGE__;
}
'line2';
}
=head3 a,b,ab,ba
Components of line
=cut
sub a($) {check(@_) if (debug); $_[0]->{a}}
sub b($) {check(@_) if (debug); $_[0]->{b}}
sub ab($) {check(@_) if (debug); vector2($_[0]->{b}{x}-$_[0]->{a}{x}, $_[0]->{b}{y}-$_[0]->{a}{y})}
sub ba($) {check(@_) if (debug); $_[0]->a-$_[0]->b}
=head3 clone
Create a line from another line
=cut
sub clone($)
{my ($l) = check(@_); # Lines
bless {a=>$l->a, b=>$l->b};
}
=head3 print
Print line
=cut
sub print($)
{my ($l) = check(@_); # Lines
my ($a, $b) = ($l->a, $l->b);
my ($A, $B) = ($a->print, $b->print);
"line2($A, $B)";
}
=head3 angle
Angle between two lines
=cut
sub angle($$)
{my ($a, $b) = check(@_); # Lines
$a->a-$a->b < $b->a-$b->b;
}
=head3 parallel
Are two lines parallel
=cut
sub parallel($$)
{my ($a, $b) = check(@_); # Lines
# return 1 if abs(1 - abs($a->ab->norm * $b->ab->norm)) < $accuracy;
return 1 if abs(1 - abs($a->ab->norm * $b->ab->norm)) < 1e-3;
0;
}
=head3 intersect
( run in 1.134 second using v1.01-cache-2.11-cpan-c221a9de4ec )