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 The 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, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef VECTOR2D_H_
25#define VECTOR2D_H_
26
27#include <algorithm>
28#include <limits>
29#include <iostream>
30#include <sstream>
31#include <type_traits>
32
33#include <math/util.h>
34
38template <class T>
40{
44};
45
46template <>
47struct VECTOR2_TRAITS<int>
48{
49 typedef int64_t extended_type;
50};
51
52// Forward declarations for template friends
53template <class T>
54class VECTOR2;
55template <class T>
56std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector );
57
65template <class T = int>
67{
68public:
70 typedef T coord_type;
71
72 static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max();
73 static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min();
74
75 T x, y;
76
78 constexpr VECTOR2();
79
81 constexpr VECTOR2( T x, T y );
82
84 template <typename CastingType>
85 constexpr VECTOR2( const VECTOR2<CastingType>& aVec )
86 {
87 if constexpr( std::is_floating_point<T>() )
88 {
89 x = static_cast<T>( aVec.x );
90 y = static_cast<T>( aVec.y );
91 }
92 else if constexpr( std::is_floating_point<CastingType>() )
93 {
94 CastingType minI = static_cast<CastingType>( std::numeric_limits<T>::min() );
95 CastingType maxI = static_cast<CastingType>( std::numeric_limits<T>::max() );
96
97 x = static_cast<T>( std::clamp( aVec.x, minI, maxI ) );
98 y = static_cast<T>( std::clamp( aVec.y, minI, maxI ) );
99 }
100 else if constexpr( std::is_integral<T>() && std::is_integral<CastingType>() )
101 {
102 int64_t minI = static_cast<int64_t>( std::numeric_limits<T>::min() );
103 int64_t maxI = static_cast<int64_t>( std::numeric_limits<T>::max() );
104
105 x = static_cast<T>( std::clamp( static_cast<int64_t>( aVec.x ), minI, maxI ) );
106 y = static_cast<T>( std::clamp( static_cast<int64_t>( aVec.y ), minI, maxI ) );
107 }
108 else
109 {
110 x = static_cast<T>( aVec.x );
111 y = static_cast<T>( aVec.y );
112 }
113 }
114
116 constexpr VECTOR2( const VECTOR2<T>& aVec )
117 {
118 x = aVec.x;
119 y = aVec.y;
120 }
121
123 template <typename U>
124 constexpr VECTOR2<U> operator()() const
125 {
126 if constexpr( std::is_floating_point<U>::value )
127 {
128 return VECTOR2<U>( static_cast<U>( x ), static_cast<U>( y ) );
129 }
130 else if constexpr( std::is_floating_point<T>() )
131 {
132 constexpr T minI = static_cast<T>( std::numeric_limits<U>::min() );
133 constexpr T maxI = static_cast<T>( std::numeric_limits<U>::max() );
134 return VECTOR2<U>( static_cast<U>( std::clamp( x, minI, maxI ) ),
135 static_cast<U>( std::clamp( y, minI, maxI ) ) );
136 }
137 else if constexpr( std::is_integral<T>() && std::is_integral<U>() )
138 {
139 constexpr int64_t minI = static_cast<int64_t>( std::numeric_limits<U>::min() );
140 constexpr int64_t maxI = static_cast<int64_t>( std::numeric_limits<U>::max() );
141 int64_t x64 = static_cast<int64_t>( x );
142 int64_t y64 = static_cast<int64_t>( y );
143
144 return VECTOR2<U>(
145 static_cast<U>( std::clamp( x64, minI, maxI ) ),
146 static_cast<U>( std::clamp( y64, minI, maxI ) ) );
147 }
148 else
149 {
150 return VECTOR2<U>( static_cast<U>( x ), static_cast<U>( y ) );
151 }
152 }
153
164
173
174
180 constexpr VECTOR2<T> Perpendicular() const;
181
188 VECTOR2<T> Resize( T aNewLength ) const;
189
195 const std::string Format() const;
196
200 constexpr extended_type Cross( const VECTOR2<T>& aVector ) const;
201
205 constexpr extended_type Dot( const VECTOR2<T>& aVector ) const;
206
211 double Distance( const VECTOR2<extended_type>& aVector ) const;
212
216 constexpr extended_type SquaredDistance( const VECTOR2<T>& aVector ) const;
217
218 // Operators
219
221 constexpr VECTOR2<T>& operator=( const VECTOR2<T>& aVector );
222
224 constexpr VECTOR2<T>& operator+=( const VECTOR2<T>& aVector );
225
227 constexpr VECTOR2<T>& operator*=( const VECTOR2<T>& aVector );
228
229 constexpr VECTOR2<T>& operator*=( const T& aScalar );
230
232 constexpr VECTOR2<T>& operator+=( const T& aScalar );
233
235 constexpr VECTOR2<T>& operator-=( const VECTOR2<T>& aVector );
236
238 constexpr VECTOR2<T>& operator-=( const T& aScalar );
239
242
244 constexpr VECTOR2<T> operator/( double aFactor ) const;
245
247 constexpr bool operator==( const VECTOR2<T>& aVector ) const;
248
250 constexpr bool operator!=( const VECTOR2<T>& aVector ) const;
251
253 constexpr bool operator<( const VECTOR2<T>& aVector ) const;
254 constexpr bool operator<=( const VECTOR2<T>& aVector ) const;
255
257 constexpr bool operator>( const VECTOR2<T>& aVector ) const;
258 constexpr bool operator>=( const VECTOR2<T>& aVector ) const;
259};
260
261
262// ----------------------
263// --- Implementation ---
264// ----------------------
265
266template <class T>
267constexpr VECTOR2<T>::VECTOR2() : x{}, y{}
268{
269}
270
271
272template <class T>
273constexpr VECTOR2<T>::VECTOR2( T aX, T aY )
274{
275 x = aX;
276 y = aY;
277}
278
279
280template <class T>
282{
283 if constexpr( std::is_integral<T>::value && std::is_signed<T>::value )
284 {
285 return T( std::min<uint64_t>( RoundedHypot( x, y ), std::numeric_limits<T>::max() ) );
286 }
287 else
288 {
289 // 45° are common in KiCad, so we can optimize the calculation
290 if( std::abs( x ) == std::abs( y ) )
291 {
292 if constexpr( std::is_integral<T>::value )
293 return KiROUND<double, T>( std::abs( x ) * M_SQRT2 );
294 else
295 return static_cast<T>( std::abs( x ) * M_SQRT2 );
296 }
297
298 if( x == 0 )
299 return static_cast<T>( std::abs( y ) );
300 if( y == 0 )
301 return static_cast<T>( std::abs( x ) );
302
303 if constexpr( std::is_integral<T>::value )
304 return KiROUND<double, T>( std::hypot( x, y ) );
305 else
306 return static_cast<T>( std::hypot( x, y ) );
307 }
308}
309
310
311template <class T>
313{
314 if constexpr( std::is_integral<T>::value && std::is_same<extended_type, int64_t>::value )
315 {
316 // Past this a single square exceeds ECOORD_MAX; below it the sum still fits in uint64_t
317 constexpr uint64_t narrowMax = ct_sqrt<uint64_t>( ECOORD_MAX );
318
319 const uint64_t ax = UnsignedAbs( x );
320 const uint64_t ay = UnsignedAbs( y );
321
322 if( ax > narrowMax || ay > narrowMax )
323 return ECOORD_MAX;
324
325 return extended_type( std::min<uint64_t>( ax * ax + ay * ay, ECOORD_MAX ) );
326 }
327 else
328 {
329 return (extended_type) x * x + (extended_type) y * y;
330 }
331}
332
333
334template <class T>
336{
337 VECTOR2<T> perpendicular( -y, x );
338 return perpendicular;
339}
340
341
342template <class T>
343constexpr VECTOR2<T>& VECTOR2<T>::operator=( const VECTOR2<T>& aVector )
344{
345 x = aVector.x;
346 y = aVector.y;
347 return *this;
348}
349
350
351template <class T>
352constexpr VECTOR2<T>& VECTOR2<T>::operator+=( const VECTOR2<T>& aVector )
353{
354 x += aVector.x;
355 y += aVector.y;
356 return *this;
357}
358
359
360template <class T>
361constexpr VECTOR2<T>& VECTOR2<T>::operator*=( const VECTOR2<T>& aVector )
362{
363 x *= aVector.x;
364 y *= aVector.y;
365 return *this;
366}
367
368
369template <class T>
370constexpr VECTOR2<T>& VECTOR2<T>::operator*=( const T& aScalar )
371{
372 x *= aScalar;
373 y *= aScalar;
374 return *this;
375}
376
377
378template <class T>
379constexpr VECTOR2<T>& VECTOR2<T>::operator+=( const T& aScalar )
380{
381 x += aScalar;
382 y += aScalar;
383 return *this;
384}
385
386
387template <class T>
388constexpr VECTOR2<T>& VECTOR2<T>::operator-=( const VECTOR2<T>& aVector )
389{
390 x -= aVector.x;
391 y -= aVector.y;
392 return *this;
393}
394
395
396template <class T>
397constexpr VECTOR2<T>& VECTOR2<T>::operator-=( const T& aScalar )
398{
399 x -= aScalar;
400 y -= aScalar;
401 return *this;
402}
403
404
405template <class T>
406VECTOR2<T> VECTOR2<T>::Resize( T aNewLength ) const
407{
408 if( x == 0 && y == 0 )
409 return VECTOR2<T> ( 0, 0 );
410
411 double newX;
412 double newY;
413
414 if( std::abs( x ) == std::abs( y ) )
415 {
416 newX = newY = std::abs( aNewLength ) * M_SQRT1_2;
417 }
418 else
419 {
420 extended_type x_sq = (extended_type) x * x;
421 extended_type y_sq = (extended_type) y * y;
422 extended_type l_sq = x_sq + y_sq;
423 extended_type newLength_sq = (extended_type) aNewLength * aNewLength;
424 newX = std::sqrt( rescale( newLength_sq, x_sq, l_sq ) );
425 newY = std::sqrt( rescale( newLength_sq, y_sq, l_sq ) );
426 }
427
428 if constexpr( std::is_integral<T>::value )
429 {
430 return VECTOR2<T>( static_cast<T>( x < 0 ? -KiROUND( newX ) : KiROUND( newX ) ),
431 static_cast<T>( y < 0 ? -KiROUND( newY ) : KiROUND( newY ) ) )
432 * sign( aNewLength );
433 }
434 else
435 {
436 return VECTOR2<T>( static_cast<T>( x < 0 ? -newX : newX ),
437 static_cast<T>( y < 0 ? -newY : newY ) )
438 * sign( aNewLength );
439 }
440}
441
442
443template <class T>
444const std::string VECTOR2<T>::Format() const
445{
446 std::stringstream ss;
447
448 ss << "( xy " << x << " " << y << " )";
449
450 return ss.str();
451}
452
453
454template <class T>
455concept FloatingPoint = std::is_floating_point<T>::value;
456
457template <class T>
458concept Integral = std::is_integral<T>::value;
459
460
461template <class T, class U>
463 const VECTOR2<U>& aRHS )
464{
465 return VECTOR2<std::common_type_t<T, U>>( aLHS.x + aRHS.x, aLHS.y + aRHS.y );
466}
467
468
469template <FloatingPoint T, class U>
470constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
471{
472 return VECTOR2<T>( aLHS.x + aScalar, aLHS.y + aScalar );
473}
474
475
476template <Integral T, Integral U>
477constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
478{
479 return VECTOR2<T>( aLHS.x + aScalar, aLHS.y + aScalar );
480}
481
482
483template <Integral T, FloatingPoint U>
484constexpr VECTOR2<T> operator+( const VECTOR2<T>& aLHS, const U& aScalar )
485{
486 return VECTOR2<T>( KiROUND( aLHS.x + aScalar ), KiROUND( aLHS.y + aScalar ) );
487}
488
489
490template <class T, class U>
492 const VECTOR2<U>& aRHS )
493{
494 return VECTOR2<std::common_type_t<T, U>>( aLHS.x - aRHS.x, aLHS.y - aRHS.y );
495}
496
497
498template <FloatingPoint T, class U>
499constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, U aScalar )
500{
501 return VECTOR2<T>( aLHS.x - aScalar, aLHS.y - aScalar );
502}
503
504
505template <Integral T, Integral U>
506constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, U aScalar )
507{
508 return VECTOR2<T>( aLHS.x - aScalar, aLHS.y - aScalar );
509}
510
511
512template <Integral T, FloatingPoint U>
513constexpr VECTOR2<T> operator-( const VECTOR2<T>& aLHS, const U& aScalar )
514{
515 return VECTOR2<T>( KiROUND( aLHS.x - aScalar ), KiROUND( aLHS.y - aScalar ) );
516}
517
518
519template <class T>
521{
522 return VECTOR2<T> ( -x, -y );
523}
524
525
526template <class T, class U>
527constexpr auto operator*( const VECTOR2<T>& aLHS, const VECTOR2<U>& aRHS )
528{
530 return (extended_type)aLHS.x * aRHS.x + (extended_type)aLHS.y * aRHS.y;
531}
532
533
534template <class T, class U>
535constexpr VECTOR2<std::common_type_t<T, U>> operator*( const VECTOR2<T>& aLHS, const U& aScalar )
536{
537 return VECTOR2<std::common_type_t<T, U>>( aLHS.x * aScalar, aLHS.y * aScalar );
538}
539
540
541template <class T, class U>
542constexpr VECTOR2<std::common_type_t<T, U>> operator*( const T& aScalar, const VECTOR2<U>& aVector )
543{
544 return VECTOR2<std::common_type_t<T, U>>( aScalar * aVector.x, aScalar * aVector.y );
545}
546
547
548template <class T>
549constexpr VECTOR2<T> VECTOR2<T>::operator/( double aFactor ) const
550{
551 if constexpr( std::is_integral<T>::value )
552 return VECTOR2<T>( KiROUND( x / aFactor ), KiROUND( y / aFactor ) );
553 else
554 return VECTOR2<T>( static_cast<T>( x / aFactor ), static_cast<T>( y / aFactor ) );
555}
556
557
558template <class T>
559constexpr typename VECTOR2<T>::extended_type VECTOR2<T>::Cross( const VECTOR2<T>& aVector ) const
560{
561 return (extended_type) x * (extended_type) aVector.y -
562 (extended_type) y * (extended_type) aVector.x;
563}
564
565
566template <class T>
567constexpr typename VECTOR2<T>::extended_type VECTOR2<T>::Dot( const VECTOR2<T>& aVector ) const
568{
569 return (extended_type) x * (extended_type) aVector.x +
570 (extended_type) y * (extended_type) aVector.y;
571}
572
573template <class T>
574double VECTOR2<T>::Distance( const VECTOR2<extended_type>& aVector ) const
575{
576 VECTOR2<double> diff( static_cast<double>( aVector.x - x ), static_cast<double>( aVector.y - y ) );
577 return diff.EuclideanNorm();
578}
579
580template <class T>
581constexpr typename VECTOR2<T>::extended_type
583{
584 const extended_type dx = (extended_type) x - aVector.x;
585 const extended_type dy = (extended_type) y - aVector.y;
586 return dx * dx + dy * dy;
587}
588
589
590template <class T>
591constexpr bool VECTOR2<T>::operator<( const VECTOR2<T>& aVector ) const
592{
593 return ( *this * *this ) < ( aVector * aVector );
594}
595
596
597template <class T>
598constexpr bool VECTOR2<T>::operator<=( const VECTOR2<T>& aVector ) const
599{
600 return ( *this * *this ) <= ( aVector * aVector );
601}
602
603
604template <class T>
605constexpr bool VECTOR2<T>::operator>( const VECTOR2<T>& aVector ) const
606{
607 return ( *this * *this ) > ( aVector * aVector );
608}
609
610
611template <class T>
612constexpr bool VECTOR2<T>::operator>=( const VECTOR2<T>& aVector ) const
613{
614 return ( *this * *this ) >= ( aVector * aVector );
615}
616
617
618template <class T>
619constexpr bool VECTOR2<T>::operator==( VECTOR2<T> const& aVector ) const
620{
621 return ( aVector.x == x ) && ( aVector.y == y );
622}
623
624
625template <class T>
626constexpr bool VECTOR2<T>::operator!=( VECTOR2<T> const& aVector ) const
627{
628 return ( aVector.x != x ) || ( aVector.y != y );
629}
630
631
632template <class T>
633constexpr const VECTOR2<T>& LexicographicalMax( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
634{
635 if( aA.x > aB.x )
636 return aA;
637 else if( aA.x == aB.x && aA.y > aB.y )
638 return aA;
639
640 return aB;
641}
642
643
644template <class T>
645constexpr const VECTOR2<T>& LexicographicalMin( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
646{
647 if( aA.x < aB.x )
648 return aA;
649 else if( aA.x == aB.x && aA.y < aB.y )
650 return aA;
651
652 return aB;
653}
654
655
656template <class T>
657constexpr int LexicographicalCompare( const VECTOR2<T>& aA, const VECTOR2<T>& aB )
658{
659 if( aA.x < aB.x )
660 return -1;
661 else if( aA.x > aB.x )
662 return 1;
663 else // aA.x == aB.x
664 {
665 if( aA.y < aB.y )
666 return -1;
667 else if( aA.y > aB.y )
668 return 1;
669 else
670 return 0;
671 }
672}
673
674
685template <class T>
686typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type
687equals( VECTOR2<T> const& aFirst, VECTOR2<T> const& aSecond,
688 T aEpsilon = std::numeric_limits<T>::epsilon() )
689{
690 if( !equals( aFirst.x, aSecond.x, aEpsilon ) )
691 {
692 return false;
693 }
694
695 return equals( aFirst.y, aSecond.y, aEpsilon );
696}
697
698
699template <class T>
700std::ostream& operator<<( std::ostream& aStream, const VECTOR2<T>& aVector )
701{
702 aStream << "[ " << aVector.x << " | " << aVector.y << " ]";
703 return aStream;
704}
705
706/* Default specializations */
710
711/* KiROUND specialization for vectors */
712inline constexpr VECTOR2I KiROUND( const VECTOR2D& vec )
713{
714 return VECTOR2I( KiROUND( vec.x ), KiROUND( vec.y ) );
715}
716
717inline constexpr VECTOR2I KiROUND( double x, double y )
718{
719 return VECTOR2I( KiROUND( x ), KiROUND( y ) );
720}
721
722/* STL specializations */
723namespace std
724{
725 // Required to enable correct use in std::map/unordered_map
726 // DO NOT USE hash tables with VECTOR2 elements. It is inefficient
727 // and degenerates to a linear search. Use the std::map/std::set
728 // trees instead that utilize the less operator below
729 // This function is purposely deleted after substantial testing
730 template <>
731 struct hash<VECTOR2I>
732 {
733 size_t operator()( const VECTOR2I& k ) const = delete;
734 };
735
736 // Required to enable use of std::hash with maps.
737 template <>
738 struct less<VECTOR2I>
739 {
740 bool operator()( const VECTOR2I& aA, const VECTOR2I& aB ) const;
741 };
742}
743
744#endif // VECTOR2D_H_
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:982
Define a general 2D-vector/point.
Definition vector2d.h:67
constexpr bool operator==(const VECTOR2< T > &aVector) const
Equality operator.
Definition vector2d.h:619
constexpr bool operator>=(const VECTOR2< T > &aVector) const
Definition vector2d.h:612
constexpr VECTOR2< U > operator()() const
Cast a vector to another specialized subclass. Beware of rounding issues.
Definition vector2d.h:124
constexpr VECTOR2< T > & operator=(const VECTOR2< T > &aVector)
Assignment operator.
Definition vector2d.h:343
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition vector2d.h:559
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition vector2d.h:574
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition vector2d.h:312
constexpr extended_type SquaredDistance(const VECTOR2< T > &aVector) const
Compute the squared distance between two vectors.
Definition vector2d.h:582
const std::string Format() const
Return the vector formatted as a string.
Definition vector2d.h:444
constexpr VECTOR2< T > & operator*=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition vector2d.h:361
static constexpr extended_type ECOORD_MAX
Definition vector2d.h:72
constexpr VECTOR2< T > & operator-=(const T &aScalar)
Compound assignment operator.
Definition vector2d.h:397
constexpr VECTOR2< T > & operator+=(const T &aScalar)
Compound assignment operator.
Definition vector2d.h:379
constexpr bool operator!=(const VECTOR2< T > &aVector) const
Not equality operator.
Definition vector2d.h:626
constexpr VECTOR2< T > & operator-=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition vector2d.h:388
constexpr bool operator<(const VECTOR2< T > &aVector) const
Smaller than operator.
Definition vector2d.h:591
constexpr VECTOR2< T > operator-()
Negate Vector operator.
Definition vector2d.h:520
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
VECTOR2_TRAITS< size_type >::extended_type extended_type
Definition vector2d.h:69
constexpr VECTOR2< T > operator/(double aFactor) const
Division with a factor.
Definition vector2d.h:549
constexpr VECTOR2(const VECTOR2< CastingType > &aVec)
Initializes a vector from another specialization. Beware of rounding issues.
Definition vector2d.h:85
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition vector2d.h:335
static constexpr extended_type ECOORD_MIN
Definition vector2d.h:73
constexpr VECTOR2(const VECTOR2< T > &aVec)
Copy a vector.
Definition vector2d.h:116
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition vector2d.h:567
constexpr VECTOR2(T x, T y)
Construct a vector with given components x, y.
Definition vector2d.h:273
constexpr VECTOR2< T > & operator*=(const T &aScalar)
Definition vector2d.h:370
constexpr bool operator<=(const VECTOR2< T > &aVector) const
Definition vector2d.h:598
constexpr VECTOR2()
Construct a 2D-vector with x, y = 0.
Definition vector2d.h:267
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:406
constexpr VECTOR2< T > & operator+=(const VECTOR2< T > &aVector)
Compound assignment operator.
Definition vector2d.h:352
size_type coord_type
Definition vector2d.h:70
constexpr bool operator>(const VECTOR2< T > &aVector) const
Greater than operator.
Definition vector2d.h:605
STL namespace.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437
Traits class for VECTOR2.
Definition vector2d.h:40
T extended_type
extended range/precision types used by operations involving multiple multiplications to prevent overf...
Definition vector2d.h:43
size_t operator()(const VECTOR2I &k) const =delete
bool operator()(const VECTOR2I &aA, const VECTOR2I &aB) const
Definition vector2.cpp:22
uint64_t RoundedHypot(int64_t aX, int64_t aY)
Nearest integer to sqrt( aX^2 + aY^2 ), computed exactly.
Definition util.h:247
constexpr int sign(T val)
Definition util.h:166
constexpr uint64_t UnsignedAbs(int64_t aX)
Magnitude of a signed integer, well defined for INT64_MIN.
Definition util.h:234
constexpr T ct_sqrt(T aX)
Floor of the square root of an integer, evaluated at compile time.
Definition util.h:197
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition util.h:160
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
std::ostream & operator<<(std::ostream &aStream, const VECTOR2< T > &aVector)
Definition vector2d.h:700
constexpr const VECTOR2< T > & LexicographicalMax(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:633
constexpr VECTOR2I KiROUND(const VECTOR2D &vec)
Definition vector2d.h:712
constexpr VECTOR2< std::common_type_t< T, U > > operator+(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition vector2d.h:462
constexpr VECTOR2< std::common_type_t< T, U > > operator-(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition vector2d.h:491
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:687
constexpr const VECTOR2< T > & LexicographicalMin(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:645
VECTOR2< int64_t > VECTOR2L
Definition vector2d.h:709
constexpr auto operator*(const VECTOR2< T > &aLHS, const VECTOR2< U > &aRHS)
Definition vector2d.h:527
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:657