public final class Rectangle extends Object
Not a geometry, to be used for communicating 2D cartesian rectangles.
Constructor and Description |
---|
Rectangle()
Creates a
Rectangle at the origin, with width and height 0. |
Rectangle(Coordinate corner1,
Coordinate corner2)
Creates a
Rectangle with the given corners. |
Rectangle(double x,
double y,
double width,
double height)
Creates a
Rectangle with the provided x, y, width, and height values. |
Rectangle(Rectangle other) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
Coordinate |
getCenter()
Returns the coordinate in the center of this rectangle.
|
double |
getHeight()
The rectangle's height.
|
Coordinate |
getLowerLeftCorner()
Returns the coordinate at the lower left corner of this rectangle.
|
Coordinate |
getLowerRightCorner()
Returns the coordinate at the lower right corner of this rectangle.
|
Coordinate |
getUpperLeftCorner()
Returns the coordinate at the upper left corner of this rectangle.
|
Coordinate |
getUpperRightCorner()
Returns the coordinate at the upper right corner of this rectangle.
|
double |
getWidth()
The rectangle's width.
|
double |
getX()
The lower left corner's x-ordinate.
|
double |
getY()
The lower left corner's y-ordinate.
|
void |
grow(double margin)
Grows this rectangle by the given margin.
|
int |
hashCode()
Returns the hash for this rectangle.
|
boolean |
isValid()
Returns whether all fields are neither not-a-number nor infinite and the width and height are non-negative.
|
String |
toString() |
public Rectangle()
Rectangle
at the origin, with width and height 0.public Rectangle(double x, double y, double width, double height)
Rectangle
with the provided x, y, width, and height values.x
- the lower left corner's x-ordinatey
- the lower left corner's y-ordinatewidth
- the rectangle's widthheight
- the rectangle's heightpublic Rectangle(@NotNull Coordinate corner1, @NotNull Coordinate corner2)
Rectangle
with the given corners.
The corners do not need to have any particular relation to each other. Only the x and y ordinates of the corners are considered.
corner1
- one corner positioncorner2
- another corner positionpublic Rectangle(@NotNull Rectangle other)
public void grow(double margin)
The lower left corner is moved in the direction of negative x and y by margin. The upper right corner is moved in the direction of positive x and y by margin.
margin
- a marginpublic double getX()
public double getY()
public double getWidth()
public double getHeight()
@NotNull public Coordinate getLowerLeftCorner()
@NotNull public Coordinate getLowerRightCorner()
@NotNull public Coordinate getUpperLeftCorner()
@NotNull public Coordinate getUpperRightCorner()
@NotNull public Coordinate getCenter()
public boolean isValid()
public int hashCode()