RectF

Rectangle type.

Header#include "nativeui/gfx/geometry/rect_f.h"
Namespacenamespace nu
Typeclass

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

RectF(float x, float y, float width, float height)

Create a rectangle defined with x, y, width, height.

Parameters

RectF(const SizeF& size)

Create a rectangle with size, positioned at (0, 0).

Parameters

RectF(const PointF& origin, const SizeF& size)

Create a rectangle with origin and size.

Parameters

Methods

float x() const

Return X coordinate.

Return

float

void set_x(float x)

Set X coordinate.

Parameters

float y() const

Return Y coordinate.

Return

float

void set_y(float y)

Set Y coordinate.

Parameters

float width() const

Return rectangle width.

Return

float

void set_width(float width)

Set rectangle width.

Parameters

float height() const

Return rectangle height.

Return

float

void set_height(float height)

Set rectangle height.

Parameters

const PointF& origin() const

Return origin.

Return

const PointF&

void set_origin(const PointF& origin)

Set origin.

Parameters

const SizeF& size() const

Return size.

Return

const SizeF&

void set_size(const SizeF& size)

Set size.

Parameters

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

void Inset(const InsetsF& insets)

Shrink the rectangle by the given insets.

Parameters

void Inset(float left, float top, float right, float bottom)

Shrink the rectangle by the specified amount on each side.

Parameters

void Offset(float horizontal, float vertical);

Move the rectangle by a horizontal and vertical distance.

Parameters

void Offset(const Vector2dF& distance)

Move the rectangle by the distance vector.

Parameters

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

Return

bool

bool Contains(const PointF& point) const

Return true if point is contained by the rectangle.

Parameters

Return

bool

bool Contains(const RectF& rect) const

Return true if rect is contained by the rectangle.

Parameters

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

Return

bool

void Intersect(const RectF& rect)

Compute the intersection of this rectangle with the given rect.

Parameters

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

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

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

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

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

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

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

Return

float

void Scale(float scale)

Scale the rectangle by scale.

Parameters

std::string ToString() const

Return string representation of the rectangle.

Return

std::string