math.geom2d.polygon
Class Rectangle2D

java.lang.Object
  extended by math.geom2d.polygon.Rectangle2D
All Implemented Interfaces:
java.awt.Shape, Domain2D, PolygonalShape2D, Shape2D

public class Rectangle2D
extends java.lang.Object
implements PolygonalShape2D

Rectangle2D defines a rectangle rotated around its first corner.


Field Summary
protected  double h
           
protected  double theta
           
protected  double w
           
protected  double x0
           
protected  double y0
           
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
Rectangle2D()
          Empty contructor (size and position zero)
Rectangle2D(double x0, double y0, double w, double h)
          Main constructor
Rectangle2D(double x0, double y0, double w, double h, double theta)
          Main constructor
Rectangle2D(Point2D point, double w, double h)
          Main constructor
Rectangle2D(Point2D point, double w, double h, double theta)
          Main constructor
Rectangle2D(java.awt.geom.Rectangle2D rect)
          Constructor from awt, to allow easy construction from existing apps.
 
Method Summary
 Shape2D clip(Box2D box)
          Return the clipped polygon, as an instance of Polygon2D.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(java.awt.geom.Point2D point)
          This method simply invoke ancestor method.
 boolean contains(java.awt.geom.Rectangle2D rect)
           
 boolean containsBounds(Shape2D shape)
          Test if the specified Shape is totally contained in this Rectangle.
 boolean equals(java.lang.Object obj)
          Test if retangles are the same.
 Boundary2D getBoundary()
          returns the boundary of the set.
 Box2D getBoundingBox()
          Return bounding box of the rectangle.
 java.awt.Rectangle getBounds()
          Return bounding box of the shape.
 java.awt.geom.Rectangle2D getBounds2D()
          Return more precise bounds for the shape.
 Shape2D getClippedShape(Box2D box)
          Return the clipped polygon, as an instance of Polygon2D.
 double getDistance(double x, double y)
          get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.
 double getDistance(java.awt.geom.Point2D p)
          get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 java.util.Collection<LineSegment2D> getEdges()
          Return the edges as line segments of the polygon
 double getHeight()
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t, double flatness)
           
 java.util.Iterator<Point2D> getPoints()
          Deprecated. use getVertices() method instead.
 double getSignedDistance(double x, double y)
          Get the signed distance of the shape to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape.
 double getSignedDistance(java.awt.geom.Point2D p)
          Get the signed distance of the shape to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape.
 double getTheta()
           
 java.util.Collection<Point2D> getVertices()
          Returns the vertices of the rectangle as a collection of points.
 int getVerticesNumber()
          Return the number of vertices of the polygon
 double getWidth()
           
 double getX()
           
 double getY()
           
 boolean intersects(double x0, double y0, double w0, double h0)
           
 boolean intersects(java.awt.geom.Rectangle2D r)
           
 boolean isBounded()
          Always returns true, because a rectangle is always bounded.
 void setRectangle(double x, double y, double width, double height, double theta)
          Apply the characteristics of the given Rectangle to this object.
 void setRectangle(Rectangle2D rect)
          Apply the characteristics of the given Rectangle to this object.
 void setRectangle(java.awt.geom.Rectangle2D rect)
          Apply the characteristics of the given Rectangle to this object.
 Polygon2D transform(AffineTransform2D trans)
          Return the new Polygon created by an affine transform of this polygon.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x0

protected double x0

y0

protected double y0

w

protected double w

h

protected double h

theta

protected double theta
Constructor Detail

Rectangle2D

public Rectangle2D(double x0,
                   double y0,
                   double w,
                   double h,
                   double theta)
Main constructor


Rectangle2D

public Rectangle2D()
Empty contructor (size and position zero)


Rectangle2D

public Rectangle2D(java.awt.geom.Rectangle2D rect)
Constructor from awt, to allow easy construction from existing apps.


Rectangle2D

public Rectangle2D(double x0,
                   double y0,
                   double w,
                   double h)
Main constructor


Rectangle2D

public Rectangle2D(Point2D point,
                   double w,
                   double h,
                   double theta)
Main constructor


Rectangle2D

public Rectangle2D(Point2D point,
                   double w,
                   double h)
Main constructor

Method Detail

getX

public double getX()

getY

public double getY()

getWidth

