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
floatwidthfloatheight
RectF(float x, float y, float width, float height)
Create a rectangle defined with x, y, width, height.
Parameters
floatxfloatyfloatwidthfloatheight
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
floatvoid set_x(float x)
Set X coordinate.
Parameters
floatx
float y() const
Return Y coordinate.
Return
floatvoid set_y(float y)
Set Y coordinate.
Parameters
floaty
float width() const
Return rectangle width.
Return
floatvoid set_width(float width)
Set rectangle width.
Parameters
floatwidth
float height() const
Return rectangle height.
Return
floatvoid set_height(float height)
Set rectangle height.
Parameters
floatheight
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
floatfloat bottom() const
Return the y coordinate of lower-right corner of the rectangle.
Return
floatVector2dF OffsetFromOrigin() const
Return the vector version of upper-left corner.
Return
Vector2dFvoid Inset(float horizontal, float vertical)
Shrink the rectangle by a horizontal and vertical distance on all
sides.
Parameters
floathorizontalfloatvertical
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
floatleftfloattopfloatrightfloatbottom
void Offset(float horizontal, float vertical);
Move the rectangle by a horizontal and vertical distance.
Parameters
floathorizontalfloatvertical
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
boolbool 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
floatxfloaty
Return
boolbool Contains(const PointF& point) const
Return true if point is contained by the rectangle.
Parameters
const PointF&point
Return
boolbool Contains(const RectF& rect) const
Return true if rect is contained by the rectangle.
Parameters
const RectF&rect
Return
boolbool 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
boolvoid 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
PointFvoid 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
boolfloat 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
floatfloat 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
floatvoid Scale(float scale)
Scale the rectangle by scale.
Parameters
floatscale
std::string ToString() const
Return string representation of the rectangle.
Return
std::string