Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_extend_2d.hpp
1#pragma once
2
3#include <ostream>
4#include <string>
5
6#include "structure/math/spk_vector2.hpp"
7
8namespace spk
9{
23 struct Extend2D
24 {
28 using Anchor = spk::Vector2Int;
32 using Size = spk::Vector2UInt;
33
34 union {
35 Anchor anchor;
36 struct
37 {
40 };
41 };
42
43 union {
44 Size size;
45 struct
46 {
47 Size::value_type width;
48 Size::value_type height;
49 };
50 };
51
55 Extend2D();
61 Extend2D(const Vector2Int &p_anchor, const Vector2UInt &p_size);
68 Extend2D(const Vector2Int &p_anchor, size_t p_width, size_t p_height);
75 Extend2D(int p_x, int p_y, const Vector2UInt &p_size);
83 Extend2D(int p_x, int p_y, size_t p_width, size_t p_height);
84
89 Extend2D atOrigin() const;
90
96 bool contains(const Vector2Int &p_point) const;
102 Extend2D shrink(const Vector2Int &p_offset) const;
108 Extend2D intersect(const Extend2D &p_other) const;
109
115 Extend2D operator+(const Extend2D &p_other) const;
121 Extend2D operator-(const Extend2D &p_other) const;
122
128 Extend2D &operator+=(const Extend2D &p_other);
134 Extend2D &operator-=(const Extend2D &p_other);
135
140 std::string toString() const;
145 std::wstring toWstring() const;
146
153 friend std::ostream &operator<<(std::ostream &p_stream, const Extend2D &p_extend);
160 friend std::wostream &operator<<(std::wostream &p_stream, const Extend2D &p_extend);
161
167 bool operator==(const Extend2D &p_other) const;
173 bool operator!=(const Extend2D &p_other) const;
174 };
175}
Extend2D & operator+=(const Extend2D &p_other)
In-place translation by another rectangle's anchor.
Definition spk_extend_2d.cpp:93
Extend2D & operator-=(const Extend2D &p_other)
In-place negative translation by another rectangle's anchor.
Definition spk_extend_2d.cpp:100
Extend2D()
Builds a zero-sized rectangle at the origin.
Definition spk_extend_2d.cpp:8
Extend2D intersect(const Extend2D &p_other) const
Computes the intersection of two rectangles.
Definition spk_extend_2d.cpp:67
Extend2D operator+(const Extend2D &p_other) const
Translates the rectangle by another rectangle's anchor.
Definition spk_extend_2d.cpp:83
Extend2D operator-(const Extend2D &p_other) const
Translates the rectangle negatively by another rectangle's anchor.
Definition spk_extend_2d.cpp:88
bool contains(const Vector2Int &p_point) const
Tests whether a point lies within the rectangle bounds.
Definition spk_extend_2d.cpp:43
Extend2D shrink(const Vector2Int &p_offset) const
Returns a rectangle shrunk by the provided offset on each side.
Definition spk_extend_2d.cpp:49
spk::Vector2Int Anchor
Position of the rectangle, expressed as its top-left corner.
Definition spk_extend_2d.hpp:28
Extend2D atOrigin() const
Returns a copy translated to the origin.
Definition spk_extend_2d.cpp:38
friend std::ostream & operator<<(std::ostream &p_stream, const Extend2D &p_extend)
Streams a rectangle to an output stream.
Definition spk_extend_2d.cpp:121
bool operator!=(const Extend2D &p_other) const
Inequality comparison between rectangles.
Definition spk_extend_2d.cpp:138
std::wstring toWstring() const
Converts the rectangle to a wide string.
Definition spk_extend_2d.cpp:114
bool operator==(const Extend2D &p_other) const
Equality comparison between rectangles.
Definition spk_extend_2d.cpp:133
std::string toString() const
Converts the rectangle to a readable string.
Definition spk_extend_2d.cpp:107
spk::Vector2UInt Size
Width and height of the rectangle.
Definition spk_extend_2d.hpp:32
int32_t value_type
Definition spk_vector2.hpp:39