9#include "tiny_skia/Math.h"
21 constexpr IntSize(LengthU32 width, LengthU32 height) : width_(width), height_(height) {}
24 static std::optional<IntSize>
fromWH(LengthU32 width, LengthU32 height) {
25 if (width == 0u || height == 0u) {
31 constexpr LengthU32 width()
const {
return width_; }
32 constexpr LengthU32 height()
const {
return height_; }
33 [[nodiscard]] ScreenIntRect toScreenIntRect(std::uint32_t x, std::uint32_t y)
const;
34 [[nodiscard]] std::optional<IntRect> toIntRect(std::int32_t x, std::int32_t y)
const;
35 [[nodiscard]] Rect toRect()
const;
37 constexpr bool operator==(
const IntSize&)
const =
default;
41 LengthU32 height_ = 0;
50 static std::optional<ScreenIntRect>
fromXYWH(std::uint32_t x, std::uint32_t y,
51 std::uint32_t width, std::uint32_t height);
53 static constexpr ScreenIntRect fromXYWHSafe(std::uint32_t x, std::uint32_t y, LengthU32 width,
58 constexpr std::uint32_t x()
const {
return x_; }
59 constexpr std::uint32_t y()
const {
return y_; }
60 constexpr LengthU32 width()
const {
return width_; }
61 constexpr LengthU32 height()
const {
return height_; }
62 constexpr LengthU32 widthSafe()
const {
return width_; }
64 constexpr std::uint32_t left()
const {
return x_; }
65 constexpr std::uint32_t top()
const {
return y_; }
67 std::uint32_t right()
const;
68 std::uint32_t bottom()
const;
70 [[nodiscard]]
bool contains(
const ScreenIntRect& other)
const;
71 [[nodiscard]] IntRect toIntRect()
const;
72 [[nodiscard]] Rect toRect()
const;
75 constexpr ScreenIntRect(std::uint32_t x, std::uint32_t y, LengthU32 width, LengthU32 height)
76 : x_{x}, y_{y}, width_{width}, height_{height} {}
88 static std::optional<IntRect>
fromXYWH(std::int32_t x, std::int32_t y, std::uint32_t width,
89 std::uint32_t height);
91 constexpr std::int32_t x()
const {
return x_; }
92 constexpr std::int32_t y()
const {
return y_; }
93 constexpr LengthU32 width()
const {
return width_; }
94 constexpr LengthU32 height()
const {
return height_; }
96 [[nodiscard]]
constexpr std::int32_t left()
const {
return x_; }
97 [[nodiscard]]
constexpr std::int32_t top()
const {
return y_; }
99 [[nodiscard]] std::int32_t right()
const;
100 [[nodiscard]] std::int32_t bottom()
const;
105 [[nodiscard]] std::optional<ScreenIntRect> toScreenIntRect()
const;
108 constexpr IntRect(std::int32_t x, std::int32_t y, LengthU32 width, LengthU32 height)
109 : x_{x}, y_{y}, width_{width}, height_{height} {}
113 LengthU32 width_ = 0;
114 LengthU32 height_ = 0;
122 static std::optional<Rect>
fromLTRB(
float left,
float top,
float right,
float bottom);
125 static std::optional<Rect>
fromXYWH(
float x,
float y,
float w,
float h) {
126 return fromLTRB(x, y, x + w, y + h);
129 constexpr float left()
const {
return left_; }
130 constexpr float top()
const {
return top_; }
131 constexpr float right()
const {
return right_; }
132 constexpr float bottom()
const {
return bottom_; }
134 constexpr float width()
const {
return right_ - left_; }
135 constexpr float height()
const {
return bottom_ - top_; }
137 constexpr bool operator==(
const Rect&)
const =
default;
140 [[nodiscard]] std::optional<IntRect>
roundOut()
const;
142 [[nodiscard]] std::optional<IntRect>
round()
const;
145 constexpr Rect(
float left,
float top,
float right,
float bottom)
146 : left_(left), top_(top), right_(right), bottom_(bottom) {}
151 float bottom_ = 0.0f;
155std::optional<ScreenIntRect> intRectToScreen(
const IntRect& rect);
Signed integer rectangle (x, y, width, height).
Definition Geom.h:85
static std::optional< IntRect > fromXYWH(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height)
Creates from components. Returns nullopt for zero dimensions or overflow.
std::optional< IntRect > intersect(const IntRect &other) const
Returns the intersection with another rect, or nullopt if disjoint.
Non-zero integer dimensions (width x height).
Definition Geom.h:18
static std::optional< IntSize > fromWH(LengthU32 width, LengthU32 height)
Creates from width/height. Returns nullopt if either is zero.
Definition Geom.h:24
Floating-point rectangle (left, top, right, bottom). All components must be finite,...
Definition Geom.h:119
static std::optional< Rect > fromXYWH(float x, float y, float w, float h)
Creates from origin and size. Returns nullopt if invalid.
Definition Geom.h:125
std::optional< IntRect > roundOut() const
Converts to IntRect by rounding outward (floor left/top, ceil right/bottom).
std::optional< IntRect > round() const
Converts to IntRect by rounding to nearest integer.
static std::optional< Rect > fromLTRB(float left, float top, float right, float bottom)
Creates from edges. Returns nullopt for non-finite, empty, or inverted rects.
Unsigned integer rectangle (x, y, width, height). Used for screen coordinates.
Definition Geom.h:45
static std::optional< ScreenIntRect > fromXYWH(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height)
Creates from components. Returns nullopt for zero width/height or overflow.