public double getWidth()

getHeight

public double getHeight()

getTheta

public double getTheta()

setRectangle

public void setRectangle(Rectangle2D rect)
Apply the characteristics of the given Rectangle to this object.


setRectangle

public void setRectangle(java.awt.geom.Rectangle2D rect)
Apply the characteristics of the given Rectangle to this object.


setRectangle

public void setRectangle(double x,
                         double y,
                         double width,
                         double height,
                         double theta)
Apply the characteristics of the given Rectangle to this object.


getPoints

@Deprecated
public java.util.Iterator<Point2D> getPoints()
Deprecated. use getVertices() method instead.

Returns the vertices of the rectangle.

Returns:
the vertices of the rectangle.

getVertices

public java.util.Collection<Point2D> getVertices()
Returns the vertices of the rectangle as a collection of points.

Specified by:
getVertices in interface PolygonalShape2D
Returns:
the vertices of the rectangle.

getVerticesNumber

public int getVerticesNumber()
Description copied from interface: PolygonalShape2D
Return the number of vertices of the polygon

Specified by:
getVerticesNumber in interface PolygonalShape2D

getEdges

public java.util.Collection<LineSegment2D> getEdges()
Description copied from interface: PolygonalShape2D
Return the edges as line segments of the polygon

Specified by:
getEdges in interface PolygonalShape2D

getBoundary

public Boundary2D getBoundary()
Description copied from interface: Domain2D
returns the boundary of the set. This boundary is either a continuous non intersecting curve (connected domain), or a set of non intersecting continuous curve (one continuous non-intersection for each connected part of the domain).

The returned curve is oriented, with an interior and an exterior.

Specified by:
getBoundary in interface Domain2D
Returns:
the boundary of the domain

isBounded

public boolean isBounded()
Always returns true, because a rectangle is always bounded.

Specified by:
isBounded in interface Shape2D

getDistance

public double getDistance(java.awt.geom.Point2D p)
Description copied from interface: Shape2D
get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Description copied from interface: Shape2D
get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
getDistance in interface Shape2D

getSignedDistance

public double getSignedDistance(java.awt.geom.Point2D p)
Get the signed distance of the shape to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape. In this case, absolute value of distance is equals to the distance to the border of the shape.


getSignedDistance

public double getSignedDistance(double x,
                                double y)
Get the signed distance of the shape to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape. In this case, absolute value of distance is equals to the distance to the border of the shape.


getClippedShape

public Shape2D getClippedShape(Box2D box)
Return the clipped polygon, as an instance of Polygon2D. If the Rectangle2D is totally clipped, return EMPTY_SET.


clip

public Shape2D clip(Box2D box)
Return the clipped polygon, as an instance of Polygon2D. If the Rectangle2D is totally clipped, return EMPTY_SET.

Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

getBoundingBox

public Box2D getBoundingBox()
Return bounding box of the rectangle.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.

transform

public Polygon2D transform(AffineTransform2D trans)
Return the new Polygon created by an affine transform of this polygon.

Specified by:
transform in interface PolygonalShape2D
Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

contains

public boolean contains(java.awt.geom.Point2D point)
This method simply invoke ancestor method. It is redefined to avoid ambiguity with contains(Shape2D).

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D rect)
Specified by:
contains in interface java.awt.Shape

containsBounds

public boolean containsBounds(Shape2D shape)
Test if the specified Shape is totally contained in this Rectangle. Note that the test is performed on the bounding box of the shape, then for rotated rectangles, this method can return false with a shape totally contained in the rectangle. The problem does not exist for horizontal rectangle, since edges of rectangle and bounding box are parallel.


intersects

public boolean intersects(double x0,
                          double y0,
                          double w0,
                          double h0)
Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Specified by:
intersects in interface java.awt.Shape

getBounds

public java.awt.Rectangle getBounds()
Return bounding box of the shape.

Specified by:
getBounds in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Return more precise bounds for the shape.

Specified by:
getBounds2D in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t,
                                                  double flatness)
Specified by:
getPathIterator in interface java.awt.Shape

equals

public boolean equals(java.lang.Object obj)
Test if retangles are the same. We consider two rectangles are equals if their corners are the same. Then, we can have different origin and different angles, but equal rectangles.

Overrides:
equals in class java.lang.Object