|
1 /* |
|
2 Copyright 2014 Teemu Piippo |
|
3 All rights reserved. |
|
4 |
|
5 Redistribution and use in source and binary forms, with or without |
|
6 modification, are permitted provided that the following conditions |
|
7 are met: |
|
8 |
|
9 1. Redistributions of source code must retain the above copyright |
|
10 notice, this list of conditions and the following disclaimer. |
|
11 2. Redistributions in binary form must reproduce the above copyright |
|
12 notice, this list of conditions and the following disclaimer in the |
|
13 documentation and/or other materials provided with the distribution. |
|
14 3. Neither the name of the copyright holder nor the names of its |
|
15 contributors may be used to endorse or promote products derived from |
|
16 this software without specific prior written permission. |
|
17 |
|
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
|
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #pragma once |
|
32 |
|
33 struct Position |
|
34 { |
|
35 int x; |
|
36 int y; |
|
37 |
|
38 Position (int x, int y) : |
|
39 x (x), |
|
40 y (y) {} |
|
41 |
|
42 Position() : |
|
43 x (0), |
|
44 y (0) {} |
|
45 |
|
46 inline METHOD operator< (const Position& other) const -> bool; |
|
47 inline METHOD operator> (const Position& other) const -> bool; |
|
48 inline METHOD operator== (const Position& other) const -> bool; |
|
49 inline METHOD operator<= (const Position& other) const -> bool; |
|
50 inline METHOD operator>= (const Position& other) const -> bool; |
|
51 inline METHOD operator!= (const Position& other) const -> bool; |
|
52 }; |
|
53 |
|
54 // ------------------------------------------------------------------------------------------------- |
|
55 |
|
56 struct Size |
|
57 { |
|
58 int width; |
|
59 int height; |
|
60 |
|
61 Size (int width, int height) : |
|
62 width (width), |
|
63 height (height) {} |
|
64 |
|
65 Size() : |
|
66 width (0), |
|
67 height (0) {} |
|
68 |
|
69 auto area() const -> int |
|
70 { |
|
71 return width * height; |
|
72 } |
|
73 }; |
|
74 |
|
75 // ------------------------------------------------------------------------------------------------- |
|
76 |
|
77 struct Rectangle : Position, Size |
|
78 { |
|
79 Rectangle (int x, int y, int width, int height) : |
|
80 Position (x, y), |
|
81 Size (width, height) {} |
|
82 |
|
83 Rectangle() : |
|
84 Position(), |
|
85 Size() {} |
|
86 }; |
|
87 |
|
88 // ------------------------------------------------------------------------------------------------- |
|
89 |
|
90 inline METHOD |
|
91 Position::operator< (const Position& other) const -> bool |
|
92 { |
|
93 if (y != other.y) |
|
94 return y < other.y; |
|
95 |
|
96 return x < other.x; |
|
97 } |
|
98 |
|
99 // ------------------------------------------------------------------------------------------------- |
|
100 |
|
101 inline METHOD |
|
102 Position::operator> (const Position& other) const -> bool |
|
103 { |
|
104 if (y != other.y) |
|
105 return y > other.y; |
|
106 |
|
107 return x > other.x; |
|
108 } |
|
109 |
|
110 // ------------------------------------------------------------------------------------------------- |
|
111 |
|
112 inline METHOD |
|
113 Position::operator== (const Position& other) const -> bool |
|
114 { |
|
115 return y == other.y and x == other.x; |
|
116 } |
|
117 |
|
118 // ------------------------------------------------------------------------------------------------- |
|
119 |
|
120 inline METHOD |
|
121 Position::operator<= (const Position& other) const -> bool |
|
122 { |
|
123 return not operator> (other); |
|
124 } |
|
125 |
|
126 // ------------------------------------------------------------------------------------------------- |
|
127 |
|
128 inline METHOD |
|
129 Position::operator>= (const Position& other) const -> bool |
|
130 { |
|
131 return not operator< (other); |
|
132 } |
|
133 |
|
134 // ------------------------------------------------------------------------------------------------- |
|
135 |
|
136 inline METHOD |
|
137 Position::operator!= (const Position& other) const -> bool |
|
138 { |
|
139 return not operator== (other); |
|
140 } |