10#ifndef GEOMETRY_TYPE_HPP
11#define GEOMETRY_TYPE_HPP
15# define Rect OTTD_Rect
16# define Point OTTD_Point
65 return (min + max - size + 1) / 2;
74 constexpr Coord2D() =
default;
75 constexpr Coord2D(
T x,
T y) :
x(
x),
y(
y) {}
81 constexpr auto operator<=>(
const Coord2D<T> &)
const =
default;
91 constexpr Coord3D() =
default;
98 constexpr auto operator<=>(
const Coord3D<T> &)
const =
default;
140 constexpr uint
Horizontal()
const {
return this->left + this->right; }
146 constexpr uint
Vertical()
const {
return this->top + this->bottom; }
162 inline int Width()
const {
return this->right - this->left + 1; }
168 inline int Height()
const {
return this->bottom - this->top + 1; }
177 return {this->left + s, this->top + s, this->right - s, this->bottom - s};
188 return {this->left + h, this->top + v, this->right - h, this->bottom - v};
199 [[nodiscard]]
inline Rect Shrink(
int left,
int top,
int right,
int bottom)
const
201 return {this->left + left, this->top + top, this->right - right, this->bottom - bottom};
211 return {this->left + other.left, this->top + other.top, this->right - other.right, this->bottom - other.bottom};
222 return {this->left + horz.left, this->top + vert.top, this->right - horz.right, this->bottom - vert.bottom};
242 return {this->left - other.left, this->top - other.top, this->right + other.right, this->bottom + other.bottom};
253 return {this->left + x, this->top + y, this->right + x, this->bottom + y};
265 ? this->
WithX(this->right - width + 1, this->right)
266 : this->WithX(this->left, this->left + width - 1);
278 ? this->
WithX(this->left, this->right - indent)
279 : this->WithX(this->left + indent, this->right);
291 ? this->
WithY(this->bottom - height + 1, this->bottom)
292 : this->WithY(this->top, this->top + height - 1);
303 return (uint)(pt.
x - this->left) <= (uint)(this->right - this->left) && (uint)(pt.
y - this->top) <= (uint)(this->bottom - this->top);
313 int new_left =
CentreBounds(this->left, this->right, width);
314 return {new_left, this->top, new_left + width - 1, this->bottom};
324 int new_top =
CentreBounds(this->top, this->bottom, height);
325 return {this->left, new_top, this->right, new_top + height - 1};
334 [[nodiscard]]
inline Rect WithX(
int new_left,
int new_right)
const {
return {new_left, this->top, new_right, this->bottom}; }
342 [[nodiscard]]
inline Rect WithY(
int new_top,
int new_bottom)
const {
return {this->left, new_top, this->right, new_bottom}; }
349 [[nodiscard]]
inline Rect WithX(
const Rect &other)
const {
return this->
WithX(other.left, other.right); }
356 [[nodiscard]]
inline Rect WithY(
const Rect &other)
const {
return this->
WithY(other.top, other.bottom); }
#define T
Climate temperate.
AlignmentH
Horizontal alignments.
@ ForceRight
Force align to the right.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Start
Align to the start, LTR/RTL aware.
@ ForceLeft
Force align to the left.
Coord2D< int > Point
Coordinates of a point in 2D.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
AlignmentV
Vertical alignments.
@ Bottom
Align to the bottom.
@ Middle
Align to the middle.
#define Point
Macro that prevents name conflicts between included headers.
AlignmentH ResolveRTL() const
Resolve horizontal alignment for the current text direction.
constexpr Alignment(AlignmentH h, AlignmentV v)
Construct an alignment with the specified horizontal and vertical alignment.
AlignmentV v
Vertical alignment.
AlignmentH h
Horizontal alignment.
constexpr Alignment(AlignmentH h)
Construct an alignment with the specific horizontal alignment.
A coordinate with two dimensions.
constexpr auto operator<=>(const Coord2D< T > &) const =default
Compare with another instance of this class.
constexpr auto operator<=>(const Coord3D< T > &) const =default
Compare with another instance of this class.
constexpr Dimension(value_type w, value_type h)
Create a dimension.
value_type height
The height of the rectangle.
uint32_t value_type
The type of the values; hack to make this look enough like a std::array for saving/loading resolution...
constexpr Dimension()=default
Create a 0x0 dimension.
value_type width
The width of the rectangle.
constexpr auto operator<=>(const Dimension &) const noexcept=default
Compare with another instance of this class.
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
Padding dimensions to apply to each side of a Rect.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Expand(const RectPadding &other) const
Copy and expand Rect by a RectPadding.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Shrink(const RectPadding &other) const
Copy and shrink Rect by a RectPadding.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
Rect CentreToWidth(int width) const
Centre a horizontal dimension within this Rect.
int Height() const
Get height of Rect.
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordinates.
Rect WithX(int new_left, int new_right) const
Create a new Rect, replacing the left and right coordinates.
Rect WithX(const Rect &other) const
Create a new Rect, replacing the left and right coordinates.
Rect Shrink(int h, int v) const
Copy and shrink Rect by h horizontal and v vertical pixels.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Rect Shrink(int left, int top, int right, int bottom) const
Copy and shrink Rect by pixels.
Rect WithY(const Rect &other) const
Create a new Rect, replacing the top and bottom coordinates.
Rect Shrink(const RectPadding &horz, const RectPadding &vert) const
Copy and shrink Rect by a different horizontal and vertical RectPadding.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
Rect Expand(int s) const
Copy and expand Rect by s pixels.