public class YRectangle extends YDimension implements IPlaneObject
Constructor and Description |
---|
YRectangle()
Creates a new rectangle with upper left corner (0,0) and size (0,0).
|
YRectangle(double x,
double y,
double width,
double height)
Creates a new rectangle with given upper left corner and size.
|
YRectangle(YPoint pos,
YDimension size)
Creates a new rectangle with given upper left corner and size.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object o) |
boolean |
contains(double x,
double y)
Checks whether or not this
YRectangle contains the given point. |
boolean |
contains(double x,
double y,
double width,
double height)
Checks whether or not this
YRectangle contains the rectangle defined by the given frame. |
static boolean |
contains(double rx,
double ry,
double rw,
double rh,
double x,
double y)
Determines whether the specified rectangle contains the specified point.
|
static boolean |
contains(double rx,
double ry,
double rw,
double rh,
double x,
double y,
boolean closed)
Determines whether the specified rectangle contains the specified point.
|
boolean |
contains(YPoint p)
Checks whether or not this
YRectangle contains the given point. |
boolean |
contains(YRectangle p)
Checks whether or not this
YRectangle contains the given rectangle. |
boolean |
equals(Object o)
Tests a dimension to equality to another dimension.
|
YRectangle |
getBoundingBox()
Gets this object.
|
double |
getEuclideanDistance(YRectangle other)
Returns the Euclidean distance to the passed rectangle.
|
YPoint |
getLocation()
Gets coordinates of upper left corner.
|
double |
getManhattanDistance(YRectangle other)
Returns the Manhattan distance to the passed rectangle.
|
double |
getX()
Gets x-coordinate of upper left corner.
|
double |
getY()
Gets y-coordinate of upper left corner.
|
int |
hashCode() |
static boolean |
intersects(YRectangle r1,
YRectangle r2)
Returns whether or not the given rectangles intersect.
|
String |
toString()
Returns a string representation of this rectangle.
|
getHeight, getWidth
public YRectangle()
public YRectangle(double x, double y, double width, double height)
x
- x-coordinate of upper left corner of the rectangle.y
- y-coordinate of upper left corner of the rectangle.width
- width of the rectangle.height
- height of the rectangle.public YRectangle(YPoint pos, YDimension size)
pos
- upper left corner of the rectangle.size
- size of the rectangle.public int compareTo(Object o)
compareTo
in interface Comparable
compareTo
in class YDimension
public boolean contains(double x, double y)
YRectangle
contains the given point.x
- the x-coordinate of the point to check.y
- the x-coordinate of the point to check.true
if the point lies inside the rectangle; false
otherwise.public boolean contains(double x, double y, double width, double height)
YRectangle
contains the rectangle defined by the given frame.public static final boolean contains(double rx, double ry, double rw, double rh, double x, double y)
rx
- the x-coordinate of the upper left corner of the rectangle.ry
- the y-coordinate of the upper left corner of the rectangle.rw
- the width of the rectangle.rh
- the height of the rectangle.x
- the x-coordinate of the point to check.y
- the x-coordinate of the point to check.true
if the point lies inside the rectangle; false
otherwise.public static final boolean contains(double rx, double ry, double rw, double rh, double x, double y, boolean closed)
rx
- the x-coordinate of the upper left corner of the rectangle.ry
- the y-coordinate of the upper left corner of the rectangle.rw
- the width of the rectangle.rh
- the height of the rectangle.x
- the x-coordinate of the point to check.y
- the x-coordinate of the point to check.closed
- if true
, all points on the border of the rectangle are considered to be contained.true
if the point lies inside the rectangle; false
otherwise.public boolean contains(YPoint p)
YRectangle
contains the given point.public boolean contains(YRectangle p)
YRectangle
contains the given rectangle.public boolean equals(Object o)
YDimension
equals
in class YDimension
public YRectangle getBoundingBox()
getBoundingBox
in interface IPlaneObject
public double getEuclideanDistance(YRectangle other)
If they overlap, the distance is 0.
other
- the second rectangle.public final YPoint getLocation()
public double getManhattanDistance(YRectangle other)
If they overlap the distance is 0.
other
- the second rectangle.public final double getX()
public final double getY()
public int hashCode()
hashCode
in class YDimension
public static final boolean intersects(YRectangle r1, YRectangle r2)
public String toString()
toString
in class YDimension