KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vector2d.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2010 Virtenio GmbH, Torsten Hueter, torsten.hueter <at> virtenio.de
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
7 * Copyright (C) 2013 CERN
8 * @author Tomasz Wlostowski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#ifndef VECTOR2D_H_
29#define VECTOR2D_H_
30
31#include <algorithm>
32#include <limits>
33#include <iostream>
34#include <sstream>
35#include <type_traits>
36
37#include <math/util.h>
38
42template <class T>
44{
47 typedef T extended_type;
48};
49
50template <>
51struct VECTOR2_TRAITS<int>
52{
53 typedef int64_t extended_type;
54};
55
56// Forward declarations for template friends
57template <class T>
58class VECTOR2;
59template <class T>
60std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector );
61
69template <class T = int>
71{
72public:
74 typedef T coord_type;
75
76 static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max();
77 static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min();
78
79 T x, y;
80
82 constexpr VECTOR2();
83
85 constexpr VECTOR2( T x, T y );
86
88 template <typename CastingType>
89 constexpr VECTOR2( const VECTOR2<CastingType>& aVec )
90 {
91 if( std::is_floating_point<T>() )
92 {
93 x = static_cast<T>( aVec.x );
94 y = static_cast<T>( aVec.y );
95 }
96 else if( std::is_floating_point<CastingType>() )
97 {
98 CastingType minI = static_cast<CastingType>( std::numeric_limits<T>::min() );
99 CastingType maxI = static_cast<CastingType>( std::numeric_limits<T>::max() );
100
101 x = static_cast<T>( std::clamp( aVec.x, minI, maxI ) );
102 y = static_cast<T>( std::clamp( aVec.y, minI, maxI ) );
103 }
104 else if( std::is_integral<T>() && std::is_integral<CastingType>() )
105 {
106 int64_t minI = static_cast<int64_t>( std::numeric_limits<T>::min() );
107 int64_t maxI = static_cast<int64_t>( std::numeric_limits<T>::max() );
108
109 x = static_cast<T>( std::clamp( static_cast<int64_t>( aVec.x ), minI, maxI ) );
110 y = static_cast<T>( std::clamp( static_cast<int64_t>( aVec.y ), minI, maxI ) );
111 }
112 else
113 {
114 x = static_cast<T>( aVec.x );
115 y = static_cast<T>( aVec.y );
116 }
117 }
118
120 constexpr VECTOR2( const VECTOR2<T>& aVec )
121 {
122 x = aVec.x;
123 y = aVec.y;
124 }
125
127 template <typename U>
128 constexpr VECTOR2<U> operator()() const
129 {
130 if( std::is_floating_point<U>::value )
131 {
132 return VECTOR2<U>( static_cast<U>( x ), static_cast<U>( y ) );
133 }
134 else if( std::is_floating_point<T>() )
135 {
136 T minI = static_cast<T>( std::numeric_limits<U>::min() );
137 T maxI = static_cast<T>( std::numeric_limits<U>::max() );
138 return VECTOR2<U>( static_cast<U>( std::clamp( x, minI, maxI ) ),
139 static_cast<U>( std::clamp( y, minI, maxI ) ) );
140 }
141 else if( std::is_integral<T>() && std::is_integral<U>() )
142 {
143 int64_t minI = static_cast<int64_t>( std::numeric_limits<U>::min() );
144 int64_t maxI = static_cast<int64_t>( std::numeric_limits<U>::max() );
145 int64_t x64 = static_cast<int64_t>( x );
146 int64_t y64 = static_cast<int64_t>( y );
147
148 return VECTOR2<U>(
149 static_cast<U>( std::clamp( x64, minI, maxI ) ),
150 static_cast<U>( std::clamp( y64, minI, maxI ) ) );
151 }
152 else
153 {
154 return VECTOR2<U>( static_cast<U>( x ), static_cast<U>( y ) );
155 }
156 }
157
165 T EuclideanNorm() const;
166
175
176
182 constexpr VECTOR2<T> Perpendicular() const;
183
190 VECTOR2<T> Resize( T aNewLength ) const;
191
197 const std::string Format() const;
198
202 constexpr extended_type Cross( const VECTOR2<T>& aVector ) const;
203
207 constexpr extended_type Dot( const VECTOR2<T>& aVector ) const;
208
213 double Distance( const VECTOR2<extended_type>& aVector ) const;
214
218 constexpr extended_type SquaredDistance( const VECTOR2<T>& aVector ) const;
219
220 // Operators
221
223 constexpr VECTOR2<T>& operator=( const VECTOR2<T>& aVector );
224
226 constexpr VECTOR2<T>& operator+=( const VECTOR2<T>& aVector );
227
229 constexpr VECTOR2<T>& operator*=( const VECTOR2<T>& aVector );
230
231 constexpr VECTOR2<T>& operator*=( const T& aScalar );
232
234 constexpr VECTOR2<T>& operator+=( const T& aScalar );
235
237 constexpr VECTOR2<T>& operator-=( const VECTOR2<T>& aVector );
238
240 constexpr VECTOR2<T>& operator-=( const T& aScalar );
241
244
246 constexpr VECTOR2<T> operator/( double aFactor ) const;
247
249 constexpr bool operator==( const VECTOR2<T>& aVector ) const;
250
252 constexpr bool operator!=( const VECTOR2<T>& aVector ) const;
253
255 constexpr bool operator<( const VECTOR2<T>& aVector ) const;
256 constexpr bool operator<=( const VECTOR2<T>& aVector ) const;
257
259 constexpr bool operator>( const VECTOR2<T>& aVector ) const;
260 constexpr bool operator>=( const VECTOR2<T>& aVector ) const;
261};
262
263
264// ----------------------
265// --- Implementation ---
266// ----------------------
267
268template <class T>
269constexpr VECTOR2<T>::VECTOR2() : x{}, y{}
270{
271}
272
273
274template <class T>
275constexpr VECTOR2<T>::VECTOR2( T aX, T aY )
276{
277 x = aX;
278 y = aY;
279}
280
281
282template <class T>
284{
285 // 45° are common in KiCad, so we can optimize the calculation
286 if( std::abs( x ) == std::abs( y ) )
287 {
288 if( std::is_integral<T>::value )
289 return KiROUND<double, T>( std::abs( x ) * M_SQRT2 );
290
291 return static_cast<T>( std::abs( x ) * M_SQRT2 );
292 }
293
294 if( x == 0 )
295 return static_cast<T>( std::abs( y ) );
296 if( y == 0 )
297 return static_cast<T>( std::abs( x ) );
298
299 if( std::is_integral<T>::value )
300 return KiROUND<double, T>( std::hypot( x, y ) );
301
302 return static_cast<T>( std::hypot( x, y ) );
303}
304
305
306template <class T>
308{
309 return (extended_type) x * x + (extended_type) y * y;
310}
311
312
313template <class T>
315{
316 VECTOR2<T> perpendicular( -y, x );
317 return perpendicular;
318}
319
320
321template <class T>
322constexpr VECTOR2<T>& VECTOR2<T>::operator=( const VECTOR2<T>& aVector )
323{
324 x = aVector.x;
325 y = aVector.y;
326 return *this;
327}
328
329
330template <class T>
331constexpr VECTOR2<T>& VECTOR2<T>::operator+=( const VECTOR2<T>& aVector )
332{
333 x += aVector.x;
334 y += aVector.y;
335 return *this;
336}
337
338
339template <class T>
340constexpr VECTOR2<T>& VECTOR2<T>::operator*=( const VECTOR2<T>& aVector )
341{
342 x *= aVector.x;
343 y *= aVector.y;
344 return *this;
345}
346
347
348template <class T>
349constexpr VECTOR2<T>& VECTOR2<T>::operator*=( const T& aScalar )
350{
351 x *= aScalar;
352 y *= aScalar;
353 return *this;
354}
355
356
357template <class T>
358constexpr VECTOR2<T>& VECTOR2<T>::operator+=( const T& aScalar )
359{
360 x += aScalar;
361 y += aScalar;
362 return *this;
363}
364
365
366template <class T>
367constexpr VECTOR2<T>& VECTOR2<T>::operator-=( const VECTOR2<T>& aVector )
368{
369 x -= aVector.x;
370 y -= aVector.y;
371 return *this;
372}
373
374
375template <class T>
376constexpr VECTOR2<T>& VECTOR2<T>::operator-=( const T& aScalar )
377{
378 x -= aScalar;
379 y -= aScalar;
380 return *this;
381}
382
383
384template <class T>
385VECTOR2<T> VECTOR2<T>::Resize( T aNewLength ) const
386{
387 if( x == 0 && y == 0 )
388 return VECTOR2<T> ( 0, 0 );
389
390 double newX;
391 double newY;
392
393 if( std::abs( x ) == std::abs( y ) )
394 {
395 newX = newY = std::abs( aNewLength ) * M_SQRT1_2;
396 }
397 else
398 {
399 extended_type x_sq = (extended_type) x * x;
400 extended_type y_sq = (extended_type) y * y;
401 extended_type l_sq = x_sq + y_sq;
402 extended_type newLength_sq = (extended_type) aNewLength * aNewLength;
403 newX = std::sqrt( rescale( newLength_sq, x_sq, l_sq ) );
404 newY = std::sqrt( rescale( newLength_sq, y_sq, l_sq ) );
405 }
406
407 if( std::is_integral<T>::value )
408 {
409 return VECTOR2<T>( static_cast<T>( x < 0 ? -KiROUND( newX ) : KiROUND( newX ) ),
410 static_cast<T>( y < 0 ? -KiROUND( newY ) : KiROUND( newY ) ) )
411 * sign( aNewLength );
412 }
413 else
414 {
415 return VECTOR2<T>( static_cast<T>( x < 0 ? -newX : newX ),
416 static_cast<T>( y < 0 ? -newY : newY ) )
417 * sign( aNewLength );
418 }
419}
420
421
422template <class T>
423const std::string VECTOR2<T>::Format() const
424{
425 std::stringstream ss;
426
427 ss << "( xy " << x << " " << y << " )";
428
429 return ss.str();
430}
431
432
433template <class T>
434concept FloatingPoint = std::is_floating_point<T>::value;
435
436template <class T>
437concept Integral = std::is_integral<T>::value;
438
439
440template <class T, class U>
442 const VECTOR2<U>& aRHS )
443{
444 return VECTOR2<std::common_type_t<T, U>>( aLHS.x + aRHS.x, aLHS.y + aRHS.y );
445}
446
447
448template <FloatingPoint T, class U>
449constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
450{
451 return VECTOR2<T>( aLHS.x + aScalar, aLHS.y + aScalar );
452}
453
454
455template <Integral T, Integral U>
456constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
457{
458 return VECTOR2<T>( aLHS.x + aScalar, aLHS.y + aScalar );
459}
460
461
462template <Integral T, FloatingPoint U>
463constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
464{
465 return VECTOR2<T>( KiROUND( aLHS.x + aScalar ), KiROUND( aLHS.y + aScalar ) );
466}
467
468
469template <class T, class U>
471 const VECTOR2<U>& aRHS )
472{
473 return VECTOR2<std::common_type_t<T, U>>( aLHS.x - aRHS.x, aLHS.y - aRHS.y );
474}
475
476
477template <FloatingPoint T, class U>
478constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, U aScalar )
479{
480 return VECTOR2<T>( aLHS.x - aScalar, aLHS.y - aScalar );
481}
482
483
484template <Integral T, Integral U>
485constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, U aScalar )
486{
487 return VECTOR2<T>( aLHS.x - aScalar, aLHS.y - aScalar );
488}
489
490
491template <Integral T, FloatingPoint U>
492constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, const U& aScalar )
493{
494 return VECTOR2<T>( KiROUND( aLHS.x - aScalar ), KiROUND( aLHS.y - aScalar ) );
495}
496
497
498template <class T>
500{
501 return VECTOR2<T> ( -x, -y );
502}
503
504
505template <class T, class U>
506#ifdef SWIG
507constexpr double operator*( const VECTOR2<T>& aLHS, const VECTOR2<U>& aRHS )
508#else
509constexpr auto operator*( const VECTOR2<T>& aLHS, const VECTOR2<U>& aRHS )
510#endif
511{
512 using extended_type = typename VECTOR2<std::common_type_t<T, U>>::extended_type;
513 return (extended_type)aLHS.x * aRHS.x + (extended_type)aLHS.y * aRHS.y;
514}
515
516
517template <class T, class U>
518constexpr VECTOR2<std::common_type_t<T, U>> operator*( const VECTOR2<T>& aLHS, const U& aScalar )
519{
520 return VECTOR2<std::common_type_t<T, U>>( aLHS.x * aScalar, aLHS.y * aScalar );
521}
522
523
524template <class T, class U>
525constexpr VECTOR2<std::common_type_t<T, U>> operator*( const T& aScalar, const VECTOR2<U>& aVector )
526{
527 return VECTOR2<std::common_type_t<T, U>>( aScalar * aVector.x, aScalar * aVector.y );
528}
529
530
531template <class T>
532constexpr VECTOR2<T> VECTOR2<T>::operator/( double aFactor ) const
533{
534 if( std::is_integral<T>::value )
535 return VECTOR2<T>( KiROUND( x / aFactor ), KiROUND( y / aFactor ) );
536 else
537 return VECTOR2<T>( static_cast<T>( x / aFactor ), static_cast<T>( y / aFactor ) );
538}
539
540
541template <class T>
542constexpr typename VECTOR2<T>::extended_type VECTOR2<T>::Cross( const VECTOR2<T>& aVector ) const
543{
544 return (extended_type) x * (extended_type) aVector.y -
545 (extended_type) y * (extended_type) aVector.x;
546}
547
548
549template <class T>
550constexpr typename VECTOR2<T>::extended_type VECTOR2<T>::Dot( const VECTOR2<T>& aVector ) const
551{
552 return (extended_type) x * (extended_type) aVector.x +
553 (extended_type) y * (extended_type) aVector.y;
554}
555
556template <class T>
557double VECTOR2<T>::Distance( const VECTOR2<extended_type>& aVector ) const
558{
559 VECTOR2<double> diff( static_cast<double>( aVector.x - x ), static_cast<double>( aVector.y - y ) );
560 return diff.EuclideanNorm();
561}
562
563template <class T>
564constexpr typename VECTOR2<T>::extended_type
566{
567 const extended_type dx = (extended_type) x - aVector.x;
568 const extended_type dy = (extended_type) y - aVector.y;
569 return dx * dx + dy * dy;
570}
571
572
573template <class T>
574constexpr bool VECTOR2<T>::operator<( const VECTOR2<T>& aVector ) const
575{
576 return ( *this * *this ) < ( aVector * aVector );
577}
578
579
580template <class T>
581constexpr bool VECTOR2<T>::operator<=( const VECTOR2<T>& aVector ) const
582{
583 return ( *this * *this ) <= ( aVector * aVector );
584}
585
586
587template <class T>
588constexpr bool VECTOR2<T>::operator>( const VECTOR2<T>& aVector ) const
589{
590 return ( *this * *this ) > ( aVector * aVector );
591}
592
593
594template <class T>
595constexpr bool VECTOR2<T>::operator>=( const VECTOR2<T>& aVector ) const
596{
597 return ( *this * *this ) >= ( aVector * aVector );
598}
599
600
601template <class T>
602constexpr bool VECTOR2<T>::operator==( VECTOR2<T> const& aVector ) const
603{
604 return ( aVector.x == x ) && ( aVector.y == y );
605}
606
607
608template <class T>
609constexpr bool VECTOR2<T>::operator!=( VECTOR2<T> const& aVector ) const
610{
611 return ( aVector.x != x ) || ( aVector.y != y );
612}
613
614
615template <class T>
616constexpr const VECTOR2<T>& LexicographicalMax( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
617{
618 if( aA.x > aB.x )
619 return aA;
620 else if( aA.x == aB.x && aA.y > aB.y )
621 return aA;
622
623 return aB;
624}
625
626
627template <class T>
628constexpr const VECTOR2<T>& LexicographicalMin( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
629{
630 if( aA.x < aB.x )
631 return aA;
632 else if( aA.x == aB.x && aA.y < aB.y )
633 return aA;
634
635 return aB;
636}
637
638
639template <class T>
640constexpr int LexicographicalCompare( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
641{
642 if( aA.x < aB.x )
643 return -1;
644 else if( aA.x > aB.x )
645 return 1;
646 else // aA.x == aB.x
647 {
648 if( aA.y < aB.y )
649 return -1;
650 else if( aA.y > aB.y )
651 return 1;
652 else
653 return 0;
654 }
655}
656
657
668template <class T>
669typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type
670equals( VECTOR2<T> const& aFirst, VECTOR2<T> const& aSecond,
671 T aEpsilon = std::numeric_limits<T>::epsilon() )
672{
673 if( !equals( aFirst.x, aSecond.x, aEpsilon ) )
674 {
675 return false;
676 }
677
678 return equals( aFirst.y, aSecond.y, aEpsilon );
679}
680
681
682template <class T>
683std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector )
684{
685 aStream << "[ " << aVector.x << " | " << aVector.y << " ]";
686 return aStream;
687}
688
689/* Default specializations */
693
694/* KiROUND specialization for vectors */
695inline constexpr VECTOR2I KiROUND( const VECTOR2D& vec )
696{
697 return VECTOR2I( KiROUND( vec.x ), KiROUND( vec.y ) );
698}
699
700/* STL specializations */
701namespace std
702{
703 // Required to enable correct use in std::map/unordered_map
704 // DO NOT USE hash tables with VECTOR2 elements. It is inefficient
705 // and degenerates to a linear search. Use the std::map/std::set
706 // trees instead that utilize the less operator below
707 // This function is purposely deleted after substantial testing
708 template <>
709 struct hash<VECTOR2I>
710 {
711 size_t operator()( const VECTOR2I& k ) const = delete;
712 };
713
714 // Required to enable use of std::hash with maps.
715 template <>
716 struct less<VECTOR2I>
717 {
718 bool operator()( const VECTOR2I& aA, const VECTOR2I& aB ) const;
719 };
720}
721
722#endif // VECTOR2D_H_
Define a general 2D-vector/point.
Definition: vector2d.h:71
constexpr bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition: vector2d.h:602
constexpr bool operator>=(const VECTOR2< T > &aVector) const
Definition: vector2d.h:595
constexpr VECTOR2< U > operator()() const
Cast a vector to another specialized subclass. Beware of rounding issues.
Definition: vector2d.h:128
constexpr VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition: vector2d.h:322
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition: vector2d.h:542
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:557
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:307
constexpr extended_type SquaredDistance(const VECTOR2< T > &aVector) const
Compute the squared distance between two vectors.
Definition: vector2d.h:565
const std::string Format() const
Return the vector formatted as a string.
Definition: vector2d.h:423
constexpr VECTOR2< T > & operator*=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:340
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:76
constexpr VECTOR2< T > & operator-=(const T &aScalar)
Compound assignment operator.
Definition: vector2d.h:376
constexpr VECTOR2< T > & operator+=(const T &aScalar)
Compound assignment operator.
Definition: vector2d.h:358
constexpr bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition: vector2d.h:609
constexpr VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:367
constexpr bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition: vector2d.h:574
constexpr VECTOR2< T > operator-()
Negate Vector operator.
Definition: vector2d.h:499
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:283
VECTOR2_TRAITS< T >::extended_type extended_type
Definition: vector2d.h:73
constexpr VECTOR2< T > operator/(double aFactor) const
Division with a factor.
Definition: vector2d.h:532
constexpr VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization. Beware of rounding issues.
Definition: vector2d.h:89
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:314
static constexpr extended_type ECOORD_MIN
Definition: vector2d.h:77
constexpr VECTOR2(const VECTOR2< T > &aVec)
Copy a vector.
Definition: vector2d.h:120
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:550
constexpr VECTOR2(T x, T y)
Construct a vector with given components x, y.
Definition: vector2d.h:275
constexpr VECTOR2< T > & operator*=(const T &aScalar)
Definition: vector2d.h:349
constexpr bool operator<=(const VECTOR2< T > &aVector) const
Definition: vector2d.h:581
constexpr VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition: vector2d.h:269
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
constexpr VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition: vector2d.h:331
T coord_type
Definition: vector2d.h:74
constexpr bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition: vector2d.h:588
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1297
STL namespace.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
int64_t extended_type
Definition: vector2d.h:53
Traits class for VECTOR2.
Definition: vector2d.h:44
T extended_type
extended range/precision types used by operations involving multiple multiplications to prevent overf...
Definition: vector2d.h:47
size_t operator()(const VECTOR2I &k) const =delete
constexpr int sign(T val)
Definition: util.h:159
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition: util.h:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690
constexpr const VECTOR2< T > & LexicographicalMax(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:616
constexpr VECTOR2I KiROUND(const VECTOR2D &vec)
Definition: vector2d.h:695
constexpr VECTOR2< std::common_type_t< T, U > > operator+(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition: vector2d.h:441
constexpr VECTOR2< std::common_type_t< T, U > > operator-(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition: vector2d.h:470
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type equals(VECTOR2< T > const &aFirst, VECTOR2< T > const &aSecond, T aEpsilon=std::numeric_limits< T >::epsilon())
Template to compare two VECTOR2<T> values for equality within a required epsilon.
Definition: vector2d.h:670
constexpr const VECTOR2< T > & LexicographicalMin(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:628
VECTOR2< int64_t > VECTOR2L
Definition: vector2d.h:692
constexpr auto operator*(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition: vector2d.h:509
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:640