10#ifndef GEOMETRY_TYPE_HPP
11#define GEOMETRY_TYPE_HPP
15# define Rect OTTD_Rect
16# define Point OTTD_Point
28 return (min + max - size + 1) / 2;
36 constexpr Point() : x(0), y(0) {}
37 constexpr Point(
int x,
int y) : x(x), y(y) {}
45 constexpr Dimension() : width(0), height(0) {}
46 constexpr Dimension(uint w, uint h) : width(w), height(h) {}
48 bool operator< (
const Dimension &other)
const
50 int x = (*this).width - other.width;
51 if (x != 0)
return x < 0;
52 return (*this).height < other.height;
55 bool operator== (
const Dimension &other)
const
57 return (*this).width == other.width && (*this).height == other.height;
74 constexpr uint
Horizontal()
const {
return this->left + this->right; }
80 constexpr uint
Vertical()
const {
return this->top + this->bottom; }
96 inline int Width()
const {
return this->right - this->left + 1; }
102 inline int Height()
const {
return this->bottom - this->top + 1; }
111 return {this->left + s, this->top + s, this->right - s, this->bottom - s};
122 return {this->left + h, this->top + v, this->right - h, this->bottom - v};
133 [[nodiscard]]
inline Rect Shrink(
int left,
int top,
int right,
int bottom)
const
135 return {this->left + left, this->top + top, this->right - right, this->bottom - bottom};
133 [[nodiscard]]
inline Rect Shrink(
int left,
int top,
int right,
int bottom)
const {
…}
145 return {this->left + other.left, this->top + other.top, this->right - other.right, this->bottom - other.bottom};
156 return {this->left + horz.left, this->top + vert.top, this->right - horz.right, this->bottom - vert.bottom};
176 return {this->left - other.left, this->top - other.top, this->right + other.right, this->bottom + other.bottom};
187 return {this->left + x, this->top + y, this->right + x, this->bottom + y};
199 ?
Rect {this->right - width + 1, this->top, this->right, this->bottom}
200 :
Rect {this->left, this->top, this->left + width - 1, this->bottom};
212 ?
Rect {this->left, this->top, this->right - indent, this->bottom}
213 :
Rect {this->left + indent, this->top, this->right, this->bottom};
225 ?
Rect {this->left, this->bottom - height + 1, this->right, this->bottom}
226 :
Rect {this->left, this->top, this->right, this->top + height - 1};
237 return (uint)(pt.x - this->left) <= (uint)(this->right - this->left) && (uint)(pt.y - this->top) <= (uint)(this->bottom - this->top);
248 int new_left =
CentreBounds(this->left, this->right, width);
249 int new_right =
CentreBounds(this->top, this->bottom, height);
250 return {new_left, new_right, new_left + width, new_right + height};
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimensions (a width and height) of a rectangle in 2D.
Specification of a rectangle with an absolute top-left coordinate and a (relative) width/height.
Coordinates of a point in 2D.
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.
Rect CentreTo(int width, int height) const
Centre a dimension within this Rect.
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.
int Height() const
Get height of Rect.
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 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.