Skip to content

Engine → Core → rect.h

rect

Syntax

struct rect

Variables

AccessNameTypeDefaultDescription
publicmaxvec2vec2(0.0f)
publicminvec2vec2(0.0f)

Functions

Public

area

[[nodiscard]] f32 area() const noexcept;

width * height; 0 for an invalid rectangle.

center

[[nodiscard]] vec2 center() const noexcept;

Midpoint of min and max.

closest_point

[[nodiscard]] vec2 closest_point(
    vec2 point) const noexcept;

The point inside or on the rectangle nearest to point (point itself when inside). An invalid rectangle has no surface and returns point unchanged.

contains

[[nodiscard]] bool contains(
    vec2 point) const noexcept;

True when the point lies inside or on the rectangle.

[[nodiscard]] bool contains(
    const rect &other) const noexcept;

True when other lies entirely inside or on this rectangle (false when either is invalid).

expand

void expand(
    vec2 point) noexcept;

Grows the rectangle to include a point.

void expand(
    const rect &other) noexcept;

Grows the rectangle to include another (an invalid other is ignored).

from_center_extents

[[nodiscard]] static rect from_center_extents(
    vec2 centerPoint,
    vec2 halfExtents) noexcept;

A rectangle from its centre and half-size on each axis (negative extents are made positive).

from_points

[[nodiscard]] static rect from_points(
    vec2 a,
    vec2 b) noexcept;

A rectangle from two arbitrary corners.

from_position_size

[[nodiscard]] static rect from_position_size(
    vec2 position,
    vec2 extent) noexcept;

The rectangle spanned by position and position + extent; a negative extent component extends to the other side of position (from_position_size((10, 10), (-4, 2)) is min (6, 10), max (10, 12)).

height

[[nodiscard]] f32 height() const noexcept;

max.y - min.y.

inflated

[[nodiscard]] rect inflated(
    f32 amount) const noexcept;

A copy grown by amount on every side (shrunk for negative amounts).

intersection

[[nodiscard]] rect intersection(
    const rect &other) const noexcept;

The overlap of both rectangles; invalid when they do not intersect.

intersects

[[nodiscard]] bool intersects(
    const rect &other) const noexcept;

True when the rectangles overlap or touch (false when either is invalid).

is_empty

[[nodiscard]] bool is_empty() const noexcept;

True when the rectangle has no area (invalid or zero width or height).

is_valid

[[nodiscard]] bool is_valid() const noexcept;

True when min <= max on both axes (an empty rectangle is valid).

size

[[nodiscard]] vec2 size() const noexcept;

max - min.

translated

[[nodiscard]] rect translated(
    vec2 offset) const noexcept;

A copy moved by offset.

width

[[nodiscard]] f32 width() const noexcept;

max.x - min.x.

Operator Overloads

Public

operator==

[[nodiscard]] bool operator==(
    const rect &other) const = default;