[system] / trunk / pg / lib / Parser / BOP / cross.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/BOP/cross.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5130 - (download) (as text) (annotate)
Mon Jul 9 12:45:06 2007 UTC (12 years, 7 months ago) by dpvc
File size: 1738 byte(s)
Added new flags to error checking of operands and function arguments.
This is so that a context can be developed that is more forgiving
about what can be put next to what.  Such a context can NOT be used
for evaluation or answer checking, but can be used to generate TeX
output in more sophisticated situations.

    1 #########################################################################
    2 #
    3 #  Implement cross product of vectors.
    4 #
    5 package Parser::BOP::cross;
    6 use strict;
    7 our @ISA = qw(Parser::BOP);
    8 
    9 #
   10 #  Promote points to vectors, if possible.
   11 #  Check that they are of length three.
   12 #
   13 sub _check {
   14   my $self = shift;
   15   my ($ltype,$rtype) = $self->promotePoints();
   16   if ($ltype->{name} eq 'Vector' && $rtype->{name} eq 'Vector') {
   17     if ($ltype->{length} == 3 && $rtype->{length} == 3 &&
   18         $ltype->{entryType}{length} == 1 && $rtype->{entryType}{length} == 1)
   19           {$self->{type} = {%{$ltype}}}
   20     elsif ($self->context->flag("allowBadOperands")) {$self->{type} = $Value::Type{number}}
   21     else {$self->Error("Operands of '><' must by in three-space")}
   22   }
   23   elsif ($self->context->flag("allowBadOperands")) {$self->{type} = $Value::Type{number}}
   24   else {$self->Error("Operands of '><' must be Vectors")}
   25 }
   26 
   27 #
   28 #  Use 'x' as cross product in perl (see Value.pm for more).
   29 #
   30 sub _eval {$_[1] x $_[2]}
   31 
   32 #
   33 #  Return the zero vector if one operand is zero.
   34 #  Factor out negatives.
   35 #
   36 sub _reduce {
   37   my $self = shift;
   38   my $reduce = $self->{equation}{context}{reduction};
   39   return $self->{lop} if $self->{lop}{isZero} && $reduce->{'0><x'};
   40   return $self->{rop} if $self->{rop}{isZero} && $reduce->{'x><0'};
   41   return $self->makeNeg($self->{lop}{op},$self->{rop}) if $self->{lop}->isNeg && $reduce->{'(-x)><y'};
   42   return $self->makeNeg($self->{lop},$self->{rop}{op}) if $self->{rop}->isNeg && $reduce->{'x><(-y)'};
   43   return $self;
   44 }
   45 
   46 $Parser::reduce->{'0><x'} = 1;
   47 $Parser::reduce->{'x><0'} = 1;
   48 $Parser::reduce->{'x><(-y)'} = 1;
   49 $Parser::reduce->{'(-x)><y'} = 1;
   50 
   51 #########################################################################
   52 
   53 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9