org.epseelon.mobimap.geom
Class RectangularShape

java.lang.Object
  extended by org.epseelon.mobimap.geom.RectangularShape
All Implemented Interfaces:
Shape
Direct Known Subclasses:
Rectangle2D

public abstract class RectangularShape
extends java.lang.Object
implements Shape

This class provides a generic framework, and several helper methods, for subclasses which represent geometric objects inside a rectangular frame. This does not specify any geometry except for the bounding box.

Since:
1.2
Author:
Tom Tromey (tromey@cygnus.com), Eric Blake (ebb9@email.byu.edu)
See Also:
Rectangle2D

Constructor Summary
protected RectangularShape()
          Default constructor.
 
Method Summary
 boolean contains(Point2D p)
          Tests if a point is inside the boundary of the shape.
 boolean contains(Rectangle2D r)
          Tests if the shape completely contains the given rectangle.
 Rectangle getBounds()
          Returns a bounding box for this shape, in integer format.
 double getCenterX()
          Return the x coordinate of the center point of the framing rectangle.
 double getCenterY()
          Return the y coordinate of the center point of the framing rectangle.
 Rectangle2D getFrame()
          Return the frame around this object.
abstract  double getHeight()
          Get the height of the framing rectangle.
 double getMaxX()
          Get the maximum x coordinate in the frame.
 double getMaxY()
          Get the maximum y coordinate in the frame.
 double getMinX()
          Get the minimum x coordinate in the frame.
 double getMinY()
          Get the minimum y coordinate in the frame.
abstract  double getWidth()
          Get the width of the framing rectangle.
abstract  double getX()
          Get the x coordinate of the upper-left corner of the framing rectangle.
abstract  double getY()
          Get the y coordinate of the upper-left corner of the framing rectangle.
 boolean intersects(Rectangle2D r)
          Tests if a rectangle and this shape share common internal points.
abstract  boolean isEmpty()
          Test if the shape is empty, meaning that no points are inside it.
abstract  void setFrame(double x, double y, double w, double h)
          Set the framing rectangle of this shape to the given coordinate and size.
 void setFrame(Point2D p, Dimension2D d)
          Set the framing rectangle of this shape to the given coordinate and size.
 void setFrame(Rectangle2D r)
          Set the framing rectangle of this shape to the given rectangle.
 void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
          Set the framing rectangle of this shape using the center of the frame, and one of the four corners.
 void setFrameFromCenter(Point2D center, Point2D corner)
          Set the framing rectangle of this shape using the center of the frame, and one of the four corners.
 void setFrameFromDiagonal(double x1, double y1, double x2, double y2)
          Set the framing rectangle of this shape using two points on a diagonal.
 void setFrameFromDiagonal(Point2D p1, Point2D p2)
          Set the framing rectangle of this shape using two points on a diagonal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.epseelon.mobimap.geom.Shape
contains, contains, getBounds2D, intersects
 

Constructor Detail

RectangularShape

protected RectangularShape()
Default constructor.

Method Detail

getX

public abstract double getX()
Get the x coordinate of the upper-left corner of the framing rectangle.

Returns:
the x coordinate

getY

public abstract double getY()
Get the y coordinate of the upper-left corner of the framing rectangle.

Returns:
the y coordinate

getWidth

public abstract double getWidth()
Get the width of the framing rectangle.

Returns:
the width

getHeight

public abstract double getHeight()
Get the height of the framing rectangle.

Returns:
the height

getMinX

public double getMinX()
Get the minimum x coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getX() even when getWidth() is negative.

Returns:
the minimum x coordinate

getMinY

public double getMinY()
Get the minimum y coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getY() even when getHeight() is negative.

Returns:
the minimum y coordinate

getMaxX

public double getMaxX()
Get the maximum x coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getX()+getWidth() even when getWidth() is negative.

Returns:
the maximum x coordinate

getMaxY

public double getMaxY()
Get the maximum y coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getY()+getHeight() even when getHeight() is negative.

Returns:
the maximum y coordinate

getCenterX

