# Pastel::Geometry::Ellipse
# Copyright 2001, Malay Kumar Basu curiouser@ccmb.ap.nic.in
package Pastel
::Geometry
::Ellipse
;
@ISA = qw(Pastel::Mixin::Mixin Pastel::Shape);
#use Pastel::Geometry::Shape;
#print STDERR "Ellipse called\n@_\n";
bless $self, ref($class) || $class;
#print STDERR "Ellipse init called\n";
#If no argument supplied, an empty constructor-
my ($x, $y, $width, $height)=
$self->_rearrange(["X", "Y", "WIDTH", "HEIGHT"], @args);
$self->{x
} = defined($x) ?
$x : 0;
$self->{y
} = defined($y) ?
$y : 0;
$self->{w
} = defined($width) ?
$width : 0;
$self->{h
} = defined($height)?
$height : 0;
return ref($self)." Location:[".$self->{x
}.",".$self->{y
}."] Width:".$self->{w
}." Height:".$self->{h
};
sub get_x
{ return $_[0]->{x
}; }
sub get_y
{ return $_[0]->{y
}; }
sub get_width
{ return $_[0]->{w
}; }
sub get_height
{ return $_[0]->{h
}; }
#Create a new Rectangle and return
my $bb = Pastel
::Geometry
::Rectangle
->new(
return if ( $self->get_width() <= 0 || $self->get_height() <= 0 );
my ($x, $y, $w, $h) = $self->_rearrange(["X", "Y", "WIDTH", "HEIGHT"], @_);
return ( $self->_contains($x, $y) &&
$self->_contains( $x + $w, $y) &&
$self->_contains( $x, $y + $h) &&
$self->_contains( $x + $w, $y + $h) );
return ( $self->_contains( $x, $y) );
croak
"Illegal parameter in Pastel::Ellipse::contains()\n";
my $width = $self->get_width();
my $normalized_x = ($x - $self->get_x() ) / $width - 0.5;
my $height = $self->get_height();
my $normalized_y = ($y - $self->get_y() ) / $height - 0.5;
return ( $normalized_x * $normalized_x + $normalized_y * $normalized_y) < 0.25;
my ($x, $y, $width, $height) =
$self->_rearrange( ["X","Y","WIDTH","HEIGHT"],
if($width <= 0 || $height <= 0){
my $w = $self->get_width();
my $h = $self->get_height();
my $norm_x1 = ( $x - $self->get_x() ) / $w - 0.5;
my $norm_x2 = $norm_x1 + $width / $w;
my $norm_y1 = ( $y - $self->get_y() ) / $h - 0.5;
my $norm_y2 = $norm_y1 + $height/ $h;
} elsif ( $norm_x2 < 0 ){
} elsif ( $norm_y2 < 0 ) {
return ( $near_x * $near_x + $near_y * $near_y ) < 0.25;
my $x = $self->get_x() + ($self->get_width() / 2);
my $y = $self->get_y() + ($self->get_height()/ 2);
return Pastel
::Geometry
::Point
->new(-x
=>$x, -y
=>$y);
my $style = $self->get_style($g);
my $s = "<ellipse cx=\"".$self->get_center()->get_x()."\" cy=\"";
$s .= $self->get_center()->get_y()."\" rx=\"";
$s .= eval($self->get_width()/2) ."\" ry=\"".eval($self->get_height()/2). "\" style=\"$style\" />";