math.geom2d
Class Box2D

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

public class Box2D
extends java.lang.Object
implements PolygonalShape2D

This class defines bounds of a shape. It stores limits in each direction: x and y. It also provides methods for clipping others shapes, depending on their type.


Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
Box2D()
          Empty constructor (size and position zero)
Box2D(double x0, double x1, double y0, double y1)
          Main constructor, given bounds for x coord, then bounds for y coord.
Box2D(Point2D point, double w, double h)
          Constructor from a point, a width and an height
Box2D(Point2D p1, Point2D p2)
          Constructor from 2 points, giving extreme coordinates of the box.
Box2D(java.awt.geom.Rectangle2D rect)
          Constructor from awt, to allow easy construction from existing apps.
 
Method Summary
 Shape2D clip(Box2D box)
          Returns an instance of Box2D, or Shape2D.EMPTY_SET if the two boxes are disjoint
 BoundarySet2D<ContinuousBoundary2D> clipBoundary(Boundary2D boundary)
          Clips a boundary and closes the result curve.
 CurveSet2D<ContinuousOrientedCurve2D> clipContinuousOrientedCurve(ContinuousOrientedCurve2D curve)
          Clip a curve, and return a CurveSet2D.
 CurveSet2D<Curve2D> clipCurve(Curve2D curve)
          Clip a curve, and return a CurveSet2D.
 CurveSet2D<Curve2D> clipCurveOld(Curve2D curve)
           
 CurveSet2D<SmoothCurve2D> clipSmoothCurve(SmoothCurve2D curve)
          clip a continuous smooth curve.
 boolean contains(double x, double y)
           
 boolean contains(double x0, double y0, double w, double h)
           
 boolean contains(java.awt.geom.Point2D point)
           
 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 boxes are the same. two boxes are the same if the have the same bounds.
static int findNextCurveIndex(double[] positions, double pos)
           
 java.awt.Rectangle getAsAWTRectangle()
          convert to AWT rectangle.
 java.awt.geom.Rectangle2D getAsAWTRectangle2D()
          convert to AWT Rectangle2D.
 Shape2D getAsRectangle()
          convert to rectangle.
 Boundary2D getBoundary()
          returns the boundary of the set.
 Box2D getBoundingBox()
          Return a new instance of Box2D with same parameters as this box.
 java.awt.Rectangle getBounds()
           
 java.awt.geom.Rectangle2D getBounds2D()
           
 Shape2D getClippedShape(Box2D box)
          Return an instance of Box2D
 java.util.Collection<StraightLine2D> getClippingLines()
          Returns the set of lines defining half-planes which all contains the box.
 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()
           
 double getMaxX()
           
 double getMaxY()
           
 double getMinX()
           
 double getMinY()
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
           
 java.util.Collection<Point2D> getVertices()
          Return the vertices (singular points) of the polygon
 int getVerticesNumber()
          Returns 4, the number of vertices of a rectangle
 double getWidth()
           
 boolean intersects(double x0, double y0, double w, double h)
           
 boolean intersects(java.awt.geom.Rectangle2D rect)
           
 boolean isBounded()
          Always returns true, because a rectangle is always bounded.
 Polygon2D transform(AffineTransform2D trans)
          Return the new domain created by an affine transform of this box.
 Box2D union(Box2D box)
          change the bounds of the box to also include bounds of the argument.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Box2D

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


Box2D

public Box2D(double x0,
             double x1,
             double y0,
             double y1)
Main constructor, given bounds for x coord, then bounds for y coord. A check is performed to ensure first bound is lower than second bound.


Box2D

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


Box2D

public Box2D(Point2D p1,
             Point2D p2)
Constructor from 2 points, giving extreme coordinates of the box.


Box2D

public Box2D(Point2D point,
             double w,
             double h)
Constructor from a point, a width and an height

Method Detail

getMinX

public double getMinX()

getMinY

public double getMinY()

getMaxX

public double getMaxX()

getMaxY

public double getMaxY()

getWidth

public double getWidth()

getHeight

public double getHeight()

getClippingLines

public java.util.Collection<StraightLine2D> getClippingLines()
Returns the set of lines defining half-planes which all contains the box.

Returns:
a set of straight lines

clipCurve

public CurveSet2D<Curve2D> clipCurve(Curve2D curve)
Clip a curve, and return a CurveSet2D. If the curve is totally outside the box, return a CurveSet2D with 0 curves inside. If the curve is totally inside the box, return a CurveSet2D with only one curve, which is the original curve.


clipCurveOld

public CurveSet2D<Curve2D> clipCurveOld(Curve2D curve)

clipSmoothCurve

public CurveSet2D<SmoothCurve2D> clipSmoothCurve(SmoothCurve2D curve)
clip a continuous smooth curve.


clipContinuousOrientedCurve

public CurveSet2D<ContinuousOrientedCurve2D> clipContinuousOrientedCurve(ContinuousOrientedCurve2D curve)
Clip a curve, and return a CurveSet2D. If the curve is totally outside the box, return a CurveSet2D with 0 curves inside. If the curve is totally inside the box, return a CurveSet2D with only one curve, which is the original curve.


clipBoundary

public BoundarySet2D<ContinuousBoundary2D> clipBoundary(Boundary2D boundary)
Clips a boundary and closes the result curve. Return an instance of BoundarySet2D.


findNextCurveIndex

public static final int findNextCurveIndex(double[] positions,
                                           double pos)

getAsAWTRectangle

public java.awt.Rectangle getAsAWTRectangle()
convert to AWT rectangle.

Returns:
an instance of java.awt.geom.Rectangle2D

getAsAWTRectangle2D

public java.awt.geom.Rectangle2D getAsAWTRectangle2D()
convert to AWT Rectangle2D. Result is an instance of HRectangle, which extends java.awt.geom.Rectangle2D.Double.

Returns:
an instance of java.awt.geom.Rectangle2D

getAsRectangle

public Shape2D getAsRectangle()
convert to rectangle. Result is an instance of HRectangle, which extends java.awt.geom.Rectangle2D.Double.

Returns:
an instance of HRectangle2D

union

public Box2D union(Box2D box)
change the bounds of the box to also include bounds of the argument.

Parameters:
box - the bounding box to include
Returns:
this

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()
Returns 4, the number of vertices of a rectangle

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

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.


getClippedShape

public Shape2D getClippedShape(Box2D box)
Return an instance of Box2D


clip

public Shape2D clip(Box2D box)
Returns an instance of Box2D, or Shape2D.EMPTY_SET if the two boxes are disjoint

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

getBoundingBox

public Box2D getBoundingBox()
Return a new instance of Box2D with same parameters as this box.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.
See Also:
Shape2D.getBoundingBox()

transform

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

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)
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 x0,
                        double y0,
                        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

intersects

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

intersects

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

getBounds

public java.awt.Rectangle getBounds()
Specified by:
getBounds in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface java.awt.Shape

getPathIterator

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

getPathIterator

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

equals

public boolean equals(java.lang.Object obj)
Test if boxes are the same. two boxes are the same if the have the same bounds.

Overrides:
equals in class java.lang.Object