2 # This file is part of Language::Befunge::Vector::XS.
3 # Copyright (c) 2008 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package Language
::Befunge
::Vector
::XS
;
20 '+=' => \
&_add_inplace
,
21 '-=' => \
&_substract_inplace
,
25 our $VERSION = '0.0.1';
28 XSLoader
::load
('Language::Befunge::Vector::XS', $VERSION);
30 # Preloaded methods go here.
39 sub get_all_components {$_[0]}
41 sub set_component {$_[0]}
42 sub bounds_check {$_[0]}
44 sub _substract {$_[0]}
46 sub _add_inplace {$_[0]}
53 Language::Befunge::Vector::XS - an opaque, N-dimensional vector class.
59 my $v1 = Language::Befunge::Vector::XS->new($x, $y, ...);
60 my $v2 = Language::Befunge::Vector::XS->new_zeroes($dims);
66 This class abstracts normal vector manipulation. It lets you pass
67 around one argument to your functions, rather than N arguments, one
68 per dimension. This means much of your code doesn't have to care
69 how many dimensions you're working with.
71 You can do vector arithmetic, test for equality, or even stringify
72 the vector to a string like I<"(1,2,3)">.
74 It has exactly the same api as C<Language::Befunge::Vector>, but LBVXS
75 is written in XS for speed reasons.
80 =head2 my $vec = LBV::XS->new( $x [, $y, ...] )
82 Create a new vector. The arguments are the actual vector data; one
83 integer per dimension.
86 =head2 my $vec = LBV::XS->new_zeroes($dims);
88 Create a new vector of dimension C<$dims>, set to the origin (all zeroes). C<<
89 LBV->new_zeroes(2) >> is exactly equivalent to B<< LBV->new(0,0) >>.
92 =head2 my $vec = $v->copy;
94 Return a new LBV object, which has the same dimensions and coordinates
101 =head2 my $str = $vec->as_string;
103 Return the stringified form of C<$vec>. For instance, a Befunge vector
104 might look like C<(1,2)>.
106 This method is also applied to stringification, ie when one forces
107 string context (C<"$vec">).
110 =head2 my $dims = $vec->get_dims;
112 Return the number of dimensions, an integer.
115 =head2 my $val = $vec->get_component($dim);
117 Get the value for dimension C<$dim>.
120 =head2 my @vals = $vec->get_all_components;
122 Get the values for all dimensions, in order from 0..N.
127 Set the vector back to the origin, all 0's.
130 =head2 $vec->set_component($dim, $value);
132 Set the value for dimension C<$dim> to C<$value>.
135 =head2 my $is_within = $vec->bounds_check($begin, $end);
137 Check whether C<$vec> is within the box defined by C<$begin> and C<$end>.
138 Return 1 if vector is contained within the box, and 0 otherwise.
142 =head1 MATHEMATICAL OPERATIONS
144 =head2 Standard operations
146 One can do some maths on the vectors. Addition and substraction work as
152 Either operation return a new LBV object, which is the result of C<$v1>
155 The inversion is also supported:
158 will subtracts C<$v1> from the origin, and effectively, gives the
159 inverse of the original vector. The new vector is the same distance from
160 the origin, in the opposite direction.
163 =head2 Inplace operations
165 LBV objects also supports inplace mathematical operations:
170 effectively adds / substracts C<$v2> to / from C<$v1>, and stores the
171 result back into C<$v1>.
176 Finally, LBV objects can be tested for equality, ie whether two vectors
177 both point at the same spot.
179 print "same
" if $v1 == $v2;
180 print "differ
" if $v1 != $v2;
185 L<Language::Befunge::Vector>
190 Jerome Quelin, E<lt>jquelin@cpan.orgE<gt>
192 Development is discussed on E<lt>language-befunge@mongueurs.netE<gt>
195 =head1 COPYRIGHT & LICENSE
197 Copyright (c) 2008 Jerome Quelin, all rights reserved.
199 This program is free software; you can redistribute it and/or modify
200 it under the same terms as Perl itself.