math.geom2d
Class Box2D

Package class diagram package Box2D
java.lang.Object
  extended by math.geom2d.Box2D
All Implemented Interfaces:
Cloneable

public class Box2D
extends Object
implements Cloneable

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.


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(Rectangle2D rect)
          Constructor from awt, to allow easy construction from existing apps.
 
Method Summary
 Box2D clip(Box2D box)
          Clip this bounding box such that after clipping, it is totally contained in the given box.
 Box2D clone()
           
 boolean contains(double x, double y)
           
 boolean contains(Point2D point)
           
 boolean containsBounds(Shape2D shape)
          Test if the specified Shape is totally contained in this Box2D.
static Box2D create(double xmin, double xmax, double ymin, double ymax)
           
static Box2D create(Point2D p1, Point2D p2)
           
 void draw(Graphics2D g2)
           
 boolean equals(Object obj)
          Test if boxes are the same. two boxes are the same if the have the same bounds.
 void fill(Graphics2D g2)
           
 Rectangle getAsAWTRectangle()
          convert to AWT rectangle.
 Rectangle2D getAsAWTRectangle2D()
          convert to AWT Rectangle2D.
 HRectangle2D getAsRectangle()
          Converts to a rectangle.
 Boundary2D getBoundary()
          Returns the boundary of this box.
 Box2D getBoundingBox()
           
 Collection<StraightLine2D> getClippingLines()
          Returns a set of straight of lines defining half-planes, that all contain the box.
 Collection<LinearShape2D> getEdges()
          Returns the set of linear shapes that constitutes the boundary of this box.
 double getHeight()
           
 double getMaxX()
           
 double getMaxY()
           
 double getMinX()
           
 double getMinY()
           
 int getVertexNumber()
          Returns the number of vertices of the box.
 Collection<Point2D> getVertices()
           
 double getWidth()
           
 Box2D intersection(Box2D box)
          Returns the Box2D which is contained both by this box and by the specified box.
 boolean isBounded()
          Returns true if all bounds are finite.
 Box2D merge(Box2D box)
          Changes the bounds of this box to also include bounds of the argument.
 String toString()
           
 Box2D transform(AffineTransform2D trans)
          Return the new domain created by an affine transform of this box.
 Box2D union(Box2D box)
          Returns the Box2D which contains both this box and the specified box.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, 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. Consider creating a new box using static factory instead (0.8.1)


Box2D

public Box2D(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. Consider creating a new box using static factory instead (0.8.1)


Box2D

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

Method Detail

create

public static final Box2D create(double xmin,
                                 double xmax,
                                 double ymin,
                                 double ymax)
Since:
0.8.1

create

public static final Box2D create(Point2D p1,
                                 Point2D p2)
Since:
0.8.1

getMinX

public double getMinX()

getMinY

public double getMinY()

getMaxX

public double getMaxX()

getMaxY

public double getMaxY()

getWidth

public double getWidth()

getHeight

public double getHeight()

isBounded

public boolean isBounded()
Returns true if all bounds are finite.


contains

public boolean contains(Point2D point)

contains

public boolean contains(double x,
                        double y)

containsBounds

public boolean containsBounds(Shape2D shape)
Test if the specified Shape is totally contained in this Box2D. 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.


getClippingLines

public Collection<StraightLine2D> getClippingLines()
Returns a set of straight of lines defining half-planes, that all contain the box. If the box is bounded, the number of straight lines is 4, otherwise it can be less.

Returns:
a set of straight lines

getEdges

public Collection<LinearShape2D> getEdges()
Returns the set of linear shapes that constitutes the boundary of this box.


getBoundary

public Boundary2D getBoundary()
Returns the boundary of this box. The boundary can be bounded, in the case of a bounded box. It is unbounded if at least one bound of the box is infinite. If both x bounds or both y-bounds are infinite, the boundary is constituted from 2 straight lines.

Returns:
the box boundary

getVertices

public Collection<Point2D> getVertices()

getVertexNumber

public int getVertexNumber()
Returns the number of vertices of the box.


union

public Box2D union(Box2D box)
Returns the Box2D which contains both this box and the specified box.

Parameters:
box - the bounding box to include
Returns:
a new Box2D

intersection

public Box2D intersection(Box2D box)
Returns the Box2D which is contained both by this box and by the specified box.

Parameters:
box - the bounding box to include
Returns:
a new Box2D

merge

public Box2D merge(Box2D box)
Changes the bounds of this box to also include bounds of the argument.

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

clip

public Box2D clip(Box2D box)
Clip this bounding box such that after clipping, it is totally contained in the given box.

Returns:
this

transform

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


getAsAWTRectangle

public Rectangle getAsAWTRectangle()
convert to AWT rectangle.

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

getAsAWTRectangle2D

public 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 HRectangle2D getAsRectangle()
Converts to a rectangle. Result is an instance of HRectangle, which extends java.awt.geom.Rectangle2D.Double.

Returns:
an instance of HRectangle2D

draw

public void draw(Graphics2D g2)

fill

public void fill(Graphics2D g2)

getBoundingBox

public Box2D getBoundingBox()

toString

public String toString()
Overrides:
toString in class Object

equals

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

Overrides:
equals in class Object

clone

public Box2D clone()
Overrides:
clone in class Object


Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.