sources/geometry.h

changeset 144
e8d58327cd7f
parent 109
e4966d7e615d
child 190
90bf9049e5eb
equal deleted inserted replaced
143:b9993733952a 144:e8d58327cd7f
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #pragma once 31 #pragma once
32 #include "basics.h" 32 #include "basics.h"
33
33 BEGIN_ZFC_NAMESPACE 34 BEGIN_ZFC_NAMESPACE
35
34 36
35 struct Position 37 struct Position
36 { 38 {
37 int x; 39 int x;
38 int y; 40 int y;
39 41
40 Position (int x, int y) : 42 Position(int x, int y) :
41 x (x), 43 x(x),
42 y (y) {} 44 y(y) {}
43 45
44 Position() : 46 Position() :
45 x (0), 47 x(0),
46 y (0) {} 48 y(0) {}
47 49
48 bool operator< (const Position& other) const 50 bool operator<(const Position& other) const
49 { 51 {
50 if (y != other.y) 52 if (y != other.y)
51 return y < other.y; 53 return y < other.y;
52 54 else
53 return x < other.x; 55 return x < other.x;
54 } 56 }
55 57
56 bool operator> (const Position& other) const 58 bool operator>(const Position& other) const
57 { 59 {
58 if (y != other.y) 60 if (y != other.y)
59 return y > other.y; 61 return y > other.y;
60 62 else
61 return x > other.x; 63 return x > other.x;
62 } 64 }
63 65
64 bool operator== (const Position& other) const 66 bool operator==(const Position& other) const
65 { 67 {
66 return y == other.y and x == other.x; 68 return y == other.y and x == other.x;
67 } 69 }
68 70
69 bool operator!= (const Position& other) const 71 bool operator!=(const Position& other) const
70 { 72 {
71 return not operator== (other); 73 return not operator==(other);
72 } 74 }
73 75
74 bool operator<= (const Position& other) const 76 bool operator<=(const Position& other) const
75 { 77 {
76 return not operator> (other); 78 return not operator>(other);
77 } 79 }
78 80
79 bool operator>= (const Position& other) const 81 bool operator>=(const Position& other) const
80 { 82 {
81 return not operator< (other); 83 return not operator<(other);
82 } 84 }
83 }; 85 };
84 86
85 // -------------------------------------------------------------------------------------------------
86 87
87 struct Size 88 struct Size
88 { 89 {
89 int width; 90 int width;
90 int height; 91 int height;
91 92
92 Size (int width, int height) : 93 Size(int width, int height) :
93 width (width), 94 width(width),
94 height (height) {} 95 height(height) {}
95 96
96 Size() : 97 Size() :
97 width (0), 98 width(0),
98 height (0) {} 99 height(0) {}
99 100
100 auto area() const -> int 101 int area() const
101 { 102 {
102 return width * height; 103 return width * height;
103 } 104 }
104 }; 105 };
105 106
106 // -------------------------------------------------------------------------------------------------
107 107
108 struct Rectangle : Position, Size 108 struct Rectangle : Position, Size
109 { 109 {
110 Rectangle (int x, int y, int width, int height) : 110 Rectangle(int x, int y, int width, int height) :
111 Position (x, y), 111 Position(x, y),
112 Size (width, height) {} 112 Size(width, height) {}
113 113
114 Rectangle() : 114 Rectangle() :
115 Position(), 115 Position(),
116 Size() {} 116 Size() {}
117 }; 117 };
118 118
119
119 END_ZFC_NAMESPACE 120 END_ZFC_NAMESPACE

mercurial