CAD-Calc
view release on metacpan or search on metacpan
lib/CAD/Calc.pm view on Meta::CPAN
=head1 LICENSE
This module is distributed under the same terms as Perl. See the Perl
source package for details.
You may use this software under one of the following licenses:
(1) GNU General Public License
(found at http://www.gnu.org/copyleft/gpl.html)
(2) Artistic License
(found at http://www.perl.com/pub/language/misc/Artistic.html)
=head1 NO WARRANTY
This software is distributed with ABSOLUTELY NO WARRANTY. The author,
his former employer, and any other contributors will in no way be held
liable for any loss or damages resulting from its use.
=head1 Modifications
The source code of this module is made freely available and
distributable under the GPL or Artistic License. Modifications to and
use of this software must adhere to one of these licenses. Changes to
the code should be noted as such and this notification (as well as the
above copyright information) must remain intact on all copies of the
code.
Additionally, while the author is actively developing this code,
notification of any intended changes or extensions would be most helpful
in avoiding repeated work for all parties involved. Please contact the
author with any such development plans.
=cut
=head1 Configuration
Used to set package global values such as precision.
=head2 import
Not called directly. Triggered by the use() function.
import(%options, @EXPORT_TAGS);
Example:
use CAD::Calc (
-precision => 0.125,
-angular => 1.0e-6,
qw(
seg_seg_intersection
dist2d
print_line
)
);
=cut
sub import {
## print "import called with @_\n";
local @ARGV = @_; # shame that Getopt::Long isn't structured better!
use Getopt::Long ();
Getopt::Long::GetOptions( '-',
'precision=f' => \$linear_precision,
'angular=f' => \$angular_precision,
) or croak("bad import arguments");
## print "using $linear_precision for linear\n";
## print "using $angular_precision for angular\n";
$linr = Math::Round::Var->new($linear_precision);
$angr = Math::Round::Var->new($angular_precision);
## print "my linear rounding will be a ", ref($linr), "\n";
## print "my angular rounding will be a ", ref($angr), "\n";
CAD::Calc->export_to_level(1, @ARGV);
} # end subroutine import definition
########################################################################
=head1 Constants
=head2 pi
Returns the value of $CAD::Calc::pi
pi;
=cut
sub pi() {
return($pi);
} # end subroutine pi definition
########################################################################
=head1 Functions
These are all exported as options.
=head2 distdivide
Returns a list of point references resulting from dividing $line into
as many parts as possible which are at least $dist apart.
@points = distdivide(\@line, $dist);
=cut
sub distdivide {
my($line, $dist) = @_;
$dist or croak("call to distdivide would cause divide by zero");
my $ptA = NewVec(@{$line->[0]});
my $ptB = NewVec(@{$line->[1]});
my $seg = NewVec($ptB->Minus($ptA));
my $length = $seg->Length();
# optionally go for fewer points here?
my $count = $length / $dist;
$count = int($count);
return(subdivide($line, $count));
} # end subroutine distdivide definition
########################################################################
=head2 subdivide
Returns a list of point references resulting from subdividing $line
into $count parts. The list will be $count-1 items long, (does not
include $line->[0] and $line->[1]);
( run in 1.563 second using v1.01-cache-2.11-cpan-d7f47b0818f )