public double getCenterX()
Return the x coordinate of the center point of the framing rectangle.

Returns:
the central x coordinate

getCenterY

public double getCenterY()
Return the y coordinate of the center point of the framing rectangle.

Returns:
the central y coordinate

getFrame

public Rectangle2D getFrame()
Return the frame around this object. Note that this may be a looser bounding box than getBounds2D.

Returns:
the frame, in double precision
See Also:
setFrame(double, double, double, double)

isEmpty

public abstract boolean isEmpty()
Test if the shape is empty, meaning that no points are inside it.

Returns:
true if the shape is empty

setFrame

public abstract void setFrame(double x,
                              double y,
                              double w,
                              double h)
Set the framing rectangle of this shape to the given coordinate and size.

Parameters:
x - the new x coordinate
y - the new y coordinate
w - the new width
h - the new height
See Also:
getFrame()

setFrame

public void setFrame(Point2D p,
                     Dimension2D d)
Set the framing rectangle of this shape to the given coordinate and size.

Parameters:
p - the new point
d - the new dimension
Throws:
java.lang.NullPointerException - if p or d is null
See Also:
getFrame()

setFrame

public void setFrame(Rectangle2D r)
Set the framing rectangle of this shape to the given rectangle.

Parameters:
r - the new framing rectangle
Throws:
java.lang.NullPointerException - if r is null
See Also:
getFrame()

setFrameFromDiagonal

public void setFrameFromDiagonal(double x1,
                                 double y1,
                                 double x2,
                                 double y2)
Set the framing rectangle of this shape using two points on a diagonal. The area will be positive.

Parameters:
x1 - the first x coordinate
y1 - the first y coordinate
x2 - the second x coordinate
y2 - the second y coordinate

setFrameFromDiagonal

public void setFrameFromDiagonal(Point2D p1,
                                 Point2D p2)
Set the framing rectangle of this shape using two points on a diagonal. The area will be positive.

Parameters:
p1 - the first point
p2 - the second point
Throws:
java.lang.NullPointerException - if either point is null

setFrameFromCenter

public void setFrameFromCenter(double centerX,
                               double centerY,
                               double cornerX,
                               double cornerY)
Set the framing rectangle of this shape using the center of the frame, and one of the four corners. The area will be positive.

Parameters:
centerX - the x coordinate at the center
centerY - the y coordinate at the center
cornerX - the x coordinate at a corner
cornerY - the y coordinate at a corner

setFrameFromCenter

public void setFrameFromCenter(Point2D center,
                               Point2D corner)
Set the framing rectangle of this shape using the center of the frame, and one of the four corners. The area will be positive.

Parameters:
center - the center point
corner - a corner point
Throws:
java.lang.NullPointerException - if either point is null

contains

public boolean contains(Point2D p)
Tests if a point is inside the boundary of the shape.

Specified by:
contains in interface Shape
Parameters:
p - the point to test
Returns:
true if the point is inside the shape
Throws:
java.lang.NullPointerException - if p is null
See Also:
Shape.contains(double, double)

intersects

public boolean intersects(Rectangle2D r)
Tests if a rectangle and this shape share common internal points.

Specified by:
intersects in interface Shape
Parameters:
r - the rectangle to test
Returns:
true if the rectangle intersects this shpae
Throws:
java.lang.NullPointerException - if r is null
See Also:
Shape.intersects(double, double, double, double)

contains

public boolean contains(Rectangle2D r)
Tests if the shape completely contains the given rectangle.

Specified by:
contains in interface Shape
Parameters:
r - the rectangle to test
Returns:
true if r is contained in this shape
Throws:
java.lang.NullPointerException - if r is null
See Also:
Shape.contains(double, double, double, double)

getBounds

public Rectangle getBounds()
Returns a bounding box for this shape, in integer format. Notice that you may get a tighter bound with getBounds2D. If the frame is empty, the box is the default empty box at the origin.

Specified by:
getBounds in interface Shape
Returns:
a bounding box
See Also:
Shape.getBounds2D()


Copyright © 2008 Epseelon. All Rights Reserved.