[system] / trunk / pg / lib / Parser / List / Interval.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/List/Interval.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2625 - (download) (as text) (annotate)
Mon Aug 16 18:35:12 2004 UTC (15 years, 3 months ago) by dpvc
File size: 1865 byte(s)
Added string comparison to all Value object classes (to compare the
string value of an object to another string).

Overloaded perl '.' operator to do dot product when the operands are
formulas returning vectors.  (Part of the auto-generation of
formulas).

A few improvements to real and complex class output results.

Made Union class slightly more robust and removed need for makeUnion
method other than in the Union itself.

    1 #########################################################################
    2 #
    3 #  Implements the Interval class
    4 #
    5 package Parser::List::Interval;
    6 use strict; use vars qw(@ISA);
    7 @ISA = qw(Parser::List);
    8 
    9 #
   10 #  Check that the number of endpoints is OK
   11 #  And that they are numbers or infinity.
   12 #
   13 sub _check {
   14   my $self = shift;
   15   my $length = $self->{type}{length}; my $coords = $self->{coords};
   16   $self->Error("Intervals can have only two endpoints") if ($length > 2);
   17   $self->Error("Intervals must have at least one endpoint") if ($length == 0);
   18   $self->Error("Coordinates of intervals can only be numbers or infinity")
   19     if !$coords->[0]->isNumOrInfinity ||
   20        ($length == 2 && !$coords->[1]->isNumOrInfinity);
   21   $self->Error("Infinite intervals require two endpoints")
   22     if ($length == 1 && $coords->[0]{isInfinite});
   23   $self->Error("The left endpoint of an interval can't be positive infinity")
   24     if ($coords->[0]{isInfinity});
   25   $self->Error("The right endpoint of an interval can't be negative infinity")
   26     if ($length == 2 && $coords->[1]{isNegativeInfinity});
   27   $self->Error("Infinite endpoints must be open")
   28     if ($self->{open} ne '(' && $coords->[0]{isInfinite}) ||
   29        ($self->{close} ne ')' && $length == 2 && $coords->[1]{isInfinite});
   30 }
   31 
   32 #
   33 #  Use the Value.pm class to produce the result
   34 #
   35 sub _eval {
   36   my $self = shift;
   37   my $type = 'Value::'.$self->type;
   38   return $type->new($self->{open},@_,$self->{close});
   39 }
   40 
   41 #
   42 #  Insert appropriate Value.pm calls to generate the result.
   43 #
   44 sub perl {
   45   my $self = shift; my $parens = shift;
   46   my $perl; my @p = ();
   47   foreach my $x (@{$self->{coords}}) {push(@p,$x->perl)}
   48   $perl = $self->type.'('.join(',',"'".$self->{open}."'",@p,"'".$self->{close}."'").')';
   49   $perl = '('.$perl.')' if $parens;
   50   return $perl;
   51 }
   52 
   53 #########################################################################
   54 
   55 1;
   56 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9