From: dpvc v. a. <we...@ma...> - 2005-02-15 02:37:48
|
Log Message: ----------- Fixed an error with Matrix() that could cause it to loop infinitely when bad data is passed to it. Also, allow Matrix(), Point(), Vector(), and Real() to accept string values that are evaluated to produce the value returned. (Sorry, accidentally committed with a blank message.) Modified Files: -------------- pg/lib: Value.pm pg/lib/Value: Matrix.pm Real.pm Point.pm Vector.pm Revision Data ------------- Index: Value.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value.pm,v retrieving revision 1.30 retrieving revision 1.31 diff -Llib/Value.pm -Llib/Value.pm -u -r1.30 -r1.31 --- lib/Value.pm +++ lib/Value.pm @@ -274,6 +274,21 @@ } # +# Parse a string and return the resulting formula if it of the right +# type. If the formula is constant, return the value rather than the +# formula. +# +sub parseFormula { + my $self = shift; my $class = ref($self) ? $self->type : class($self); + $class = "Number" if $class eq 'Real' || $class eq "Complex"; + my $f = (scalar(@_) > 1) ? join(',',@_) : shift; + $f = Value::Formula->new($f); $f = $f->eval() if $f->isConstant; + Value::Error("Can't convert ".Value::showClass($f)." to ".Value::showClass($self)) + if ($f->type ne $class); + return $f; +} + +# # A shortcut for new() that creates an instance of the object, # but doesn't do the error checking. We assume the data are already # known to be good. Index: Vector.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Vector.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -Llib/Value/Vector.pm -Llib/Value/Vector.pm -u -r1.12 -r1.13 --- lib/Value/Vector.pm +++ lib/Value/Vector.pm @@ -29,6 +29,7 @@ # a list of numbers, or an reference to an array of numbers # a point or vector object (demote a vector) # a matrix if it is n x 1 or 1 x n +# a string that parses to a vector # sub new { my $self = shift; my $class = ref($self) || $self; Index: Point.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Point.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -Llib/Value/Point.pm -Llib/Value/Point.pm -u -r1.10 -r1.11 --- lib/Value/Point.pm +++ lib/Value/Point.pm @@ -29,6 +29,7 @@ # a list of numbers, or an reference to an array of numbers # a point or vector object (demote a vector) # a matrix if it is n x 1 or 1 x n +# a string that evaluates to a point # sub new { my $self = shift; my $class = ref($self) || $self; Index: Real.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Real.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -Llib/Value/Real.pm -Llib/Value/Real.pm -u -r1.11 -r1.12 --- lib/Value/Real.pm +++ lib/Value/Real.pm @@ -33,7 +33,7 @@ # # Check that the input is a real number or a formula -# Make a formula if either part is a formula +# or a string that evaluates to a number # sub new { my $self = shift; my $class = ref($self) || $self; Index: Matrix.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Matrix.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -Llib/Value/Matrix.pm -Llib/Value/Matrix.pm -u -r1.14 -r1.15 --- lib/Value/Matrix.pm +++ lib/Value/Matrix.pm @@ -29,7 +29,7 @@ # Convert a value to a matrix. The value can be: # a list of numbers or list of (nested) references to arrays of numbers # a point, vector or matrix object, a matrix-valued formula, or a string -# containing a matrix expression in the current context. +# that evaluates to a matrix # sub new { my $self = shift; my $class = ref($self) || $self; |