From c448a3fd3856f26373856fcc5c31b5893b60bc28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Tue, 15 Jan 2008 11:28:59 +0100 Subject: [PATCH] LBV::bounds_check() moved to its place in the module --- lib/Language/Befunge/Vector.pm | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/Language/Befunge/Vector.pm b/lib/Language/Befunge/Vector.pm index f44cd13..69db709 100644 --- a/lib/Language/Befunge/Vector.pm +++ b/lib/Language/Befunge/Vector.pm @@ -140,6 +140,26 @@ sub set_component { } +# +# other methods +# +# my $is_within = $vec->bounds_check($begin, $end); +# +# Check whether $vec is within the box defined by $begin and $end. +# Return 1 if vector is contained within the box, and 0 otherwise. +# +sub bounds_check { + my ($vchk, $begin, $end) = @_; + croak "uneven dimensions in bounds check!" unless $vchk->get_dims == $begin->get_dims; + croak "uneven dimensions in bounds check!" unless $vchk->get_dims == $end->get_dims; + for (my $d = 0; $d < $vchk->get_dims; $d++) { + return 0 if $vchk->get_component($d) < $begin->get_component($d); + return 0 if $vchk->get_component($d) > $end->get_component($d); + } + return 1; +} + + # -- PRIVATE METHODS #- math ops @@ -231,27 +251,6 @@ sub _substract_inplace { # -# bounds_check( begin, end ) -# -# die "out of bounds" -# unless $vector->bounds_check($begin, $end); -# -# Checks whether the given vector is within the box defined by begin and end. -# Returns 1 if vector is contained within the box, and 0 otherwise. -# -sub bounds_check { - my ($vchk, $begin, $end) = @_; - croak "uneven dimensions in bounds check!" unless $vchk->get_dims == $begin->get_dims; - croak "uneven dimensions in bounds check!" unless $vchk->get_dims == $end->get_dims; - for(my $d = 0; $d < $vchk->get_dims; $d++) { - return 0 if $vchk->get_component($d) < $begin->get_component($d); - return 0 if $vchk->get_component($d) > $end->get_component($d); - } - return 1; -} - - -# # vector_as_string( ) # # Returns the stringified form of the vector. For instance, a Befunge vector might look like "(1,2)". -- 2.11.4.GIT