public final class MutableRectangle extends Object implements IMutableRectangle, IOrientedRectangle, ICloneable
IMutablePoint
and IMutableSize
.
This implementation delegates the storage to implementations of IMutablePoint
for the upper left corner of the
rectangle and IMutableSize
for the size of the rectangle. members. As a convenience it implements the
IOrientedRectangle
, and the ICloneable
interfaces.
IRectangle
,
IMutableRectangle
EMPTY
Constructor and Description |
---|
MutableRectangle()
Creates a new empty instance located at the origin with width and height set to
-1 . |
MutableRectangle(double x,
double y,
double width,
double height)
Creates a new instance using the provided values to initialize the position and size.
|
MutableRectangle(IMutablePoint location,
IMutableSize size)
Creates a new instance using the provided implementation for the storage of the position and size of the rectangle.
|
MutableRectangle(IRectangle rectangle)
Creates a new instance initialized to the values of the provided argument.
|
MutableRectangle(PointD location,
SizeD size)
Creates a new instance using the provided values to initialize the position and size.
|
Modifier and Type | Method and Description |
---|---|
MutableRectangle |
clone()
Creates a copy of the current state of this instance using a new
MutablePoint and Size to
store the position and size. |
boolean |
equals(IRectangle other) |
boolean |
equals(Object other)
Implements the equals method by comparing the given object's values.
|
double |
getAnchorX()
Implements the
IOrientedRectangle and will return the x coordinate of the Location . |
double |
getAnchorY()
|
PointD |
getCenter()
Gets the coordinates of the center of the rectangle as a
PointD . |
IMutablePoint |
getDynamicCenter()
Create a dynamic
IMutablePoint implementation
that always points to the center of the given rectangle. |
double |
getHeight()
Gets the height of this instance from the
Size instance. |
IPoint |
getLocation()
Returns the instance that stores the position of this rectangle.
|
ISize |
getSize()
Returns the instance that stores the size of this rectangle.
|
double |
getUpX()
Always returns
0 . |
double |
getUpY()
Always returns
-1 . |
double |
getWidth()
Gets the width of this instance from the
Size instance. |
double |
getX()
Gets the x coordinate of the upper left corner of this instance from the
Location instance. |
double |
getX2()
|
double |
getY()
Gets the y coordinate of the upper left corner of this instance from the
Location instance. |
double |
getY2()
|
boolean |
isEmpty()
Returns whether this instance has negative width or height.
|
void |
moveBy(PointD delta)
Moves this rectangle by applying the offset to the
Location . |
void |
setAnchorX(double value)
Implements the
IOrientedRectangle and will return the x coordinate of the Location . |
void |
setAnchorY(double value)
|
void |
setHeight(double value)
Sets the height of this instance from the
Size instance. |
void |
setLocation(IPoint value)
Returns the instance that stores the position of this rectangle.
|
void |
setSize(ISize value)
Returns the instance that stores the size of this rectangle.
|
void |
setWidth(double value)
Sets the width of this instance from the
Size instance. |
void |
setX(double value)
Sets the x coordinate of the upper left corner of this instance from the
Location instance. |
void |
setX2(double value)
|
void |
setY(double value)
Sets the y coordinate of the upper left corner of this instance from the
Location instance. |
void |
setY2(double value)
|
SizeD |
toSizeD()
Gets the current size of the rectangle as a
SizeD struct. |
String |
toString() |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add, add, reshape, reshape, reshape, reshape, resize, setCenter, setToUnion
resize, resize
relocate, relocate, relocate
contains, contains, getBottomLeft, getBottomRight, getDynamicPoint, getMaxX, getMaxY, getTopLeft, getTopRight, toRectD
distanceTo, toPointD
contains, createTransform, getAnchorLocation, getBounds, getTopLeftLocation, getUp, hits
public MutableRectangle()
-1
.public MutableRectangle(double x, double y, double width, double height)
An instance of MutablePoint
will be used to store the position and an instance of Size
will
be used to store the size.
x
- The x coordinate of the upper left corner of the rectangle.y
- The y coordinate of the upper left corner of the rectangle.width
- The width of the rectangle.height
- The height of the rectangle.public MutableRectangle(IMutablePoint location, IMutableSize size)
The instances provided will be referenced by this instance. This instance will be used as a live view over the provided instances. Changes to them will indirectly change the state of this instance and changes applied through this instance will be written to the referenced implementations.
location
- The provider for the dynamic position of this instance.size
- The provider for the dynamic size of this instance.public MutableRectangle(IRectangle rectangle)
public MutableRectangle(PointD location, SizeD size)
An instance of MutablePoint
will be used to store the position and an instance of Size
will
be used to store the size.
location
- The coordinates of the upper left corner of the rectangle.size
- The size of the rectangle.public final MutableRectangle clone()
MutablePoint
and Size
to
store the position and size.clone
in interface ICloneable
clone
in class Object
MutableRectangle
Object.clone()
public final boolean equals(IRectangle other)
public boolean equals(Object other)
Note that RectD
cannot be equal. Only instances of this type and the ones returned by
the factory methods of this type can be equal to each other.
public final double getAnchorX()
IOrientedRectangle
and will return the x coordinate of the Location
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
getAnchorX
in interface IOrientedRectangle
setAnchorX(double)
public final double getAnchorY()
IOrientedRectangle
and will return the y coordinate of the Location
plus
the Height
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
getAnchorY
in interface IOrientedRectangle
setAnchorY(double)
public PointD getCenter()
PointD
.getCenter
in interface IOrientedRectangle
getCenter
in interface IRectangle
public IMutablePoint getDynamicCenter()
IMutablePoint
implementation
that always points to the center of the given rectangle.
Modifying the point's x and y coordinates, will in fact move the rectangle's
position accordingly.
This method delegates to RectangleExtensions.getDynamicCenter(IMutableRectangle)
.
getDynamicCenter
in interface IMutableRectangle
getDynamicCenter
in interface IOrientedRectangle
getDynamicCenter
in interface IRectangle
public final double getHeight()
Size
instance.
Note that that depending on the implementation used for holding the size the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
getHeight
in interface IMutableSize
getHeight
in interface ISize
setHeight(double)
public final IPoint getLocation()
This will return a live view of the position of this rectangle. However setting a position instance will only copy the values of the point provided to the current position.
setLocation(IPoint)
public final ISize getSize()
This will return a live view of the size of this rectangle. However setting a size instance will only copy the values of the size provided to the current size.
setSize(ISize)
public final double getUpX()
0
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
getUpX
in interface IOrientedRectangle
public final double getUpY()
-1
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
getUpY
in interface IOrientedRectangle
public final double getWidth()
Size
instance.
Note that depending on the implementation used for holding the size the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
getWidth
in interface IMutableSize
getWidth
in interface ISize
setWidth(double)
public final double getX()
Location
instance.
Note that depending on the implementation used for holding the position the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
getX
in interface IMutablePoint
getX
in interface IPoint
setX(double)
public final double getX2()
Location
and Size
instances.
Setting this value will update the width accordingly. Note that depending on the implementation used for holding the Size
the results may vary. However the default implementation will do just that: read and write the values without modifying
them in any way.
setX2(double)
public final double getY()
Location
instance.
Note that depending on the implementation used for holding the position the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
getY
in interface IMutablePoint
getY
in interface IPoint
setY(double)
public final double getY2()
Location
and Size
instances.
Setting this value will update the height accordingly. Note that depending on the implementation used for holding the Size
the results may vary. However the default implementation will do just that: read and write the values without modifying
them in any way.
setY2(double)
public final boolean isEmpty()
isEmpty
in interface IRectangle
public final void moveBy(PointD delta)
Location
.delta
- The offset to move the rectangle's position by.public final void setAnchorX(double value)
IOrientedRectangle
and will return the x coordinate of the Location
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
value
- The AnchorX to set.getAnchorX()
public final void setAnchorY(double value)
IOrientedRectangle
and will return the y coordinate of the Location
plus
the Height
.
This implementation behaves like an IOrientedRectangle
that is anchored at the lower left corner of this
rectangle and whose up vector is (0, -1).
value
- The AnchorY to set.getAnchorY()
public final void setHeight(double value)
Size
instance.
Note that that depending on the implementation used for holding the size the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
setHeight
in interface IMutableSize
value
- The Height to set.getHeight()
public final void setLocation(IPoint value)
This will return a live view of the position of this rectangle. However setting a position instance will only copy the values of the point provided to the current position.
value
- The Location to set.getLocation()
public final void setSize(ISize value)
This will return a live view of the size of this rectangle. However setting a size instance will only copy the values of the size provided to the current size.
value
- The Size to set.getSize()
public final void setWidth(double value)
Size
instance.
Note that depending on the implementation used for holding the size the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
setWidth
in interface IMutableSize
value
- The Width to set.getWidth()
public final void setX(double value)
Location
instance.
Note that depending on the implementation used for holding the position the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
setX
in interface IMutablePoint
value
- The X to set.getX()
public final void setX2(double value)
Location
and Size
instances.
Setting this value will update the width accordingly. Note that depending on the implementation used for holding the Size
the results may vary. However the default implementation will do just that: read and write the values without modifying
them in any way.
value
- The X2 to set.getX2()
public final void setY(double value)
Location
instance.
Note that depending on the implementation used for holding the position the results may vary. However the default implementation will do just that: read and write the values without modifying them in any way.
setY
in interface IMutablePoint
value
- The Y to set.getY()
public final void setY2(double value)
Location
and Size
instances.
Setting this value will update the height accordingly. Note that depending on the implementation used for holding the Size
the results may vary. However the default implementation will do just that: read and write the values without modifying
them in any way.
value
- The Y2 to set.getY2()
public SizeD toSizeD()
SizeD
struct.
This method delegates to RectangleExtensions.toSizeD(IRectangle)
.
toSizeD
in interface IOrientedRectangle
toSizeD
in interface IRectangle
toSizeD
in interface ISize