Math-Zap

 view release on metacpan or  search on metacpan

lib/Math/Zap/Cube.pm  view on Meta::CPAN




=cut


sub new($$$$)
 {my ($a, $x, $y, $z) = vectorCheck(@_);
  bless {a=>$a, x=>$x, y=>$y, z=>$z}; 
 }


=head3 cube

Synonym for L</new>

=cut


sub cube($$$$) {new($_[0], $_[1], $_[2], $_[3])};


=head3 unit

Unit cube                   

=cut


sub unit()
 {cube(vector(0,0,0), vector(1,0,0), vector(0,1,0), vector(0,0,1));
 }


=head2 Methods


=head3 Check

Check that an anonymous reference is a reference to a cube and confess
if it is not.

=cut


sub check(@)
 {for my $c(@_)
   {confess "$c is not a cube" unless ref($c) eq __PACKAGE__;
   }
  return (@_)
 }


=head3 is

Same as L</check> but return the result to the caller.   

=cut


sub is(@)
 {for my $r(@_)
   {return 0 unless ref($r) eq __PACKAGE__;
   }
  'cube';
 }


=head3 a, x, y, z

Components of cube

=cut


sub a($) {my ($c) = check(@_); $c->{a}}
sub x($) {my ($c) = check(@_); $c->{x}}
sub y($) {my ($c) = check(@_); $c->{y}}
sub z($) {my ($c) = check(@_); $c->{z}}


=head3 Clone

Create a cube from another cube

=cut


sub clone($)
 {my ($c) = check(@_); # Cube
  bless {a=>$c->a, x=>$c->x, y=>$c->y, z=>$c->z};
 }


=head3 Accuracy

Get/Set accuracy for comparisons

=cut


my $accuracy = 1e-10;

sub accuracy
 {return $accuracy unless scalar(@_);
  $accuracy = shift();
 }


=head3 Add

Add a vector to a cube                   

=cut


sub add($$)
 {my ($c) =       check(@_[0..0]); # Cube       
  my ($v) = vectorCheck(@_[1..1]); # Vector     
  new($c->a+$v, $c->x, $c->y, $c->z);                         
 }



( run in 0.470 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )