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