nomlib
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nomlib
math
Point2.hpp
1
/******************************************************************************
2
3
nomlib - C++11 cross-platform game engine
4
5
Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
1. Redistributions of source code must retain the above copyright notice, this
12
list of conditions and the following disclaimer.
13
2. Redistributions in binary form must reproduce the above copyright notice,
14
this list of conditions and the following disclaimer in the documentation
15
and/or other materials provided with the distribution.
16
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
******************************************************************************/
29
#ifndef NOMLIB_MATH_POINT2_HEADERS
30
#define NOMLIB_MATH_POINT2_HEADERS
31
32
#include <iostream>
33
34
#include "export.hpp"
35
#include "nomlib/config.hpp"
36
37
namespace
nom {
38
40
const
std::string POINT_DELIMITER =
", "
;
41
43
template
<
typename
T>
44
struct
NOM_EXPORT
Point2
45
{
47
Point2
(
void
) :
48
x
( -1 ),
49
y
( -1 )
50
{
51
//NOM_LOG_TRACE(NOM);
52
}
53
55
~Point2
(
void
)
56
{
57
//NOM_LOG_TRACE(NOM);
58
}
59
61
Point2
( T
x
, T
y
) :
62
x
(
x
),
63
y
(
y
)
64
{
65
//NOM_LOG_TRACE(NOM);
66
}
67
73
template
<
typename
U>
74
explicit
Point2
(
const
Point2<U>
& copy ) :
75
x
{ static_cast<T> ( copy.
x
) },
76
y
{ static_cast<T> ( copy.
y
) }
77
{
78
//NOM_LOG_TRACE(NOM);
79
}
80
82
inline
const
Point2<T>
&
get
(
void
)
const
83
{
84
return
*
this
;
85
}
86
90
static
const
Point2
null
;
91
93
static
const
Point2
zero
;
94
96
T
x
;
97
99
T
y
;
100
};
101
109
template
<
typename
T>
110
NOM_EXPORT
111
inline
std::ostream& operator << ( std::ostream& os,
const
Point2<T>
& pos )
112
{
113
os
114
<< pos.
x
115
<< POINT_DELIMITER
116
<< pos.
y
;
117
118
return
os;
119
}
120
129
template
<
typename
T>
130
NOM_EXPORT
131
inline
bool
operator == (
const
Point2<T>& lhs,
const
Point2<T>& rhs )
132
{
133
return
( lhs.x == rhs.x ) && ( lhs.y == rhs.y );
134
}
135
140
template
<
typename
T>
141
NOM_EXPORT
142
inline
bool
operator <(
const
Point2<T>
lhs,
const
Point2<T>
& rhs )
143
{
144
return
( lhs.x < rhs.x ) && ( lhs.y < rhs.y );
145
}
146
151
template
<
typename
T>
152
NOM_EXPORT
153
inline
bool
operator >(
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
154
{
155
return
( rhs.x < lhs.x ) && ( rhs.y < lhs.y );
156
}
157
162
template
<
typename
T>
163
NOM_EXPORT
164
inline
bool
operator <=(
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
165
{
166
return
( lhs.x <= rhs.x ) && ( lhs.y <= rhs.y );
167
}
168
173
template
<
typename
T>
174
NOM_EXPORT
175
inline
bool
operator >=(
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
176
{
177
return
( rhs.x <= lhs.x ) && ( rhs.y <= lhs.y );
178
}
179
188
template
<
typename
T>
189
NOM_EXPORT
190
inline
bool
operator != (
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
191
{
192
return
! ( lhs == rhs );
193
}
194
201
template
<
typename
T>
202
NOM_EXPORT
203
inline
Point2<T>
operator + (
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
204
{
205
return
Point2<T>
( lhs.x + rhs.x,
206
lhs.y + rhs.y
207
);
208
}
209
216
template
<
typename
T>
217
NOM_EXPORT
218
inline
Point2<T>
operator +(
int
lhs,
const
Point2<T>
& rhs)
219
{
220
return
Point2<T>
(lhs + rhs.x, lhs + rhs.y);
221
}
222
229
template
<
typename
T>
230
NOM_EXPORT
231
inline
Point2<T>
operator +(
const
Point2<T>
& lhs,
int
rhs)
232
{
233
return
Point2<T>
(lhs.x + rhs, lhs.y + rhs);
234
}
235
241
template
<
typename
T>
242
NOM_EXPORT
243
inline
Point2<T>
operator ++ (
Point2<T>
& rhs )
244
{
245
return
Point2<T>
( ++rhs.x,
246
++rhs.y
247
);
248
}
249
255
template
<
typename
T>
256
NOM_EXPORT
257
inline
Point2<T>
operator - (
const
Point2<T>
& rhs )
258
{
259
return
Point2<T>
( -rhs.x,
260
-rhs.y
261
);
262
}
263
270
template
<
typename
T>
271
NOM_EXPORT
272
inline
Point2<T>
operator - (
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
273
{
274
return
Point2<T>
( lhs.x - rhs.x,
275
lhs.y - rhs.y
276
);
277
}
278
285
template
<
typename
T>
286
NOM_EXPORT
287
inline
Point2<T>
operator -(
int
lhs,
const
Point2<T>
& rhs)
288
{
289
return
Point2<T>
(lhs - rhs.x, lhs - rhs.y);
290
}
291
298
template
<
typename
T>
299
NOM_EXPORT
300
inline
Point2<T>
operator -(
const
Point2<T>
& lhs,
int
rhs)
301
{
302
return
Point2<T>
(lhs.x - rhs, lhs.y - rhs);
303
}
304
310
template
<
typename
T>
311
NOM_EXPORT
312
inline
Point2<T>
operator -- (
Point2<T>
& rhs )
313
{
314
return
Point2<T>
( --rhs.x,
315
--rhs.y
316
);
317
}
318
325
template
<
typename
T>
326
NOM_EXPORT
327
inline
Point2<T>
operator * (
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
328
{
329
return
Point2<T>
( lhs.x * rhs.x,
330
lhs.y * rhs.y
331
);
332
}
333
340
template
<
typename
T>
341
NOM_EXPORT
342
inline
Point2<T>
operator *(
int
lhs,
const
Point2<T>
& rhs)
343
{
344
return
Point2<T>
(lhs * rhs.x, lhs * rhs.y);
345
}
346
353
template
<
typename
T>
354
NOM_EXPORT
355
inline
Point2<T>
operator *(
const
Point2<T>
& lhs,
int
rhs)
356
{
357
return
Point2<T>
(lhs.x * rhs, lhs.y * rhs);
358
}
359
368
template
<
typename
T>
369
NOM_EXPORT
370
inline
Point2<T>
operator / (
const
Point2<T>
& lhs,
const
Point2<T>
& rhs )
371
{
372
return
Point2<T>
( lhs.x / rhs.x,
373
lhs.y / rhs.y
374
);
375
}
376
385
template
<
typename
T>
386
NOM_EXPORT
387
inline
Point2<T>
operator /(
int
lhs,
const
Point2<T>
& rhs)
388
{
389
return
Point2<T>
(lhs / rhs.x, lhs / rhs.y);
390
}
391
400
template
<
typename
T>
401
NOM_EXPORT
402
inline
Point2<T>
operator /(
const
Point2<T>
& lhs,
int
rhs)
403
{
404
return
Point2<T>
(lhs.x / rhs, lhs.y / rhs);
405
}
406
416
template
<
typename
T>
417
NOM_EXPORT
418
inline
Point2<T>
& operator += (
Point2<T>
& lhs,
const
Point2<T>
& rhs )
419
{
420
lhs.
x
+= rhs.x;
421
lhs.y += rhs.y;
422
423
return
lhs;
424
}
425
435
template
<
typename
T>
436
NOM_EXPORT
437
inline
Point2<T>
& operator +=(
int
lhs,
const
Point2<T>
& rhs)
438
{
439
lhs += rhs.
x
;
440
lhs += rhs.y;
441
442
return
lhs;
443
}
444
454
template
<
typename
T>
455
NOM_EXPORT
456
inline
Point2<T>
& operator +=(
Point2<T>
& lhs,
int
rhs)
457
{
458
lhs.
x
+= rhs;
459
lhs.y += rhs;
460
461
return
lhs;
462
}
463
473
template
<
typename
T>
474
NOM_EXPORT
475
inline
Point2<T>
& operator -= (
Point2<T>
& lhs,
const
Point2<T>
& rhs )
476
{
477
lhs.
x
-= rhs.x;
478
lhs.y -= rhs.y;
479
480
return
lhs;
481
}
482
492
template
<
typename
T>
493
NOM_EXPORT
494
inline
Point2<T>
& operator -=(
int
lhs,
const
Point2<T>
& rhs)
495
{
496
lhs -= rhs.
x
;
497
lhs -= rhs.y;
498
499
return
lhs;
500
}
501
511
template
<
typename
T>
512
NOM_EXPORT
513
inline
Point2<T>
& operator -=(
Point2<T>
& lhs,
int
rhs)
514
{
515
lhs.
x
-= rhs;
516
lhs.y -= rhs;
517
518
return
lhs;
519
}
520
530
template
<
typename
T>
531
NOM_EXPORT
532
inline
Point2<T>
& operator *= (
Point2<T>
& lhs,
const
Point2<T>
& rhs )
533
{
534
lhs.
x
*= rhs.x;
535
lhs.y *= rhs.y;
536
537
return
lhs;
538
}
539
549
template
<
typename
T>
550
NOM_EXPORT
551
inline
Point2<T>
& operator *=(
int
lhs,
const
Point2<T>
& rhs)
552
{
553
lhs *= rhs.
x
;
554
lhs *= rhs.y;
555
556
return
lhs;
557
}
558
568
template
<
typename
T>
569
NOM_EXPORT
570
inline
Point2<T>
& operator *=(
Point2<T>
& lhs,
int
rhs)
571
{
572
lhs.
x
*= rhs;
573
lhs.y *= rhs;
574
575
return
lhs;
576
}
577
587
template
<
typename
T>
588
NOM_EXPORT
589
inline
Point2<T>
& operator /= (
Point2<T>
& lhs,
Point2<T>
& rhs )
590
{
591
lhs.
x
/= rhs.x;
592
lhs.y /= rhs.y;
593
594
return
lhs;
595
}
596
606
template
<
typename
T>
607
NOM_EXPORT
608
inline
Point2<T>
& operator /=(
int
lhs,
Point2<T>
& rhs)
609
{
610
lhs /= rhs.
x
;
611
lhs /= rhs.y;
612
613
return
lhs;
614
}
615
625
template
<
typename
T>
626
NOM_EXPORT
627
inline
Point2<T>
& operator /=(
Point2<T>
& lhs,
int
rhs)
628
{
629
lhs.
x
/= rhs;
630
lhs.y /= rhs;
631
632
return
lhs;
633
}
634
636
typedef
Point2<int>
Point2i;
637
639
typedef
Point2<float>
Point2f;
640
642
typedef
Point2<double>
Point2d;
643
645
template
<> NOM_EXPORT
const
Point2i
Point2i::null
;
646
648
template
<> NOM_EXPORT
const
Point2f
Point2f::null
;
649
651
template
<> NOM_EXPORT
const
Point2d
Point2d::null
;
652
654
template
<> NOM_EXPORT
const
Point2i
Point2i::zero
;
655
657
template
<> NOM_EXPORT
const
Point2f
Point2f::zero
;
658
661
template
<> NOM_EXPORT
const
Point2d
Point2d::zero
;
662
663
}
// namespace nom
664
665
#endif
// include guard defined
nom::Point2
2D point container
Definition
Point2.hpp:45
nom::Point2< int >::x
int x
Definition
Point2.hpp:96
nom::Point2::Point2
Point2(const Point2< U > ©)
Copy constructor.
Definition
Point2.hpp:74
nom::Point2::~Point2
~Point2(void)
Destructor.
Definition
Point2.hpp:55
nom::Point2< int >::y
int y
Definition
Point2.hpp:99
nom::Point2< int >::null
static const Point2 null
Definition
Point2.hpp:90
nom::Point2::Point2
Point2(void)
Default constructor; initialize values to Point2<T>::null.
Definition
Point2.hpp:47
nom::Point2< int >::zero
static const Point2 zero
Definition
Point2.hpp:93
nom::Point2::Point2
Point2(T x, T y)
Constructor variant for initializing x, y at construction.
Definition
Point2.hpp:61
nom::Point2::get
const Point2< T > & get(void) const
Obtain a reference of the object.
Definition
Point2.hpp:82
Generated on
for nomlib by
1.18.0