RectF
Rectangle type.
Header | #include "nativeui/gfx/geometry/rect_f.h" |
Namespace | namespace nu |
Type | class |
This type defines a simple integer rectangle class. The containment semantics are array-like; that is, the coordinate (x, y) is considered to be contained by the rectangle, but the coordinate (x + width, y) is not.
The class will happily let you create malformed rectangles (that is, rectangles with negative width and/or height), but there will be assertions in the operations (such as Contains()) to complain in this case.
Constructors
RectF()
Create an empty rectangle.
RectF(float width, float height)
Create a rectangle with width
and height
, positioned at (0, 0).
Parameters
float
widthfloat
height
RectF(float x, float y, float width, float height)
Create a rectangle defined with x
, y
, width
, height
.
Parameters
float
xfloat
yfloat
widthfloat
height
RectF(const SizeF& size)
Create a rectangle with size
, positioned at (0, 0).
Parameters
const SizeF&
size
RectF(const PointF& origin, const SizeF& size)
Create a rectangle with origin
and size
.
Parameters
const PointF&
originconst SizeF&
size
Methods
float x() const
Return X coordinate.
Return
float
void set_x(float x)
Set X coordinate.
Parameters
float
x
float y() const
Return Y coordinate.
Return
float
void set_y(float y)
Set Y coordinate.
Parameters
float
y
float width() const
Return rectangle width.
Return
float
void set_width(float width)
Set rectangle width.
Parameters
float
width
float height() const
Return rectangle height.
Return
float
void set_height(float height)
Set rectangle height.
Parameters
float
height
const PointF& origin() const
Return origin.
Return
const PointF&
void set_origin(const PointF& origin)
Set origin.
Parameters
const PointF&
origin
const SizeF& size() const
Return size.
Return
const SizeF&
void set_size(const SizeF& size)
Set size.
Parameters
const SizeF&
size
float right() const
Return the x coordinate of lower-right corner of the rectangle.
Return
float
float bottom() const
Return the y coordinate of lower-right corner of the rectangle.
Return
float
Vector2dF OffsetFromOrigin() const
Return the vector version of upper-left corner.
Return
Vector2dF
void Inset(float horizontal, float vertical)
Shrink the rectangle by a horizontal
and vertical
distance on all
sides.
Parameters
float
horizontalfloat
vertical
void Inset(const InsetsF& insets)
Shrink the rectangle by the given insets
.
Parameters
const InsetsF&
insets
void Inset(float left, float top, float right, float bottom)
Shrink the rectangle by the specified amount on each side.
Parameters
float
leftfloat
topfloat
rightfloat
bottom
void Offset(float horizontal, float vertical);
Move the rectangle by a horizontal
and vertical
distance.
Parameters
float
horizontalfloat
vertical
void Offset(const Vector2dF& distance)
Move the rectangle by the distance
vector.
Parameters
const Vector2dF&
distance
bool IsEmpty() const
Return true
if the area of the rectangle is zero.
Return
bool
bool Contains(float x, float y) const
Return true
if the point identified by point x
and y
falls inside
this rectangle. The point (x, y) is inside the rectangle, but the
point (x + width, y + height) is not.
Parameters
float
xfloat
y
Return
bool
bool Contains(const PointF& point) const
Return true
if point
is contained by the rectangle.
Parameters
const PointF&
point
Return
bool
bool Contains(const RectF& rect) const
Return true
if rect
is contained by the rectangle.
Parameters
const RectF&
rect
Return
bool
bool Intersects(const RectF& rect) const
Return true
if this rectangle intersects the specified rect
. An empty
rectangle doesn't intersect any rectangle.
Parameters
const RectF&
rect
Return
bool
void Intersect(const RectF& rect)
Compute the intersection of this rectangle with the given rect
.
Parameters
const RectF&
rect
void Union(const RectF& rect)
Compute the union of this rectangle with the given rect
. The union
is the smallest rectangle containing both rectangles.
Parameters
const RectF&
rect
void Subtract(const RectF& rect)
Compute the rectangle resulting from subtracting rect
from *this
,
i.e. the bounding rect of Region(*this) - Region(rect)
.
Parameters
const RectF&
rect
void AdjustToFit(const RectF& rect)
Fit as much of the receiving rectangle into the supplied rectangle as possible, becoming the result. For example, if the receiver had a x-location of 2 and a width of 4, and the supplied rectangle had an x-location of 0 with a width of 5, the returned rectangle would have an x-location of 1 with a width of 4.
Parameters
const RectF&
rect
PointF CenterPoint() const
Return the center of the rectangle.
Return
PointF
void ClampToCenteredSize(const SizeF& size)
Become a rectangle that has the same center point but with a size capped
at given size
.
Parameters
const SizeF&
size
void SplitVertically(RectF* left_half, RectF* right_half) const
Split the rectangle in two halves, left_half
and right_half
.
Parameters
bool SharesEdgeWith(const RectF& rect) const
Return true
if this rectangle shares an entire edge (i.e., same width
or same height) with the given rectangle, and the rectangles do not
overlap.
Parameters
const RectF&
rect
Return
bool
float ManhattanDistanceToPoint(const PointF& point) const
Return the manhattan distance from the rect to the point
. If the point
is inside the rect, return 0.
Parameters
const PointF&
point
Return
float
float ManhattanInternalDistance(const RectF& rect) const
Return the manhattan distance between the contents of this rect and the contents of the given rect. That is, if the intersection of the two rects is non-empty then the function returns 0. If the rects share a side, it return the smallest non-zero value appropriate for float.
Parameters
const RectF&
rect
Return
float
void Scale(float scale)
Scale the rectangle by scale
.
Parameters
float
scale
std::string ToString() const
Return string representation of the rectangle.
Return
std::string