Package edu.umd.cs.piccolo.util
Class PBounds
java.lang.Object
java.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double
edu.umd.cs.piccolo.util.PBounds
- All Implemented Interfaces:
Shape,Serializable,Cloneable
PBounds is simply a Rectangle2D.Double with extra methods that more
properly deal with the case when the rectangle is "empty". A PBounds has an
extra bit to store emptiness. In this state, adding new geometry replaces the
current geometry. A PBounds is emptied with the reset() method. A useful side
effect of the reset method is that it only modifies the fIsEmpty variable,
the other x, y, with, height variables are left alone. This is used by
Piccolo's layout management system to see if a the full bounds of a node has
really changed when it is recomputed. See PNode.validateLayout.
- Version:
- 1.0
- Author:
- Jesse Grosjean
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float -
Field Summary
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, yFields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP -
Constructor Summary
ConstructorsConstructorDescriptionPBounds()Creates an empty bounds.PBounds(double x, double y, double width, double height) Constructs a PBounds object at the given coordinates with the given dimensions.Creates a bounds identical to the one provided.Constructs a PBounds object with the given center point and the specified insets.PBounds(Rectangle2D aBounds) Creates a bounds with the same shape as the rectangle provided. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double newx, double newy) Grows the bounds to contain the coordinate provided.voidChanges this bounds to contain the provided bounds.voidadd(Rectangle2D r) Grows bounds to contain the rectangle if needed.clone()Returns a clone of this node.deltaRequiredToCenter(Rectangle2D targetBounds) Returns the required translation in order for this bounds origin to sit on the center of the provided rectangle.deltaRequiredToContain(Rectangle2D targetBounds) Returns the required translation in order for these to contain the bounds provided.voidRounds the rectangle to the next largest bounds who's measurements are integers.Returns the midpoint of the bounds.Returns the x,y coordinate of the bounds.getSize()Returns the size of the bounds.inset(double dx, double dy) Adjust the measurements of this bounds so that they are the amounts given "in" from their previous border.booleanisEmpty()Returns true if this bounds has been flagged as empty.moveBy(double dx, double dy) Translates the bounds by the given deltas.reset()Flags this bounds as empty.Resets the bounds to (0,0,0,0) and flags it as empty.setOrigin(double x, double y) Changes the origin of these bounds.voidsetRect(double x, double y, double width, double height) Sets the shape of the bounds to the position and dimension provided.voidSets the bounds to the same shape as the bounds provided.voidSets the bounds to the same shape as the rectangle.voidsetSize(double width, double height) Changes the size of the bounds, but retains the origin.toString()Returns a string representation of this PBounds for debugging purposes.Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, outcodeMethods inherited from class java.awt.geom.Rectangle2D
add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, unionMethods inherited from class java.awt.geom.RectangularShape
contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
-
Constructor Details
-
PBounds
public PBounds()Creates an empty bounds. -
PBounds
Creates a bounds identical to the one provided.- Parameters:
aBounds- bounds to be copied
-
PBounds
Creates a bounds with the same shape as the rectangle provided.- Parameters:
aBounds- rectangle to be copied
-
PBounds
Constructs a PBounds object with the given center point and the specified insets.- Parameters:
aCenterPoint- resulting center point of the PBounds objectinsetX- distance from left and right the center should beinsetY- distance from top and bottom the center should be
-
PBounds
public PBounds(double x, double y, double width, double height) Constructs a PBounds object at the given coordinates with the given dimensions.- Parameters:
x- left of boundsy- top of boundswidth- width of boundsheight- height of bounds
-
-
Method Details
-
clone
Returns a clone of this node.- Overrides:
clonein classRectangularShape- Returns:
- cloned copy of this bounds
-
isEmpty
public boolean isEmpty()Returns true if this bounds has been flagged as empty. Not necessarily if it is empty.- Overrides:
isEmptyin classRectangle2D.Double- Returns:
- true if bounds marked as empty
-
reset
Flags this bounds as empty.- Returns:
- itself for chaining
-
resetToZero
Resets the bounds to (0,0,0,0) and flags it as empty.- Returns:
- itself for chaining
-
setRect
Sets the bounds to the same shape as the rectangle. And flags the bounds as not empty.- Overrides:
setRectin classRectangle2D.Double- Parameters:
r- rectangle to copy
-
setRect
Sets the bounds to the same shape as the bounds provided. And flags the bounds as not empty.- Parameters:
b- bounds to copy
-
setRect
public void setRect(double x, double y, double width, double height) Sets the shape of the bounds to the position and dimension provided.- Overrides:
setRectin classRectangle2D.Double- Parameters:
x- new left of boundsy- new top of boundswidth- new width of boundsheight- new height of bounds
-
add
public void add(double newx, double newy) Grows the bounds to contain the coordinate provided.- Overrides:
addin classRectangle2D- Parameters:
newx- x component of pointnewy- y component of point
-
add
Grows bounds to contain the rectangle if needed.- Overrides:
addin classRectangle2D- Parameters:
r- rectangle being added
-
add
Changes this bounds to contain the provided bounds.- Parameters:
bounds- bounds being added
-
getOrigin
Returns the x,y coordinate of the bounds.- Returns:
- coordinate of the bounds
-
setOrigin
Changes the origin of these bounds. And flags it as non-empty.- Parameters:
x- new x component of boundsy- new y component of the bounds- Returns:
- the modified PBounds with its new origin
-
getSize
Returns the size of the bounds.- Returns:
- size of the bounds
-
setSize
public void setSize(double width, double height) Changes the size of the bounds, but retains the origin.- Parameters:
width- new width of the boundsheight- new height of the bounds
-
getCenter2D
Returns the midpoint of the bounds.- Returns:
- midpoint of the bounds
-
moveBy
Translates the bounds by the given deltas.- Parameters:
dx- amount to move xdy- amount to move y- Returns:
- itself for chaining
-
expandNearestIntegerDimensions
public void expandNearestIntegerDimensions()Rounds the rectangle to the next largest bounds who's measurements are integers. Note: this is not the same as rounding its measurements. -
inset
Adjust the measurements of this bounds so that they are the amounts given "in" from their previous border.- Parameters:
dx- amount to move in from border along horizontal axisdy- amount to move in from border along vertical axis- Returns:
- itself for chaining
-
deltaRequiredToCenter
Returns the required translation in order for this bounds origin to sit on the center of the provided rectangle.- Parameters:
targetBounds- rectangle to measure the center of- Returns:
- the delta required to move to center of the targetBounds
-
deltaRequiredToContain
Returns the required translation in order for these to contain the bounds provided.- Parameters:
targetBounds- rectangle to measure the center of- Returns:
- the delta required in order for the bounds to overlap completely the targetBounds
-
toString
Returns a string representation of this PBounds for debugging purposes.- Overrides:
toStringin classRectangle2D.Double- Returns:
- string representation of this PBounds
-