Ember
Loading...
Searching...
No Matches
Geometry.h
Go to the documentation of this file.
1#pragma once
2
3namespace EmberCore {
4
8struct Point {
9 int x = 0;
10 int y = 0;
11
12 Point() = default;
13 Point(int x, int y) : x(x), y(y) {}
14
15 bool operator==(const Point &other) const { return x == other.x && y == other.y; }
16
17 bool operator!=(const Point &other) const { return !(*this == other); }
18};
19
23struct Size {
24 int width = 0;
25 int height = 0;
26
27 Size() = default;
29
30 bool operator==(const Size &other) const { return width == other.width && height == other.height; }
31
32 bool operator!=(const Size &other) const { return !(*this == other); }
33
34 bool IsEmpty() const { return width <= 0 || height <= 0; }
35};
36
40struct Rect {
41 int x = 0;
42 int y = 0;
43 int width = 0;
44 int height = 0;
45
46 Rect() = default;
47 Rect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {}
48 Rect(const Point &position, const Size &size)
49 : x(position.x), y(position.y), width(size.width), height(size.height) {}
50
51 bool operator==(const Rect &other) const {
52 return x == other.x && y == other.y && width == other.width && height == other.height;
53 }
54
55 bool operator!=(const Rect &other) const { return !(*this == other); }
56
57 Point GetPosition() const { return Point(x, y); }
58 Size GetSize() const { return Size(width, height); }
59
60 void SetPosition(const Point &position) {
61 x = position.x;
62 y = position.y;
63 }
64
65 void SetSize(const Size &size) {
66 width = size.width;
67 height = size.height;
68 }
69
70 bool IsEmpty() const { return width <= 0 || height <= 0; }
71
72 bool Contains(const Point &point) const {
73 return point.x >= x && point.x < x + width && point.y >= y && point.y < y + height;
74 }
75
76 bool Contains(const Rect &rect) const {
77 return rect.x >= x && rect.y >= y && rect.x + rect.width <= x + width && rect.y + rect.height <= y + height;
78 }
79};
80
81} // namespace EmberCore
Main types header for EmberCore.
2D point with integer coordinates
Definition Geometry.h:8
bool operator==(const Point &other) const
Definition Geometry.h:15
bool operator!=(const Point &other) const
Definition Geometry.h:17
Point(int x, int y)
Definition Geometry.h:13
Rect(const Point &position, const Size &size)
Definition Geometry.h:48
bool Contains(const Point &point) const
Definition Geometry.h:72
bool operator!=(const Rect &other) const
Definition Geometry.h:55
Rect()=default
Rect(int x, int y, int width, int height)
Definition Geometry.h:47
Size GetSize() const
Definition Geometry.h:58
bool operator==(const Rect &other) const
Definition Geometry.h:51
void SetSize(const Size &size)
Definition Geometry.h:65
void SetPosition(const Point &position)
Definition Geometry.h:60
Point GetPosition() const
Definition Geometry.h:57
bool Contains(const Rect &rect) const
Definition Geometry.h:76
bool IsEmpty() const
Definition Geometry.h:70
2D size with integer dimensions
Definition Geometry.h:23
bool operator==(const Size &other) const
Definition Geometry.h:30
bool IsEmpty() const
Definition Geometry.h:34
Size()=default
bool operator!=(const Size &other) const
Definition Geometry.h:32
Size(int width, int height)
Definition Geometry.h:28