Class Rectangle
- java.lang.Object
-
- org.jungrapht.visualization.layout.model.Rectangle
-
public class Rectangle extends Object
Simple, immutable Rectangle class, included to reduce dependency on awt classes- Author:
- Tom Nelson
-
-
Field Summary
Fields Modifier and Type Field Description doubleheightheight (y dimensionstatic RectangleIDENTITYidentity rectangle of zero size at origindoublemaxXx location of lower right cornerdoublemaxYy location of lower right cornerdoublewidthwidth (x dimension)doublexx location of upper-left cornerdoubleyy location of upper left corner
-
Constructor Summary
Constructors Constructor Description Rectangle(double x, double y, double width, double height)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(double ox, double oy)Fail fast for the most common case where the point coordinates are not contained.booleancontains(Point p)booleanequals(Object o)Compare for equalitystatic Rectanglefrom(Point min, Point max)doublegetCenterX()doublegetCenterY()inthashCode()booleanintersects(Rectangle other)fail-fast implementation to reduce computationPointmax()Pointmin()static Rectangleof(double x, double y, double width, double height)static Rectangleof(int width, int height)static Rectangleof(int x, int y, int width, int height)Rectangleoffset(double x, double y)offset the rectangle's location by the passed coordinatesStringtoString()Rectangleunion(double newX, double newY)return a new Rectangle that is is the expansion of this Rectangle to contain the passed PointRectangleunion(Rectangle other)return a union of this rectangle and the other rectangle
-
-
-
Field Detail
-
x
public final double x
x location of upper-left corner
-
y
public final double y
y location of upper left corner
-
width
public final double width
width (x dimension)
-
height
public final double height
height (y dimension
-
maxX
public final double maxX
x location of lower right corner
-
maxY
public final double maxY
y location of lower right corner
-
IDENTITY
public static Rectangle IDENTITY
identity rectangle of zero size at origin
-
-
Method Detail
-
of
public static Rectangle of(int x, int y, int width, int height)
- Parameters:
x- location of upper left cornery- location of upper left cornerwidth- size in x dimensionheight- size in y dimension- Returns:
- a new Rectangle with the passed properties
-
of
public static Rectangle of(int width, int height)
-
of
public static Rectangle of(double x, double y, double width, double height)
- Parameters:
x- location of upper left cornery- location of upper left cornerwidth- size in x dimensionheight- size in y dimension- Returns:
- a new Rectangle with the passed properties
-
getCenterX
public double getCenterX()
- Returns:
- the x coordinate of the center of this Rectangle
-
getCenterY
public double getCenterY()
- Returns:
- the y coordinate of the center of this Rectangle
-
intersects
public boolean intersects(Rectangle other)
fail-fast implementation to reduce computation- Parameters:
other- another Rectangle to compare- Returns:
- whether there is a non-zero intersection of the 2 shapes
-
contains
public boolean contains(Point p)
- Parameters:
p- point to test- Returns:
- true if the coordinate is contained, false otherwise
-
min
public Point min()
-
max
public Point max()
-
contains
public boolean contains(double ox, double oy)Fail fast for the most common case where the point coordinates are not contained. Implementation leaves space for debug breakpoints- Parameters:
ox- coodinate to testoy- coordinate to test- Returns:
- true if the coordinate is contained, false otherwise
-
offset
public Rectangle offset(double x, double y)
offset the rectangle's location by the passed coordinates- Parameters:
x- horizontal offsety- vertical offset- Returns:
- a new Rectangle offset by the passed coordinates
-
union
public Rectangle union(double newX, double newY)
return a new Rectangle that is is the expansion of this Rectangle to contain the passed Point- Parameters:
newX- x coordinate of expansion pointnewY- y coordinate of expansion point- Returns:
- a new Rectangle that was expanded to include the passed coordinates
-
union
public Rectangle union(Rectangle other)
return a union of this rectangle and the other rectangle- Parameters:
other-- Returns:
-
equals
public boolean equals(Object o)
Compare for equality
-
hashCode
public int hashCode()
-
-