manticore/Manticore/Geometry/Vector.pm

30 lines
546 B
Perl

package Manticore::Geometry::Vector;
use strict;
use warnings;
sub new {
my (undef, $x, $y) = @_;
return bless [$x,$y]
}
# add point to a vector
sub add {
my ($self, $other) = @_;
return Manticore::Geometry::Point->new($other->[0]+$self->[0], $other->[1]+$self->[1]);
}
# returns the size of a vector
sub size {
my $self = shift;
return sqrt($self->[0]*$self->[0]+$self->[1]*$self->[1])
}
# scalarproduct with another vector
sub scalar {
my ($self, $other) = @_;
return $self->[0]*$other->[0] + $self->[1]*$other->[1];
}
1;