28 #ifndef AGS_SHARED_UTIL_GEOMETRY_H 29 #define AGS_SHARED_UTIL_GEOMETRY_H 31 #include "ags/shared/util/math.h" 35 namespace AGSMath = AGS::Shared::Math;
48 kAlignTopLeft = 0x0001,
49 kAlignTopCenter = 0x0002,
50 kAlignTopRight = 0x0004,
51 kAlignMiddleLeft = 0x0008,
52 kAlignMiddleCenter = 0x0010,
53 kAlignMiddleRight = 0x0020,
54 kAlignBottomLeft = 0x0040,
55 kAlignBottomCenter = 0x0080,
56 kAlignBottomRight = 0x0100,
61 kMAlignLeft = kAlignTopLeft | kAlignMiddleLeft | kAlignBottomLeft,
62 kMAlignRight = kAlignTopRight | kAlignMiddleRight | kAlignBottomRight,
63 kMAlignTop = kAlignTopLeft | kAlignTopCenter | kAlignTopRight,
64 kMAlignBottom = kAlignBottomLeft | kAlignBottomCenter | kAlignBottomRight,
65 kMAlignHCenter = kAlignTopCenter | kAlignMiddleCenter | kAlignBottomCenter,
66 kMAlignVCenter = kAlignMiddleLeft | kAlignMiddleCenter | kAlignMiddleRight
73 kHAlignNone = kAlignNone,
74 kHAlignLeft = kAlignTopLeft,
75 kHAlignRight = kAlignTopRight,
76 kHAlignCenter = kAlignTopCenter
83 kPlaceStretchProportional,
101 inline bool operator ==(
const Point &p)
const {
102 return X == p.X && Y == p.Y;
105 inline bool operator !=(
const Point &p)
const {
106 return X != p.X || Y != p.Y;
109 inline Point operator +(
const Point &p)
const {
110 return Point(X + p.X, Y + p.Y);
113 inline bool Equals(
const int x,
const int y)
const {
114 return X == x && Y == y;
131 Line(
int x1,
int y1,
int x2,
int y2) {
140 inline Line HLine(
int x1,
int x2,
int y) {
141 return Line(x1, y, x2, y);
144 inline Line VLine(
int x,
int y1,
int y2) {
145 return Line(x, y1, x, y2);
157 Size(
int width,
int height) {
162 inline bool IsNull()
const {
163 return Width <= 0 || Height <= 0;
166 inline static Size Clamp(
const Size &sz,
const Size &floor,
const Size &ceil) {
167 return Size(AGSMath::Clamp(sz.Width, floor.Width, ceil.Width),
168 AGSMath::Clamp(sz.Height, floor.Height, ceil.Height));
172 inline bool ExceedsByAny(
const Size &size)
const {
173 return Width > size.Width || Height > size.Height;
176 inline bool operator==(
const Size &size)
const {
177 return Width == size.Width && Height == size.Height;
180 inline bool operator!=(
const Size &size)
const {
181 return Width != size.Width || Height != size.Height;
184 inline bool operator<(
const Size &other)
const {
185 return Width < other.Width || (Width == other.Width && Height < other.Height);
188 inline Size operator+(
const Size &size)
const {
189 return Size(Width + size.Width, Height + size.Height);
192 inline Size operator-(
const Size &size)
const {
193 return Size(Width - size.Width, Height - size.Height);
196 inline Size operator *(
int x)
const {
197 return Size(Width * x, Height * x);
200 inline Size operator /(
int x)
const {
201 return Size(Width / x, Height / x);
204 inline Size &operator *=(
int x) {
210 inline Size &operator /=(
int x) {
232 Rect(
int l,
int t,
int r,
int b) {
239 inline Point GetLT()
const {
240 return Point(Left, Top);
243 inline Point GetCenter()
const {
244 return Point(Left + GetWidth() / 2, Top + GetHeight() / 2);
247 inline int GetWidth()
const {
248 return Right - Left + 1;
251 inline int GetHeight()
const {
252 return Bottom - Top + 1;
255 inline Size GetSize()
const {
256 return Size(GetWidth(), GetHeight());
259 inline bool IsEmpty()
const {
260 return Right < Left || Bottom < Top;
263 inline bool IsInside(
int x,
int y)
const {
264 return x >= Left && y >= Top && (x <= Right) && (y <= Bottom);
267 inline bool IsInside(
const Point &pt)
const {
268 return IsInside(pt.X, pt.Y);
271 inline void MoveToX(
int x) {
276 inline void MoveToY(
int y) {
281 inline void MoveTo(
const Point &pt) {
286 inline void SetWidth(
int width) {
287 Right = Left + width - 1;
290 inline void SetHeight(
int height) {
291 Bottom = Top + height - 1;
294 inline static Rect MoveBy(
const Rect &r,
int x,
int y) {
295 return Rect(r.Left + x, r.Top + y, r.Right + x, r.Bottom + y);
298 inline bool operator ==(
const Rect &r)
const {
299 return Left == r.Left && Top == r.Top &&
300 Right == r.Right && Bottom == r.Bottom;
305 inline Rect RectWH(
int x,
int y,
int width,
int height) {
306 return Rect(x, y, x + width - 1, y + height - 1);
309 inline Rect RectWH(
const Size &sz) {
310 return Rect(0, 0, sz.Width - 1, sz.Height - 1);
331 Triangle(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3) {
352 Circle(
int x,
int y,
int radius) {
362 bool AreRectsIntersecting(
const Rect &r1,
const Rect &r2);
364 bool IsRectInsideRect(
const Rect &place,
const Rect &item);
366 float DistanceBetween(
const Rect &r1,
const Rect &r2);
368 int AlignInHRange(
int x1,
int x2,
int off_x,
int width, FrameAlignment align);
369 int AlignInVRange(
int y1,
int y2,
int off_y,
int height, FrameAlignment align);
370 Rect AlignInRect(
const Rect &frame,
const Rect &item, FrameAlignment align);
372 Size ProportionalStretch(
int dest_w,
int dest_h,
int item_w,
int item_h);
373 Size ProportionalStretch(
const Size &dest,
const Size &item);
378 Rect PlaceInRect(
const Rect &place,
const Rect &item,
const RectPlacement &placement);
Definition: geometry.h:87
Definition: geometry.h:314
Definition: geometry.h:118
Definition: geometry.h:219
Definition: geometry.h:148
Definition: geometry.h:341