public class Rectangle extends Object
Modifier and Type | Field and Description |
---|---|
float |
maxX
use primitives instead of arrays for the coordinates of the rectangle,
to reduce memory requirements.
|
float |
maxY
use primitives instead of arrays for the coordinates of the rectangle,
to reduce memory requirements.
|
float |
minX
use primitives instead of arrays for the coordinates of the rectangle,
to reduce memory requirements.
|
float |
minY
use primitives instead of arrays for the coordinates of the rectangle,
to reduce memory requirements.
|
Constructor and Description |
---|
Rectangle() |
Rectangle(float x1,
float y1,
float x2,
float y2)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Point p)
Computes the union of this rectangle and the passed point, storing
the result in this rectangle.
|
void |
add(Rectangle r)
Computes the union of this rectangle and the passed rectangle, storing
the result in this rectangle.
|
float |
area()
Compute the area of this rectangle.
|
static float |
area(float minX,
float minY,
float maxX,
float maxY)
Compute the area of a rectangle.
|
float |
aspectRatio() |
Point |
centre() |
boolean |
containedBy(Rectangle r)
Determine whether this rectangle is contained by the passed rectangle
|
static boolean |
contains(float r1MinX,
float r1MinY,
float r1MaxX,
float r1MaxY,
float r2MinX,
float r2MinY,
float r2MaxX,
float r2MaxY)
Determine whether or not one rectangle contains another.
|
boolean |
contains(Rectangle r)
Determine whether this rectangle contains the passed rectangle
|
Rectangle |
copy()
Make a copy of this rectangle
|
static float |
distance(float minX,
float minY,
float maxX,
float maxY,
float pX,
float pY)
Return the distance between a rectangle and a point.
|
float |
distance(Point p)
Return the distance between this rectangle and the passed point.
|
float |
distance(Rectangle r)
Return the distance between this rectangle and the passed rectangle.
|
static float |
distanceSq(float minX,
float minY,
float maxX,
float maxY,
float pX,
float pY) |
boolean |
edgeOverlaps(Rectangle r)
Determine whether an edge of this rectangle overlies the equivalent
edge of the passed rectangle
|
static float |
enlargement(float r1MinX,
float r1MinY,
float r1MaxX,
float r1MaxY,
float r2MinX,
float r2MinY,
float r2MaxX,
float r2MaxY)
Calculate the area by which a rectangle would be enlarged if
added to the passed rectangle..
|
float |
enlargement(Rectangle r)
Calculate the area by which this rectangle would be enlarged if
added to the passed rectangle.
|
boolean |
equals(Object o)
Determine whether this rectangle is equal to a given object.
|
int |
hashCode() |
float |
height() |
static boolean |
intersects(float r1MinX,
float r1MinY,
float r1MaxX,
float r1MaxY,
float r2MinX,
float r2MinY,
float r2MaxX,
float r2MaxY)
Determine whether or not two rectangles intersect
|
boolean |
intersects(Rectangle r)
Determine whether this rectangle intersects the passed rectangle
|
boolean |
sameObject(Object o)
Determine whether this rectangle is the same as another object
Note that two rectangles can be equal but not the same object,
if they both have the same bounds.
|
void |
set(float x1,
float y1,
float x2,
float y2)
Sets the size of the rectangle.
|
void |
set(Rectangle r)
Sets the size of this rectangle to equal the passed rectangle.
|
String |
toString()
Return a string representation of this rectangle, in the form:
(1.2, 3.4), (5.6, 7.8)
|
Rectangle |
union(Rectangle r)
Find the the union of this rectangle and the passed rectangle.
|
float |
width()
Utility methods (not used by JSI); added to
enable this to be used as a generic rectangle class
|
public float minX
public float minY
public float maxX
public float maxY
public Rectangle()
public Rectangle(float x1, float y1, float x2, float y2)
x1
- coordinate of any corner of the rectangley1
- (see x1)x2
- coordinate of the opposite cornery2
- (see x2)public void set(float x1, float y1, float x2, float y2)
x1
- coordinate of any corner of the rectangley1
- (see x1)x2
- coordinate of the opposite cornery2
- (see x2)public void set(Rectangle r)
public Rectangle copy()
public boolean edgeOverlaps(Rectangle r)
public boolean intersects(Rectangle r)
r
- The rectangle that might intersect this rectanglepublic static boolean intersects(float r1MinX, float r1MinY, float r1MaxX, float r1MaxY, float r2MinX, float r2MinY, float r2MaxX, float r2MaxY)
r1MinX
- minimum X coordinate of rectangle 1r1MinY
- minimum Y coordinate of rectangle 1r1MaxX
- maximum X coordinate of rectangle 1r1MaxY
- maximum Y coordinate of rectangle 1r2MinX
- minimum X coordinate of rectangle 2r2MinY
- minimum Y coordinate of rectangle 2r2MaxX
- maximum X coordinate of rectangle 2r2MaxY
- maximum Y coordinate of rectangle 2public boolean contains(Rectangle r)
r
- The rectangle that might be contained by this rectanglepublic static boolean contains(float r1MinX, float r1MinY, float r1MaxX, float r1MaxY, float r2MinX, float r2MinY, float r2MaxX, float r2MaxY)
r1MinX
- minimum X coordinate of rectangle 1r1MinY
- minimum Y coordinate of rectangle 1r1MaxX
- maximum X coordinate of rectangle 1r1MaxY
- maximum Y coordinate of rectangle 1r2MinX
- minimum X coordinate of rectangle 2r2MinY
- minimum Y coordinate of rectangle 2r2MaxX
- maximum X coordinate of rectangle 2r2MaxY
- maximum Y coordinate of rectangle 2public boolean containedBy(Rectangle r)
r
- The rectangle that might contain this rectanglepublic float distance(Point p)
p
- Point to find the distance topublic static float distance(float minX, float minY, float maxX, float maxY, float pX, float pY)
minX
- minimum X coordinate of rectangleminY
- minimum Y coordinate of rectanglemaxX
- maximum X coordinate of rectanglemaxY
- maximum Y coordinate of rectanglepX
- X coordinate of pointpY
- Y coordinate of pointpublic static float distanceSq(float minX, float minY, float maxX, float maxY, float pX, float pY)
public float distance(Rectangle r)
r
- Rectangle to find the distance topublic float enlargement(Rectangle r)
r
- Rectangle to union with this rectangle, in order to
compute the difference in area of the union and the
original rectanglepublic static float enlargement(float r1MinX, float r1MinY, float r1MaxX, float r1MaxY, float r2MinX, float r2MinY, float r2MaxX, float r2MaxY)
r1MinX
- minimum X coordinate of rectangle 1r1MinY
- minimum Y coordinate of rectangle 1r1MaxX
- maximum X coordinate of rectangle 1r1MaxY
- maximum Y coordinate of rectangle 1r2MinX
- minimum X coordinate of rectangle 2r2MinY
- minimum Y coordinate of rectangle 2r2MaxX
- maximum X coordinate of rectangle 2r2MaxY
- maximum Y coordinate of rectangle 2public float area()
public static float area(float minX, float minY, float maxX, float maxY)
minX
- the minimum X coordinate of the rectangleminY
- the minimum Y coordinate of the rectanglemaxX
- the maximum X coordinate of the rectanglemaxY
- the maximum Y coordinate of the rectanglepublic void add(Rectangle r)
r
- Rectangle to add to this rectanglepublic void add(Point p)
p
- Point to add to this rectanglepublic Rectangle union(Rectangle r)
r
- The rectangle to union with this rectanglepublic boolean equals(Object o)
public boolean sameObject(Object o)
o
- The object to compare with this rectangle.public String toString()
public float width()
public float height()
public float aspectRatio()
public Point centre()