3
3
4
4
#include " util/fastMath.h"
5
5
6
- typedef int cord_t ;
7
- typedef float f_cord_t ;
6
+ typedef int coordinate_t ;
7
+ typedef float f_coordinate_t ;
8
8
9
9
struct Vector ;
10
10
struct FVector ;
@@ -17,9 +17,9 @@ struct Vector {
17
17
class Iterator ;
18
18
19
19
inline Vector () noexcept : dx(0 ), dy(0 ) { }
20
- inline Vector (cord_t dx, cord_t dy) noexcept : dx(dx), dy(dy) { }
20
+ inline Vector (coordinate_t dx, coordinate_t dy) noexcept : dx(dx), dy(dy) { }
21
21
// allows the easy creation of vectors that are all the same value
22
- inline Vector (cord_t d) noexcept : dx(d), dy(d) { }
22
+ inline Vector (coordinate_t d) noexcept : dx(d), dy(d) { }
23
23
inline FVector free () const noexcept ;
24
24
25
25
inline void extentToFit (Vector vector) noexcept {
@@ -34,9 +34,9 @@ struct Vector {
34
34
inline bool hasZeros () const noexcept { return !(dx && dy); }
35
35
inline bool widthInSize (Size size) const noexcept ;
36
36
37
- inline cord_t manhattenlength () const noexcept { return Abs (dx) + Abs (dy); }
38
- inline f_cord_t lengthSquared () const noexcept { return FastPower<2 >(dx) + FastPower<2 >(dy); }
39
- inline f_cord_t length () const noexcept { return sqrt (lengthSquared ()); }
37
+ inline coordinate_t manhattenlength () const noexcept { return Abs (dx) + Abs (dy); }
38
+ inline f_coordinate_t lengthSquared () const noexcept { return FastPower<2 >(dx) + FastPower<2 >(dy); }
39
+ inline f_coordinate_t length () const noexcept { return sqrt (lengthSquared ()); }
40
40
41
41
inline Vector operator +(Vector other) const noexcept { return Vector (dx + other.dx , dy + other.dy ); }
42
42
inline Vector& operator +=(Vector other) noexcept {
@@ -50,23 +50,23 @@ struct Vector {
50
50
dy -= other.dy ;
51
51
return *this ;
52
52
}
53
- inline cord_t operator *(Vector vector) const noexcept { return dx * vector.dx + dy * vector.dy ; }
54
- inline Vector operator *(cord_t scalar) const noexcept { return Vector (dx * scalar, dy * scalar); }
55
- inline Vector& operator *=(cord_t scalar) noexcept {
53
+ inline coordinate_t operator *(Vector vector) const noexcept { return dx * vector.dx + dy * vector.dy ; }
54
+ inline Vector operator *(coordinate_t scalar) const noexcept { return Vector (dx * scalar, dy * scalar); }
55
+ inline Vector& operator *=(coordinate_t scalar) noexcept {
56
56
dx *= scalar;
57
57
dy *= scalar;
58
58
return *this ;
59
59
}
60
- inline Vector operator /(cord_t scalar) const noexcept { return Vector (dx / scalar, dy / scalar); }
61
- inline Vector& operator /=(cord_t scalar) noexcept {
60
+ inline Vector operator /(coordinate_t scalar) const noexcept { return Vector (dx / scalar, dy / scalar); }
61
+ inline Vector& operator /=(coordinate_t scalar) noexcept {
62
62
dx /= scalar;
63
63
dy /= scalar;
64
64
return *this ;
65
65
}
66
66
67
67
inline Iterator iter () const noexcept ;
68
68
69
- cord_t dx, dy;
69
+ coordinate_t dx, dy;
70
70
};
71
71
72
72
class Vector ::Iterator {
@@ -126,8 +126,8 @@ Vector::Iterator Vector::iter() const noexcept { return Iterator(*this); }
126
126
template <>
127
127
struct std ::hash<Vector> {
128
128
inline std::size_t operator ()(Vector vec) const noexcept {
129
- std::size_t x = std::hash<cord_t >{}(vec.dx );
130
- std::size_t y = std::hash<cord_t >{}(vec.dy );
129
+ std::size_t x = std::hash<coordinate_t >{}(vec.dx );
130
+ std::size_t y = std::hash<coordinate_t >{}(vec.dy );
131
131
return (std::size_t )x ^ ((std::size_t )y << 32 );
132
132
}
133
133
};
@@ -141,19 +141,19 @@ struct std::formatter<Vector> : std::formatter<std::string> {
141
141
142
142
struct FVector {
143
143
inline FVector () noexcept : dx(0 .0f ), dy(0 .0f ) { }
144
- inline FVector (f_cord_t dx, f_cord_t dy) noexcept : dx(dx), dy(dy) { }
144
+ inline FVector (f_coordinate_t dx, f_coordinate_t dy) noexcept : dx(dx), dy(dy) { }
145
145
// allows the easy creation of fvectors that are all the same value
146
- inline FVector (f_cord_t d) noexcept : dx(d), dy(d) { }
146
+ inline FVector (f_coordinate_t d) noexcept : dx(d), dy(d) { }
147
147
inline Vector snap () const noexcept ;
148
148
149
149
inline std::string toString () const noexcept { return " <" + std::to_string (dx) + " , " + std::to_string (dy) + " >" ; }
150
150
151
151
inline bool operator ==(FVector other) const noexcept { return approx_equals (dx, other.dx ) && approx_equals (dy, other.dy ); }
152
152
inline bool operator !=(FVector other) const noexcept { return !operator ==(other); }
153
153
154
- inline f_cord_t manhattenlength () const noexcept { return fabs (dx) + fabs (dy); }
155
- inline f_cord_t lengthSquared () const noexcept { return FastPower<2 >(dx) + FastPower<2 >(dy); }
156
- inline f_cord_t length () const noexcept { return sqrt (FastPower<2 >(dx) + FastPower<2 >(dy)); }
154
+ inline f_coordinate_t manhattenlength () const noexcept { return fabs (dx) + fabs (dy); }
155
+ inline f_coordinate_t lengthSquared () const noexcept { return FastPower<2 >(dx) + FastPower<2 >(dy); }
156
+ inline f_coordinate_t length () const noexcept { return sqrt (FastPower<2 >(dx) + FastPower<2 >(dy)); }
157
157
158
158
inline FVector operator +(FVector other) const noexcept { return FVector (dx + other.dx , dy + other.dy ); }
159
159
inline FVector& operator +=(FVector other) noexcept {
@@ -167,23 +167,23 @@ struct FVector {
167
167
dy -= other.dy ;
168
168
return *this ;
169
169
}
170
- inline FVector operator *(f_cord_t scalar) const noexcept { return FVector (dx * scalar, dy * scalar); }
171
- inline FVector& operator *=(f_cord_t scalar) noexcept {
170
+ inline FVector operator *(f_coordinate_t scalar) const noexcept { return FVector (dx * scalar, dy * scalar); }
171
+ inline FVector& operator *=(f_coordinate_t scalar) noexcept {
172
172
dx *= scalar, dy *= scalar;
173
173
return *this ;
174
174
}
175
- inline f_cord_t operator *(FVector vector) const noexcept { return dx * vector.dx + dy * vector.dy ; }
176
- inline FVector operator /(f_cord_t scalar) noexcept { return FVector (dx / scalar, dy / scalar); }
177
- inline FVector& operator /=(f_cord_t scalar) noexcept {
175
+ inline f_coordinate_t operator *(FVector vector) const noexcept { return dx * vector.dx + dy * vector.dy ; }
176
+ inline FVector operator /(f_coordinate_t scalar) noexcept { return FVector (dx / scalar, dy / scalar); }
177
+ inline FVector& operator /=(f_coordinate_t scalar) noexcept {
178
178
dx /= scalar;
179
179
dy /= scalar;
180
180
return *this ;
181
181
}
182
182
183
- inline f_cord_t lengthAlongProjectToVec (FVector vector) const noexcept { return (*this * vector) / vector.length (); }
183
+ inline f_coordinate_t lengthAlongProjectToVec (FVector vector) const noexcept { return (*this * vector) / vector.length (); }
184
184
inline FVector projectToVec (FVector vector) const noexcept { return vector * (*this * vector) / vector.lengthSquared (); }
185
185
186
- f_cord_t dx, dy;
186
+ f_coordinate_t dx, dy;
187
187
};
188
188
189
189
template <>
@@ -197,9 +197,9 @@ struct Size {
197
197
class Iterator ;
198
198
199
199
inline Size () noexcept : w(0 ), h(0 ) { }
200
- inline Size (cord_t w, cord_t h) noexcept : w(w), h(h) { }
200
+ inline Size (coordinate_t w, coordinate_t h) noexcept : w(w), h(h) { }
201
201
// makes the size for hypercube with some edges length
202
- inline Size (cord_t sideLength) noexcept : w(sideLength), h(sideLength) { }
202
+ inline Size (coordinate_t sideLength) noexcept : w(sideLength), h(sideLength) { }
203
203
inline FSize free () const noexcept ;
204
204
205
205
inline void extentToFit (Vector vector) noexcept {
@@ -214,14 +214,14 @@ struct Size {
214
214
// w != 0 and h != 0
215
215
inline bool isValid () const noexcept { return w > 0 && h > 0 ; }
216
216
217
- inline cord_t area () const noexcept { return w * h; }
218
- inline cord_t perimeter () const noexcept { return w * 2 + h * 2 ; }
217
+ inline coordinate_t area () const noexcept { return w * h; }
218
+ inline coordinate_t perimeter () const noexcept { return w * 2 + h * 2 ; }
219
219
220
220
inline Iterator iter () const noexcept ;
221
221
222
222
inline Vector getLargestVectorInArea () { return Vector (w - 1 , h - 1 ); }
223
223
224
- cord_t w, h;
224
+ coordinate_t w, h;
225
225
};
226
226
227
227
template <>
@@ -296,7 +296,7 @@ struct FSize {
296
296
// class Iterator;
297
297
298
298
inline FSize () noexcept : w(0 ), h(0 ) { }
299
- inline FSize (f_cord_t w, f_cord_t h) noexcept : w(w), h(h) { }
299
+ inline FSize (f_coordinate_t w, f_coordinate_t h) noexcept : w(w), h(h) { }
300
300
inline Size snap () const noexcept ;
301
301
302
302
inline void extentToFit (FVector vector) noexcept {
@@ -311,12 +311,12 @@ struct FSize {
311
311
// w != 0 and h != 0
312
312
inline bool isValid () const noexcept { return !(w && h); }
313
313
314
- inline f_cord_t area () const noexcept { return w * h; }
315
- inline f_cord_t perimeter () const noexcept { return w * 2 + h * 2 ; }
314
+ inline f_coordinate_t area () const noexcept { return w * h; }
315
+ inline f_coordinate_t perimeter () const noexcept { return w * 2 + h * 2 ; }
316
316
317
317
// inline Iterator iter() const noexcept;
318
318
319
- f_cord_t w, h;
319
+ f_coordinate_t w, h;
320
320
};
321
321
322
322
template <>
@@ -330,7 +330,7 @@ struct Position {
330
330
class Iterator ;
331
331
332
332
inline Position () noexcept : x(0 ), y(0 ) { }
333
- inline Position (cord_t x, cord_t y) noexcept : x(x), y(y) { }
333
+ inline Position (coordinate_t x, coordinate_t y) noexcept : x(x), y(y) { }
334
334
inline FPosition free () const noexcept ;
335
335
336
336
inline std::string toString () const noexcept { return " (" + std::to_string (x) + " , " + std::to_string (y) + " )" ; }
@@ -339,12 +339,12 @@ struct Position {
339
339
inline bool operator !=(Position position) const noexcept { return !operator ==(position); }
340
340
inline bool withinArea (Position small, Position large) const noexcept { return small.x <= x && small.y <= y && large.x >= x && large.y >= y; }
341
341
342
- inline cord_t manhattenDistanceTo (Position position) const noexcept { return Abs (x - position.x ) + Abs (y - position.y ); }
343
- inline cord_t manhattenDistanceToOrigin () const noexcept { return Abs (x) + Abs (y); }
344
- inline cord_t distanceToSquared (Position position) const noexcept { return FastPower<2 >(x - position.x ) + FastPower<2 >(y - position.y ); }
345
- inline cord_t distanceToOriginSquared () const noexcept { return FastPower<2 >(x) + FastPower<2 >(y); }
346
- inline f_cord_t distanceTo (Position position) const noexcept { return sqrt (FastPower<2 >(x - position.x ) + FastPower<2 >(y - position.y )); }
347
- inline f_cord_t distanceToOrigin () const noexcept { return sqrt (FastPower<2 >(x) + FastPower<2 >(y)); }
342
+ inline coordinate_t manhattenDistanceTo (Position position) const noexcept { return Abs (x - position.x ) + Abs (y - position.y ); }
343
+ inline coordinate_t manhattenDistanceToOrigin () const noexcept { return Abs (x) + Abs (y); }
344
+ inline coordinate_t distanceToSquared (Position position) const noexcept { return FastPower<2 >(x - position.x ) + FastPower<2 >(y - position.y ); }
345
+ inline coordinate_t distanceToOriginSquared () const noexcept { return FastPower<2 >(x) + FastPower<2 >(y); }
346
+ inline f_coordinate_t distanceTo (Position position) const noexcept { return sqrt (FastPower<2 >(x - position.x ) + FastPower<2 >(y - position.y )); }
347
+ inline f_coordinate_t distanceToOrigin () const noexcept { return sqrt (FastPower<2 >(x) + FastPower<2 >(y)); }
348
348
349
349
inline Position operator +(Vector vector) const noexcept { return Position (x + vector.dx , y + vector.dy ); }
350
350
inline Position& operator +=(Vector vector) noexcept {
@@ -362,7 +362,7 @@ struct Position {
362
362
363
363
inline Iterator iterTo (Position other) const noexcept ;
364
364
365
- cord_t x, y;
365
+ coordinate_t x, y;
366
366
};
367
367
368
368
class Position ::Iterator {
@@ -440,8 +440,8 @@ inline bool areaWithinArea(Position area1Small, Position area1Large, Position ar
440
440
template <>
441
441
struct std ::hash<Position> {
442
442
inline std::size_t operator ()(Position pos) const noexcept {
443
- std::size_t x = std::hash<cord_t >{}(pos.x );
444
- std::size_t y = std::hash<cord_t >{}(pos.y );
443
+ std::size_t x = std::hash<coordinate_t >{}(pos.x );
444
+ std::size_t y = std::hash<coordinate_t >{}(pos.y );
445
445
return y + 0x9e3779b9 + (x << 6 ) + (x >> 2 );
446
446
}
447
447
};
@@ -465,7 +465,7 @@ struct std::formatter<Position> : std::formatter<std::string> {
465
465
struct FPosition {
466
466
static FPosition getInvalid () { return FPosition (std::numeric_limits<double >::quiet_NaN (), std::numeric_limits<double >::quiet_NaN ()); }
467
467
inline FPosition () noexcept : x(0 .0f ), y(0 .0f ) { }
468
- inline FPosition (f_cord_t x, f_cord_t y) noexcept : x(x), y(y) { }
468
+ inline FPosition (f_coordinate_t x, f_coordinate_t y) noexcept : x(x), y(y) { }
469
469
inline Position snap () const noexcept ;
470
470
471
471
inline std::string toString () const noexcept { return " (" + std::to_string (x) + " , " + std::to_string (y) + " )" ; }
@@ -478,12 +478,12 @@ struct FPosition {
478
478
inline bool operator !=(FPosition position) const noexcept { return !operator ==(position); }
479
479
inline bool withinArea (FPosition small, FPosition large) const noexcept { return small.x <= x && small.y <= y && large.x >= x && large.y >= y; }
480
480
481
- inline f_cord_t manhattenDistanceTo (FPosition other) const noexcept { return fabs (x - other.x ) + fabs (y - other.y ); }
482
- inline f_cord_t manhattenDistanceToOrigin () const noexcept { return fabs (x) + fabs (y); }
483
- inline f_cord_t distanceToSquared (FPosition other) const noexcept { return FastPower<2 >(x - other.x ) + FastPower<2 >(y - other.y ); }
484
- inline f_cord_t distanceToOriginSquared () const noexcept { return FastPower<2 >(x) + FastPower<2 >(y); }
485
- inline f_cord_t distanceTo (FPosition other) const noexcept { return sqrt (FastPower<2 >(x - other.x ) + FastPower<2 >(y - other.y )); }
486
- inline f_cord_t distanceToOrigin () const noexcept { return sqrt (FastPower<2 >(x) + FastPower<2 >(y)); }
481
+ inline f_coordinate_t manhattenDistanceTo (FPosition other) const noexcept { return fabs (x - other.x ) + fabs (y - other.y ); }
482
+ inline f_coordinate_t manhattenDistanceToOrigin () const noexcept { return fabs (x) + fabs (y); }
483
+ inline f_coordinate_t distanceToSquared (FPosition other) const noexcept { return FastPower<2 >(x - other.x ) + FastPower<2 >(y - other.y ); }
484
+ inline f_coordinate_t distanceToOriginSquared () const noexcept { return FastPower<2 >(x) + FastPower<2 >(y); }
485
+ inline f_coordinate_t distanceTo (FPosition other) const noexcept { return sqrt (FastPower<2 >(x - other.x ) + FastPower<2 >(y - other.y )); }
486
+ inline f_coordinate_t distanceToOrigin () const noexcept { return sqrt (FastPower<2 >(x) + FastPower<2 >(y)); }
487
487
488
488
inline FPosition operator +(FVector vector) const noexcept { return FPosition (x + vector.dx , y + vector.dy ); }
489
489
inline FPosition& operator +=(FVector vector) noexcept {
@@ -498,11 +498,11 @@ struct FPosition {
498
498
y -= vector.dy ;
499
499
return *this ;
500
500
}
501
- inline FPosition operator *(f_cord_t scalar) const noexcept { return FPosition (x * scalar, y * scalar); }
502
- inline f_cord_t lengthAlongProjectToVec (FPosition orginOfVec, FVector vector) const noexcept { return (*this - orginOfVec).lengthAlongProjectToVec (vector); }
501
+ inline FPosition operator *(f_coordinate_t scalar) const noexcept { return FPosition (x * scalar, y * scalar); }
502
+ inline f_coordinate_t lengthAlongProjectToVec (FPosition orginOfVec, FVector vector) const noexcept { return (*this - orginOfVec).lengthAlongProjectToVec (vector); }
503
503
inline FPosition projectToVec (FPosition orginOfVec, FVector vector) const noexcept { return orginOfVec + (*this - orginOfVec).projectToVec (vector); }
504
504
505
- f_cord_t x, y;
505
+ f_coordinate_t x, y;
506
506
};
507
507
508
508
inline bool areaWithinArea (FPosition area1Small, FPosition area1Large, FPosition area2Small, FPosition area2Large) noexcept {
0 commit comments