Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::Rect Struct Reference

Axis-aligned rectangle in continuous (float) coordinates. More...

#include <geometry.hpp>

Public Member Functions

constexpr float right () const
constexpr float bottom () const
Point origin () const
Size size () const
Point center () const
constexpr float center_x () const
 True center in continuous coordinates — exact halves, no truncation.
constexpr float center_y () const
bool contains (Point p) const
constexpr bool contains (float px, float py) const
constexpr bool encloses (const Rect &r) const
 Whole-rect containment: does this rect fully enclose r?
constexpr bool is_empty () const
Rect inset (float amount) const
Rect inset (float h, float v) const
Rect reduced (float d) const
 Shrink by d on every side (the common "padding" idiom).
Rect reduced (float dx, float dy) const
Rect expanded (float d) const
 Grow by d on every side.
Rect expanded (float dx, float dy) const
constexpr Rect translated (float dx, float dy) const
constexpr Rect with_x (float v) const
constexpr Rect with_y (float v) const
constexpr Rect with_width (float v) const
constexpr Rect with_height (float v) const
constexpr Rect with_size (float w, float h) const
constexpr Rect with_position (float nx, float ny) const
constexpr Rect with_size_keeping_center (float w, float h) const
 Resize about the center — the center stays put and the edges move.
Rect remove_from_top (float amount)
Rect remove_from_bottom (float amount)
Rect remove_from_left (float amount)
Rect remove_from_right (float amount)
constexpr bool intersects (const Rect &o) const
Rect intersection (const Rect &o) const
 The overlap, or an empty rect when they do not overlap.
Rect union_with (const Rect &o) const
 Smallest rect enclosing both.
IntRect to_nearest_int () const
 Round each edge to the nearest integer.
IntRect to_enclosing_int () const
 Smallest integer rect that fully CONTAINS this one.
bool operator== (const Rect &r) const
bool operator!= (const Rect &r) const

Public Attributes

float x = 0
float y = 0
float width = 0
float height = 0

Detailed Description

Axis-aligned rectangle in continuous (float) coordinates.

── WHY THERE IS ALSO AN IntRect ────────────────────────────────────── A float rect's center is x + width / 2.0f. An INTEGER rect's center is x + width / 2 — integer division, which TRUNCATES. For an even extent the two agree; for an odd one they differ by half a pixel. That half pixel is not academic: it is the difference between a 7px row's content landing on the pixel grid and landing between two pixels, where it renders as a blurry double-width line. Code that computes an integer layout with float maths and rounds at the end does NOT reproduce integer-rect behavior, because the truncation has to happen at each step, not once at the end.

So the two types deliberately do NOT share an implementation. Pick the one that matches the coordinate space you are actually in, and convert explicitly with to_int() / to_float().

Member Function Documentation

◆ bottom()

float pulp::view::Rect::bottom ( ) const
inlineconstexpr

◆ center()

Point pulp::view::Rect::center ( ) const
inline

◆ center_x()

float pulp::view::Rect::center_x ( ) const
inlineconstexpr

True center in continuous coordinates — exact halves, no truncation.

◆ center_y()

float pulp::view::Rect::center_y ( ) const
inlineconstexpr

◆ contains() [1/2]

bool pulp::view::Rect::contains ( float px,
float py ) const
inlineconstexpr

◆ contains() [2/2]

bool pulp::view::Rect::contains ( Point p) const
inline

◆ encloses()

bool pulp::view::Rect::encloses ( const Rect & r) const
inlineconstexpr

Whole-rect containment: does this rect fully enclose r?

NOT an overload of contains, on purpose. Rect has default member initializers, so a braced {50, 30} is a valid two-field Rect as well as a valid Point — which makes the natural, idiomatic r.contains({50, 30}) ambiguous at EVERY call site the moment a contains(const Rect&) overload exists. A distinct name is the fix; encloses also says what it does more plainly than a third contains.

