Package org.jfree.layouting.util.geom
Class StrictBounds
- java.lang.Object
-
- org.jfree.layouting.util.geom.StrictBounds
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class StrictBounds extends java.lang.Object implements java.io.Serializable, java.lang.CloneableThe StrictBounds class is a replacement for the Rectangle2D classes. This class uses integer mathematics instead of floating point values to achive a higher degree of stability.- Author:
- Thomas Morgner
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StrictBounds()DefaultConstructor.StrictBounds(long x, long y, long width, long height)Creates a StrictBounds object with the given coordinates, width and height.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(StrictBounds bounds)Adds the given bounds to this bounds instance.java.lang.Objectclone()Returns a copy of this bounds object.booleancontains(long x, long y)Checks, whether this rectangle contains the given point.static booleancontains(StrictBounds rect1, StrictBounds rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).StrictBoundscreateIntersection(StrictBounds bounds)Intersects this rectangle with the given bounds.StrictBoundscreateUnion(StrictBounds bg)Creates a union from this and the given rectangle.booleanequals(java.lang.Object o)Checks, whether the given object is a StrictBounds instance convering the same area as these bounds.longgetHeight()Returns the height of the framing rectangle in micro points.StrictBoundsgetLockedInstance()Returns a copy of this bounds object which cannot be modified anymore.StrictBoundsgetUnlockedInstance()Returns a copy of this bounds object which can be modified later.longgetWidth()Returns the width of the framing rectangle in micro points.longgetX()Returns the X coordinate of the upper left corner of the framing rectangle in micro points.longgetY()Returns the Y coordinate of the upper left corner of the framing rectangle in micro points.inthashCode()Computes the hashcode for this rectangle.static booleanintersects(StrictBounds rect1, StrictBounds rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).booleanisEmpty()Determines whether theRectangularShapeis empty.booleanisLocked()Checks, whether this bounds object is locked.voidsetRect(long x, long y, long w, long h)Sets the location and size of thisStrictBoundsto the specified double values.java.lang.StringtoString()Returns a string representation of these bounds.
-
-
-
Constructor Detail
-
StrictBounds
public StrictBounds()
DefaultConstructor.
-
StrictBounds
public StrictBounds(long x, long y, long width, long height)Creates a StrictBounds object with the given coordinates, width and height.- Parameters:
x- the x-coordinatey- the y-coordinatewidth- the width of the rectangleheight- the height of the rectangle
-
-
Method Detail
-
isLocked
public boolean isLocked()
Checks, whether this bounds object is locked.- Returns:
- true, if the bounds are locked and therefore immutable, false otherwise.
-
getLockedInstance
public StrictBounds getLockedInstance()
Returns a copy of this bounds object which cannot be modified anymore.- Returns:
- a locked copy.
-
getUnlockedInstance
public StrictBounds getUnlockedInstance()
Returns a copy of this bounds object which can be modified later.- Returns:
- an unlocked copy.
-
setRect
public void setRect(long x, long y, long w, long h)Sets the location and size of thisStrictBoundsto the specified double values.- Parameters:
x- the coordinates to which to set the location of the upper left corner of thisStrictBoundsy- the coordinates to which to set the location of the upper left corner of thisStrictBoundsw- the value to use to set the width of thisStrictBoundsh- the value to use to set the height of thisStrictBounds
-
getHeight
public long getHeight()
Returns the height of the framing rectangle in micro points.- Returns:
- the height of the framing rectangle.
-
getWidth
public long getWidth()
Returns the width of the framing rectangle in micro points.- Returns:
- the width of the framing rectangle.
-
getX
public long getX()
Returns the X coordinate of the upper left corner of the framing rectangle in micro points.- Returns:
- the x coordinate of the upper left corner of the framing rectangle.
-
getY
public long getY()
Returns the Y coordinate of the upper left corner of the framing rectangle in micro points.- Returns:
- the y coordinate of the upper left corner of the framing rectangle.
-
isEmpty
public boolean isEmpty()
Determines whether theRectangularShapeis empty. When theRectangularShapeis empty, it encloses no area.- Returns:
trueif theRectangularShapeis empty;falseotherwise.
-
clone
public java.lang.Object clone()
Returns a copy of this bounds object. This method will never throw a 'CloneNotSupportedException'.- Overrides:
clonein classjava.lang.Object- Returns:
- the cloned instance.
-
contains
public boolean contains(long x, long y)Checks, whether this rectangle contains the given point.- Parameters:
x- the x-coordinate of the point.y- the y-coordinate of the point.- Returns:
- true, if the point is inside or directly on the border of this rectangle, false otherwise.
-
intersects
public static boolean intersects(StrictBounds rect1, StrictBounds rect2)
Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).- Parameters:
rect1- the first rectangle.rect2- the second rectangle.- Returns:
- true, if the rectangles intersect each other, false otherwise.
-
add
public void add(StrictBounds bounds)
Adds the given bounds to this bounds instance. The resulting rectangle will fully contain both rectangles.- Parameters:
bounds- the rectangle that should be added.
-
createIntersection
public StrictBounds createIntersection(StrictBounds bounds)
Intersects this rectangle with the given bounds. The resulting rectangle will cover the space, that is occupied by both rectangles at the same time.- Parameters:
bounds- the other rectangle.- Returns:
- the resulting intersection.
-
contains
public static boolean contains(StrictBounds rect1, StrictBounds rect2)
Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).- Parameters:
rect1- the first rectangle.rect2- the second rectangle.- Returns:
- A boolean.
-
equals
public boolean equals(java.lang.Object o)
Checks, whether the given object is a StrictBounds instance convering the same area as these bounds.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the other object.- Returns:
- true, if the other object is equal to this object, false otherwise.
-
hashCode
public int hashCode()
Computes the hashcode for this rectangle.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the computed hashcode.
-
toString
public java.lang.String toString()
Returns a string representation of these bounds.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representing this object.
-
createUnion
public StrictBounds createUnion(StrictBounds bg)
Creates a union from this and the given rectangle. This is similiar to calling 'add'. Calling this method does not modify the original and there are no guarantees, that the resulting rectangle has a positive width or height.- Parameters:
bg- the other rectangle.- Returns:
- the resulting union rectangle.
-
-