[system] / trunk / pg / lib / Parser / BOP / cross.pm Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

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

Wed Jul 28 20:32:33 2004 UTC (15 years, 6 months ago) by sh002i
File size: 1309 byte(s)
```merged changes from rel-2-1-a1 -- stop using that branch.
```

```    1 #########################################################################
2 #
3 #  Implement cross product of vectors.
4 #
5 package Parser::BOP::cross;
6 use strict; use vars qw(@ISA);
7 @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     else {\$self->Error("Operands of '><' must by in three-space")}
21   } else {\$self->Error("Operands of '><' must be Vectors")}
22 }
23
24 #
25 #  Use 'x' as cross product in perl (see Value.pm for more).
26 #
27 sub _eval {\$_[1] x \$_[2]}
28
29 #
30 #  Return the zero vector if one operand is zero.
31 #  Factor out negatives.
32 #
33 sub _reduce {
34   my \$self = shift;
35   return \$self->{lop} if (\$self->{lop}{isZero});
36   return \$self->{rop} if (\$self->{rop}{isZero});
37   return \$self->makeNeg(\$self->{lop}{op},\$self->{rop}) if (\$self->{lop}->isNeg);
38   return \$self->makeNeg(\$self->{lop},\$self->{rop}{op}) if (\$self->{rop}->isNeg);
39   return \$self;
40 }
41
42 #########################################################################
43
44 1;
45
```