◆ expanded() [1/2]

Rect pulp::view::Rect::expanded ( float d) const
inline

Grow by d on every side.

◆ expanded() [2/2]

Rect pulp::view::Rect::expanded ( float dx,
float dy ) const
inline

◆ inset() [1/2]

Rect pulp::view::Rect::inset ( float amount) const
inline

◆ inset() [2/2]

Rect pulp::view::Rect::inset ( float h,
float v ) const
inline

◆ intersection()

Rect pulp::view::Rect::intersection ( const Rect & o) const
inline

The overlap, or an empty rect when they do not overlap.

◆ intersects()

bool pulp::view::Rect::intersects ( const Rect & o) const
inlineconstexpr

◆ is_empty()

bool pulp::view::Rect::is_empty ( ) const
inlineconstexpr

◆ operator!=()

bool pulp::view::Rect::operator!= ( const Rect & r) const
inline

◆ operator==()

bool pulp::view::Rect::operator== ( const Rect & r) const
inline

◆ origin()

Point pulp::view::Rect::origin ( ) const
inline

◆ reduced() [1/2]

Rect pulp::view::Rect::reduced ( float d) const
inline

Shrink by d on every side (the common "padding" idiom).

◆ reduced() [2/2]

Rect pulp::view::Rect::reduced ( float dx,
float dy ) const
inline

◆ remove_from_bottom()

Rect pulp::view::Rect::remove_from_bottom ( float amount)
inline

◆ remove_from_left()

Rect pulp::view::Rect::remove_from_left ( float amount)
inline

◆ remove_from_right()

Rect pulp::view::Rect::remove_from_right ( float amount)
inline

◆ remove_from_top()

Rect pulp::view::Rect::remove_from_top ( float amount)
inline

◆ right()

float pulp::view::Rect::right ( ) const
inlineconstexpr

◆ size()

Size pulp::view::Rect::size ( ) const
inline

◆ to_enclosing_int()

IntRect pulp::view::Rect::to_enclosing_int ( ) const
inline

Smallest integer rect that fully CONTAINS this one.

◆ to_nearest_int()

IntRect pulp::view::Rect::to_nearest_int ( ) const
inline

Round each edge to the nearest integer.

Note this rounds the EDGES, so the resulting width can differ from round(width) by one — which is the correct behavior for a rect being snapped to the pixel grid.

◆ translated()

Rect pulp::view::Rect::translated ( float dx,
float dy ) const
inlineconstexpr

◆ union_with()

Rect pulp::view::Rect::union_with ( const Rect & o) const
inline

Smallest rect enclosing both.

An empty operand contributes nothing — without that rule, a default-constructed accumulator at (0,0) would drag every union back to the origin.

◆ with_height()

Rect pulp::view::Rect::with_height ( float v) const
inlineconstexpr

◆ with_position()

Rect pulp::view::Rect::with_position ( float nx,
float ny ) const
inlineconstexpr

◆ with_size()

Rect pulp::view::Rect::with_size ( float w,
float h ) const
inlineconstexpr

◆ with_size_keeping_center()

Rect pulp::view::Rect::with_size_keeping_center ( float w,
float h ) const
inlineconstexpr

Resize about the center — the center stays put and the edges move.

◆ with_width()

Rect pulp::view::Rect::with_width ( float v) const
inlineconstexpr

◆ with_x()

Rect pulp::view::Rect::with_x ( float v) const
inlineconstexpr

◆ with_y()

Rect pulp::view::Rect::with_y ( float v) const
inlineconstexpr

Member Data Documentation

◆ height

float pulp::view::Rect::height = 0

◆ width

float pulp::view::Rect::width = 0

◆ x

float pulp::view::Rect::x = 0

◆ y

float pulp::view::Rect::y = 0

The documentation for this struct was generated from the following file:
  • /home/runner/work/pulp/pulp/core/view/include/pulp/view/geometry.hpp