math.geom2d.polygon
Class HRectangle2D

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.geom.Rectangle2D.Double
              extended by math.geom2d.polygon.HRectangle2D
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable, Domain2D, PolygonalShape2D, Shape2D

public class HRectangle2D
extends java.awt.geom.Rectangle2D.Double
implements PolygonalShape2D

HRectangle2D defines a rectangle with edges parallel to main axis. Thus, it can not be rotated, contrary to Rectangle2D. This class is actually simply a wrapper of class java.awt.geom.Rectangle2D.Double with interface AbstractPolygon.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
 
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
HRectangle2D()
          Empty constructor (size and position zero)
HRectangle2D(double x0, double y0, double w, double h)
          Main constructor
HRectangle2D(Point2D point, double w, double h)
          Main constructor
HRectangle2D(java.awt.geom.Rectangle2D rect)
          Constructor from awt, to allow easy construction from existing apps.
 
Method Summary
 Shape2D clip(Box2D box)
          Returns the clipping of the rectangle, as an instance of HRectangle2D.
 boolean containsBounds(Shape2D shape)
          Test if the specified Shape is totally contained in this Rectangle.
 boolean equals(java.lang.Object obj)
          Test if rectangles are the same.
 Boundary2D getBoundary()
          returns the boundary of the set.
 Box2D getBoundingBox()
          Returns the bounding box of the shape.
 Shape2D getClippedShape(Box2D box)
          return the clipping of the rectangle, as an instance of HRectangle2D.
 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
 java.util.Iterator<Point2D> getPoints()
          Deprecated. use getVertices() 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.
 java.util.Collection<Point2D> getVertices()
          Return the vertices (singular points) of the polygon
 int getVerticesNumber()
          Return the number of vertices of the polygon
 boolean isBounded()
          Always returns true, because a rectangle is always bounded.
 Polygon2D transform(AffineTransform2D trans)
          Return the new Polygon created by an affine transform of this polygon.
 
Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect, toString
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

HRectangle2D

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


HRectangle2D

public HRectangle2D()
Empty constructor (size and position zero)


HRectangle2D

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


HRectangle2D

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

Method Detail

isBounded

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

Specified by:
isBounded in interface Shape2D

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.


getPoints

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


getVertices

public java.util.Collection<Point2D> getVertices()
Description copied from interface: PolygonalShape2D
Return the vertices (singular points) of the polygon

Specified by:
getVertices in interface PolygonalShape2D

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

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 clipping of the rectangle, as an instance of HRectangle2D. If rectangle is outside clipping box, return an instance of HRectangle with 0 width and height.


clip

public Shape2D clip(Box2D box)
Returns the clipping of the rectangle, as an instance of HRectangle2D. If rectangle is outside clipping box, returns an instance of HRectangle with 0 width and height.

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

getBoundingBox

public Box2D getBoundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

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

equals

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

Overrides:
equals in class java.awt.geom.Rectangle2D

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