public final class RectD extends Object implements com.yworks.yfiles.utils.IStruct, IRectangle
This class differs from other possible implementation in the way negative width
and height
properties
are handled and interpreted. Width and/or height values may be negative in which case the rectangle is considered empty
and non-existent. Empty rectangles are not considered in union-like
operations, whereas
rectangles with width
and height
of 0.0d
are. This class implements the IRectangle
interface so that it can be used in methods that require that interface.
Modifier and Type | Field and Description |
---|---|
static RectD |
EMPTY
An
empty rectangle. |
double |
height
Gets the height of the rectangle.
|
static RectD |
INFINITE
An infinite rectangle.
|
double |
width
Gets the width of the rectangle.
|
double |
x
Gets the X coordinate of the upper left corner of the rectangle.
|
double |
y
Gets the Y coordinate of the upper left corner of the rectangle.
|
Constructor and Description |
---|
RectD() |
RectD(double x,
double y,
double width,
double height)
Initializes a new instance.
|
RectD(IRectangle rectangle)
Initializes a new instance of the
RectD struct with the initial values obtained from the given rectangle. |
RectD(PointD p1,
PointD p2)
Initializes a new instance using two point to define the bounds.
|
RectD(PointD location,
SizeD size)
|
Modifier and Type | Method and Description |
---|---|
static RectD |
add(RectD rectangle,
PointD point)
Returns the union of the given rectangle and the given point.
|
static RectD |
add(RectD firstRectangle,
RectD secondRectangle)
Returns the union of the given rectangles.
|
boolean |
contains(PointD point,
double eps)
Determines whether this rectangle contains the specified point with respect to a given epsilon.
|
static RectD |
convertFrom(MutableRectangle rectangle)
Performs an explicit conversion from
MutableRectangle to RectD . |
static MutableRectangle |
convertToMutableRectangle(RectD rectangle)
Performs an explicit conversion from
RectD to MutableRectangle . |
boolean |
equals(Object other)
Indicates whether this instance and a specified object are equal.
|
static boolean |
equals(RectD firstRectangle,
RectD secondRectangle)
|
PointD |
findLineIntersection(PointD inner,
PointD outer)
Finds the intersection between a rectangle and a line.
|
static RectD |
fromCenter(PointD center,
SizeD size)
Creates a new instance given the center of the rectangle and its size.
|
double |
getArea()
|
PointD |
getBottomLeft()
Gets the coordinates of the bottom left corner of the rectangle.
|
PointD |
getBottomRight()
Gets the coordinates of the bottom right corner of the rectangle.
|
PointD |
getCenter()
|
double |
getCenterX()
Gets the center X coordinate of the rectangle.
|
double |
getCenterY()
Gets the center Y coordinate of the rectangle.
|
RectD |
getEnlarged(double size)
Creates an enlarged instance of this rectangle using the same insets for all sides.
|
RectD |
getEnlarged(InsetsD insets)
Creates an enlarged instance that is the same as this one but enlarged by the specified insets.
|
double |
getHeight()
Gets or sets the height of the rectangle.
|
double |
getMaxX()
Gets the coordinates of the right border for this struct.
|
double |
getMaxY()
Gets the coordinates of the lower border for this struct.
|
double |
getMinX()
Gets the X coordinates of the left side of this instance.
|
double |
getMinY()
Gets the Y coordinates of the top side of this instance.
|
SizeD |
getSize()
Gets the size of this instance.
|
PointD |
getTopLeft()
Gets the coordinates of the top left corner of the rectangle.
|
PointD |
getTopRight()
Gets the coordinates of the top right corner of the rectangle.
|
RectD |
getTransformed(Matrix2D transform)
Transforms this instance using specified transform storing the bounds in place.
|
RectD |
getTranslated(PointD delta)
|
double |
getWidth()
Gets or sets the width of the rectangle.
|
double |
getX()
Gets or sets the X coordinate of the upper left corner of the rectangle.
|
double |
getY()
Gets or sets the Y coordinate of the upper left corner of the rectangle.
|
int |
hashCode()
Returns the hash code for this instance.
|
boolean |
intersects(IOrientedRectangle rectangle,
double eps)
Determines whether this rectangle intersects an
IOrientedRectangle , given an epsilon. |
boolean |
intersects(RectD rectangle)
Determines whether the bounds of this instance intersect with the bounds of the specified rectangle.
|
boolean |
intersectsLine(PointD start,
PointD end)
Determines whether this rectangle intersects a line.
|
boolean |
intersectsPolyline(Iterable<IPoint> points)
Determines whether a rectangle intersects a polygonal line.
|
boolean |
isEmpty()
Gets a value indicating whether this instance is considered empty.
|
boolean |
isFinite()
Gets a value indicating whether this instance is finite.
|
IMutableRectangle |
toMutableRectangle()
Creates an
IMutableRectangle using the values from this instance. |
PointD |
toPointD()
Copies the current values of the coordinates of the point to a
PointD struct. |
RectD |
toRectD()
Copies the current values of the rectangle to
RectD struct. |
SizeD |
toSizeD()
Gets the current size of the rectangle as a
SizeD struct. |
String |
toString()
Creates a human readable from of this instance.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
contains, contains, getDynamicCenter, getDynamicPoint
distanceTo
public static final RectD EMPTY
public final double height
public static final RectD INFINITE
width
and height
are set to Double.POSITIVE_INFINITY
, x
and y
are set to
Double.NEGATIVE_INFINITY
.
public final double width
public final double x
public final double y
public RectD()
public RectD(double x, double y, double width, double height)
public RectD(IRectangle rectangle)
RectD
struct with the initial values obtained from the given rectangle.rectangle
- The rectangle to retrieve the initial values from.public RectD(PointD p1, PointD p2)
This will always result in non-IsEmpty
rectangles as the coordinates of the points are sorted so that
the smaller gets assigned to x
and y
respectively and the greater ones define the width
and
height
.
p1
- The first point to determine the bounds.p2
- The second point to determine the bounds.public static final RectD add(RectD rectangle, PointD point)
If rectangle
IsEmpty
, the point will be used to set the x
and y
coordinates
and width
and height
will be set to 0.0d
, making it non-empty
.
rectangle
- The rectangle to enlarge.point
- The point to add to the rectangle.public static final RectD add(RectD firstRectangle, RectD secondRectangle)
firstRectangle
- The first rectangle.secondRectangle
- The second rectangle.public final boolean contains(PointD point, double eps)
point
- The point to test.eps
- The positive epsilon distance that the point may lie outside the rectangle and still be considered contained.true
if this rectangle contains the specified point; false
otherwise. An empty
instance never contains any point. A point is considered to be contained in the rectangle when the coordinates are not
smaller than MinX
and MinY
minus eps
nor greater than MaxX
and MaxY
plus eps
.public static final RectD convertFrom(MutableRectangle rectangle)
MutableRectangle
to RectD
.rectangle
- The rectangle to convert.public static final MutableRectangle convertToMutableRectangle(RectD rectangle)
RectD
to MutableRectangle
.rectangle
- The rectangle to convert.public boolean equals(Object other)
public final PointD findLineIntersection(PointD inner, PointD outer)
inner
- The coordinates of a point lying inside the rectangle.outer
- The coordinates of a point lying outside the rectangle.null
otherwise.public static final RectD fromCenter(PointD center, SizeD size)
center
- The center to use.size
- The size to assign.center
and size is size
public final double getArea()
public final PointD getBottomLeft()
getBottomLeft
in interface IRectangle
x
and MaxY
.public final PointD getBottomRight()
getBottomRight
in interface IRectangle
MaxX
and MaxY
.public final PointD getCenter()
getCenter
in interface IRectangle
public final double getCenterX()
public final double getCenterY()
public final RectD getEnlarged(double size)
If this instance IsEmpty
, the result will be the same.
size
- The inset to add to each of the sides to grow the new instance.getEnlarged(InsetsD)
public final RectD getEnlarged(InsetsD insets)
If this instance IsEmpty
, the same will be returned.
insets
- The insets to use to add to the instance.public final double getHeight()
public final double getMaxX()
getMaxX
in interface IRectangle
x
and width
or simply x
if the width is
non-positive.public final double getMaxY()
getMaxY
in interface IRectangle
y
and height
or simply y
if the height is
non-positive.public final double getMinX()
public final double getMinY()
public final SizeD getSize()
public final PointD getTopLeft()
getTopLeft
in interface IRectangle
x
and y
.public final PointD getTopRight()
getTopRight
in interface IRectangle
MaxX
and y
.public final RectD getTransformed(Matrix2D transform)
transform
- The transform matrix to apply to this instance.public final double getWidth()
public final double getX()
public final double getY()
public int hashCode()
public final boolean intersects(IOrientedRectangle rectangle, double eps)
IOrientedRectangle
, given an epsilon.rectangle
- The IOrientedRectangle
to test.eps
- A positive value allows for fuzzy hit testing. If the point lies outside the given object but it's distance is less than
or equal to that value, it will be considered a hit.public final boolean intersects(RectD rectangle)
rectangle
- The rectangle to check.Area
.public final boolean intersectsLine(PointD start, PointD end)
start
- The first end point of the line.end
- The second end point of the line.public final boolean intersectsPolyline(Iterable<IPoint> points)
points
- The list of points that is interpreted as a number of line segments.true
if the rectangle intersects at least one segment of the line.public final boolean isEmpty()
Yields true
if this at least one of width
or height
is negative; false
otherwise. Note
that a width and height of both 0.0d
is not considered empty for this implementation.
isEmpty
in interface IRectangle
public final boolean isFinite()
public final IMutableRectangle toMutableRectangle()
IMutableRectangle
using the values from this instance.public PointD toPointD()
IPoint
PointD
struct.
This method is useful to obtain a copy of the state and for making use of the various utility methods that are provided
by PointD
.
toPointD
in interface IPoint
PointD.toMutablePoint()
,
IMutablePoint.relocate(PointD)
public RectD toRectD()
IRectangle
RectD
struct.
This method can be used to obtain a copy of the current state of the rectangle and for using the utility methods that
are available for the RectD
type.
toRectD
in interface IRectangle
RectD
that holds the values of the rectangle
at the time of the invocation.IMutableRectangle.reshape(double, double, double, double)
,
toMutableRectangle()
public SizeD toSizeD()
IRectangle
SizeD
struct.toSizeD
in interface IRectangle
toSizeD
in interface ISize