-
Notifications
You must be signed in to change notification settings - Fork 12
/
MagnumMath.hpp
7950 lines (6195 loc) · 324 KB
/
MagnumMath.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Magnum::Math
— a graphics-focused vector math library
https://doc.magnum.graphics/magnum/namespaceMagnum_1_1Math.html
https://doc.magnum.graphics/magnum/namespaceMagnum_1_1EigenIntegration.html
https://doc.magnum.graphics/magnum/namespaceMagnum_1_1GlmIntegration.html
This is a single-header library generated from the Magnum project. With the
goal being easy integration, it's deliberately free of all comments to keep
the file size small. More info, changelogs and full docs here:
- Project homepage — https://magnum.graphics/magnum/
- Documentation — https://doc.magnum.graphics/
- GitHub project page — https://github.com/mosra/magnum
- GitHub Singles repository — https://github.com/mosra/magnum-singles
The library has a separate non-inline implementation part, enable it *just
once* like this:
#define MAGNUM_MATH_IMPLEMENTATION
#include <MagnumMath.hpp>
If you need the deinlined symbols to be exported from a shared library,
`#define MAGNUM_EXPORT` as appropriate. In addition, contents of the
GlmIntegration and EigenIntegration libraries are included as well ---
opt-in by specifying either `#define MAGNUM_MATH_GLM_INTEGRATION` or
`#define MAGNUM_MATH_EIGEN_INTEGRATION` before including the file.
Including it multiple times with different macros defined works as well.
v2020.06-2544-g3e435 (2023-09-11)
- Fixes to the Utility::swap() helper to avoid ambiguity with std::swap()
v2020.06-2502-gfa079385b (2023-08-28)
- New Range1Dui, Range2Dui, Range3Dui, Degh, Radh, Range1Dh, Range2Dh and
Range3Dh typedefs
- New binomialCoefficient(), popcount() and fmod() APIs
- Added r() and g() accessors to Vector2 and rg() to Vector3
- New Color3::fromLinearRgbInt(), toLinearRgbInt() and
Color4::fromLinearRgbaInt(), toLinearRgbaInt() for converting a color
from/to a packed 24-/32-bit representation without a sRGB conversion;
integer-taking fromSrgb() and fromSrgbAlpha() is now renamed to
fromSrgbInt() and fromSrgbAlphaInt() for consistency
- Added an off-center Matrix3::projection() and
Matrix4::orthographicProjection() overloads
- New Matrix4::orthographicProjectionNear(), orthographicProjectionFar(),
perspectiveProjectionNear(), perspectiveProjectionFar() accessors
- Added Quaternion::reflection() and reflectVector() APIs which perform
a reflection with a quaternion instead of a rotation
- Ability to create a DualQuaternion from a rotation quaternion and a
translation vector
- angle() for Quaternion is now called halfAngle() because that's what it
returns, angle() will be eventually reintroduced again but returning
the correct value
- Convenience Distance::pointPoint() and pointPointSquared(),
Intersection::pointCircle() and pointSphere() APIs as a more
self-documenting way of using (a - b).length() or dot()
- New Intersection::rayRange() API
- Conversion between Eigen::AlignedBox and Range
- Added unary operator+ to all math classes
- Matrices can now created from matrices of different sizes with a custom
value on new diagonal elements
- data() accessors of all classes now return sized array references
instead of pointers
- Fixed Matrix4::normalMatrix() to behave correctly in presence of a
reflection
- BoolVector is renamed to BitVector and has new set() and reset() APIs
- 64-bit integers and long doubles are no longer compiled away on
Emscripten
- Fixed QuadraticBezier2Dd, QuadraticBezier3Dd, CubicBezier2Dd and
CubicBezier3Dd typedefs to be actually doubles
- Compatibility with C++20 which removes the <ciso646> header
v2020.06-0-gfac6f4da2 (2020-06-27)
- Various fixes for Clang-CL compatibility
- Expanding the APIs to work with Half and long double types
- Magnum::Math::NoInit is now Magnum::NoInit
- Minor changes for faster performance of dot() and cross() in Debug
- Added reflect() and refract() functions
- slerp() / slerpShortestPath() falls back to linear interpolation for
quaternions that are close together, instead or always returning the
first
- Added Quaternion::toEuler()
- Added transformVector() to DualComplex and DualQuaternion to have the
the same set of APIs as with Matrix3 / Matrix4
- Mutable access to Frustum planes
- Fixed implicit conversion of std::pair to Range*D
- New BoolVector[234], 8-/16-bit and half-float vector and matrix
convenience typedefs
v2019.10-0-g8412e8f99 (2019-10-24)
- New IsScalar, IsVector, IsIntegral, IsFloatingPoint type traits,
correct handling of Deg and Rad types in all APIs
- Guaranteed NaN handling semantic in min()/max()/minmax() APIs
- Using a GCC compiler builtin in sincos()
- swizzle() is replaced with gather() and scatter()
- Added Matrix::{cofactor,comatrix,adjugate}(), Matrix4::normalMatrix()
- New Matrix4::perspectiveProjection() overload taking corner positions
- Handling also Eigen::Ref types; EigenIntegration::eigenCast() is now
just EigenIntegration::cast()
v2019.01-241-g93686746a (2019-04-03)
- Initial release
Generated from Corrade v2020.06-1502-g147e (2023-09-11),
Magnum v2020.06-2544-g3e435 (2023-09-11) and
Magnum Integration v2020.06-201-gbb8a (2023-09-11), 7950 / 10096 LoC
*/
/*
This file is part of Magnum.
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2019, 2020, 2021, 2022, 2023
Vladimír Vondruš <[email protected]>
Copyright © 2016 Ashwin Ravichandran <[email protected]>
Copyright © 2016, 2018, 2020 Jonathan Hale <[email protected]>
Copyright © 2017 sigman78 <[email protected]>
Copyright © 2019 Marco Melorio <[email protected]>
Copyright © 2020 Janos <[email protected]>
Copyright © 2020 Nghia Truong <[email protected]>
Copyright © 2020 Pablo Escobar <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <type_traits>
#include <utility>
#if (!defined(CORRADE_ASSERT) || !defined(CORRADE_CONSTEXPR_ASSERT) || !defined(CORRADE_INTERNAL_ASSERT_OUTPUT) || !defined(CORRADE_INTERNAL_ASSERT_UNREACHABLE)) && !defined(NDEBUG)
#include <cassert>
#endif
#if defined(_MSC_VER) && _MSC_VER < 1920
#define CORRADE_MSVC2017_COMPATIBILITY
#endif
#if defined(_MSC_VER) && _MSC_VER < 1910
#define CORRADE_MSVC2015_COMPATIBILITY
#endif
#ifdef _WIN32
#define CORRADE_TARGET_WINDOWS
#endif
#ifdef __EMSCRIPTEN__
#define CORRADE_TARGET_EMSCRIPTEN
#endif
#ifdef __ANDROID__
#define CORRADE_TARGET_ANDROID
#endif
#ifdef _MSC_VER
#ifdef _MSVC_LANG
#define CORRADE_CXX_STANDARD _MSVC_LANG
#else
#define CORRADE_CXX_STANDARD 201103L
#endif
#else
#define CORRADE_CXX_STANDARD __cplusplus
#endif
#if CORRADE_CXX_STANDARD >= 202002
#include <version>
#else
#include <ciso646>
#endif
#ifdef _LIBCPP_VERSION
#define CORRADE_TARGET_LIBCXX
#elif defined(_CPPLIB_VER)
#define CORRADE_TARGET_DINKUMWARE
#elif defined(__GLIBCXX__)
#define CORRADE_TARGET_LIBSTDCXX
#elif defined(__has_include)
#if __has_include(<bits/c++config.h>)
#include <bits/c++config.h>
#ifdef __GLIBCXX__
#define CORRADE_TARGET_LIBSTDCXX
#endif
#endif
#elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
#define CORRADE_TARGET_LIBSTDCXX
#else
#endif
#ifdef __GNUC__
#define CORRADE_TARGET_GCC
#endif
#ifdef __clang__
#define CORRADE_TARGET_CLANG
#endif
#if defined(__clang__) && defined(_MSC_VER)
#define CORRADE_TARGET_CLANG_CL
#endif
#ifdef _MSC_VER
#define CORRADE_TARGET_MSVC
#endif
#if defined(CORRADE_TARGET_MSVC) || (defined(CORRADE_TARGET_ANDROID) && !__LP64__) || defined(CORRADE_TARGET_EMSCRIPTEN) || (defined(CORRADE_TARGET_APPLE) && !defined(CORRADE_TARGET_IOS) && defined(CORRADE_TARGET_ARM))
#define CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
#endif
#ifndef MAGNUM_EXPORT
#define MAGNUM_EXPORT
#endif
#ifndef Corrade_Utility_StlMath_h
#define Corrade_Utility_StlMath_h
#ifdef _GLIBCXX_USE_STD_SPEC_FUNCS
#undef _GLIBCXX_USE_STD_SPEC_FUNCS
#define _GLIBCXX_USE_STD_SPEC_FUNCS 0
#endif
#include <cmath>
#endif
#ifndef Magnum_Types_h
#define Magnum_Types_h
namespace Magnum {
typedef std::uint8_t UnsignedByte;
typedef std::int8_t Byte;
typedef std::uint16_t UnsignedShort;
typedef std::int16_t Short;
typedef std::uint32_t UnsignedInt;
typedef std::int32_t Int;
typedef std::uint64_t UnsignedLong;
typedef std::int64_t Long;
typedef float Float;
typedef double Double;
}
#endif
#ifndef Magnum_Math_Math_h
#define Magnum_Math_Math_h
namespace Magnum { namespace Math {
template<std::size_t> class BitVector;
template<class> struct Constants;
template<class> class Complex;
template<class> class Dual;
template<class> class DualComplex;
template<class> class DualQuaternion;
template<class> class Frustum;
template<std::size_t, class> class Matrix;
template<class T> using Matrix2x2 = Matrix<2, T>;
template<class T> using Matrix3x3 = Matrix<3, T>;
template<class T> using Matrix4x4 = Matrix<4, T>;
template<class> class Matrix3;
template<class> class Matrix4;
template<class> class Quaternion;
template<std::size_t, std::size_t, class> class RectangularMatrix;
template<class T> using Matrix2x3 = RectangularMatrix<2, 3, T>;
template<class T> using Matrix3x2 = RectangularMatrix<3, 2, T>;
template<class T> using Matrix2x4 = RectangularMatrix<2, 4, T>;
template<class T> using Matrix4x2 = RectangularMatrix<4, 2, T>;
template<class T> using Matrix3x4 = RectangularMatrix<3, 4, T>;
template<class T> using Matrix4x3 = RectangularMatrix<4, 3, T>;
template<template<class> class, class> class Unit;
template<class> class Deg;
template<class> class Rad;
class Half;
template<std::size_t, class> class Vector;
template<class> class Vector2;
template<class> class Vector3;
template<class> class Vector4;
template<class> struct ColorHsv;
template<class> class Color3;
template<class> class Color4;
template<UnsignedInt, UnsignedInt, class> class Bezier;
template<UnsignedInt dimensions, class T> using QuadraticBezier = Bezier<2, dimensions, T>;
template<UnsignedInt dimensions, class T> using CubicBezier = Bezier<3, dimensions, T>;
template<class T> using QuadraticBezier2D = QuadraticBezier<2, T>;
template<class T> using QuadraticBezier3D = QuadraticBezier<3, T>;
template<class T> using CubicBezier2D = CubicBezier<2, T>;
template<class T> using CubicBezier3D = CubicBezier<3, T>;
template<class> class CubicHermite;
template<class T> using CubicHermite1D = CubicHermite<T>;
template<class T> using CubicHermite2D = CubicHermite<Vector2<T>>;
template<class T> using CubicHermite3D = CubicHermite<Vector3<T>>;
template<class T> using CubicHermiteComplex = CubicHermite<Complex<T>>;
template<class T> using CubicHermiteQuaternion = CubicHermite<Quaternion<T>>;
template<UnsignedInt, class> class Range;
template<class T> using Range1D = Range<1, T>;
template<class> class Range2D;
template<class> class Range3D;
}}
#endif
#ifndef MagnumMath_hpp
#define MagnumMath_hpp
#define CORRADE_HAS_TYPE(className, ...) \
template<class U> class className { \
template<class T> static char get(T&&, __VA_ARGS__* = nullptr); \
static short get(...); \
public: \
enum: bool { value = sizeof(get(std::declval<U>())) == sizeof(char) }; \
}
namespace Magnum {
typedef Math::Half Half;
typedef Math::BitVector<2> BitVector2;
typedef Math::BitVector<3> BitVector3;
typedef Math::BitVector<4> BitVector4;
typedef Math::Vector2<Float> Vector2;
typedef Math::Vector3<Float> Vector3;
typedef Math::Vector4<Float> Vector4;
typedef Math::Vector2<UnsignedByte> Vector2ub;
typedef Math::Vector3<UnsignedByte> Vector3ub;
typedef Math::Vector4<UnsignedByte> Vector4ub;
typedef Math::Vector2<Byte> Vector2b;
typedef Math::Vector3<Byte> Vector3b;
typedef Math::Vector4<Byte> Vector4b;
typedef Math::Vector2<UnsignedShort> Vector2us;
typedef Math::Vector3<UnsignedShort> Vector3us;
typedef Math::Vector4<UnsignedShort> Vector4us;
typedef Math::Vector2<Short> Vector2s;
typedef Math::Vector3<Short> Vector3s;
typedef Math::Vector4<Short> Vector4s;
typedef Math::Vector2<UnsignedInt> Vector2ui;
typedef Math::Vector3<UnsignedInt> Vector3ui;
typedef Math::Vector4<UnsignedInt> Vector4ui;
typedef Math::Vector2<Int> Vector2i;
typedef Math::Vector3<Int> Vector3i;
typedef Math::Vector4<Int> Vector4i;
typedef Math::Color3<Float> Color3;
typedef Math::Color4<Float> Color4;
typedef Math::Color3<UnsignedByte> Color3ub;
typedef Math::Color4<UnsignedByte> Color4ub;
typedef Math::Color3<UnsignedShort> Color3us;
typedef Math::Color4<UnsignedShort> Color4us;
typedef Math::Matrix3<Float> Matrix3;
typedef Math::Matrix4<Float> Matrix4;
typedef Math::Matrix2x2<Float> Matrix2x2;
typedef Math::Matrix3x3<Float> Matrix3x3;
typedef Math::Matrix4x4<Float> Matrix4x4;
typedef Math::Matrix2x3<Float> Matrix2x3;
typedef Math::Matrix3x2<Float> Matrix3x2;
typedef Math::Matrix2x4<Float> Matrix2x4;
typedef Math::Matrix4x2<Float> Matrix4x2;
typedef Math::Matrix3x4<Float> Matrix3x4;
typedef Math::Matrix4x3<Float> Matrix4x3;
typedef Math::Matrix2x2<Byte> Matrix2x2b;
typedef Math::Matrix2x3<Byte> Matrix2x3b;
typedef Math::Matrix2x4<Byte> Matrix2x4b;
typedef Math::Matrix3x2<Byte> Matrix3x2b;
typedef Math::Matrix3x3<Byte> Matrix3x3b;
typedef Math::Matrix3x4<Byte> Matrix3x4b;
typedef Math::Matrix4x2<Byte> Matrix4x2b;
typedef Math::Matrix4x3<Byte> Matrix4x3b;
typedef Math::Matrix4x4<Byte> Matrix4x4b;
typedef Math::Matrix2x2<Short> Matrix2x2s;
typedef Math::Matrix2x3<Short> Matrix2x3s;
typedef Math::Matrix2x4<Short> Matrix2x4s;
typedef Math::Matrix3x2<Short> Matrix3x2s;
typedef Math::Matrix3x3<Short> Matrix3x3s;
typedef Math::Matrix3x4<Short> Matrix3x4s;
typedef Math::Matrix4x2<Short> Matrix4x2s;
typedef Math::Matrix4x3<Short> Matrix4x3s;
typedef Math::Matrix4x4<Short> Matrix4x4s;
typedef Math::QuadraticBezier2D<Float> QuadraticBezier2D;
typedef Math::QuadraticBezier3D<Float> QuadraticBezier3D;
typedef Math::CubicBezier2D<Float> CubicBezier2D;
typedef Math::CubicBezier3D<Float> CubicBezier3D;
typedef Math::CubicHermite1D<Float> CubicHermite1D;
typedef Math::CubicHermite2D<Float> CubicHermite2D;
typedef Math::CubicHermite3D<Float> CubicHermite3D;
typedef Math::CubicHermiteComplex<Float> CubicHermiteComplex;
typedef Math::CubicHermiteQuaternion<Float> CubicHermiteQuaternion;
typedef Math::Complex<Float> Complex;
typedef Math::DualComplex<Float> DualComplex;
typedef Math::Quaternion<Float> Quaternion;
typedef Math::DualQuaternion<Float> DualQuaternion;
typedef Math::Constants<Float> Constants;
typedef Math::Deg<Float> Deg;
typedef Math::Rad<Float> Rad;
typedef Math::Range1D<Float> Range1D;
typedef Math::Range2D<Float> Range2D;
typedef Math::Range3D<Float> Range3D;
typedef Math::Range1D<UnsignedInt> Range1Dui;
typedef Math::Range2D<UnsignedInt> Range2Dui;
typedef Math::Range3D<UnsignedInt> Range3Dui;
typedef Math::Range1D<Int> Range1Di;
typedef Math::Range2D<Int> Range2Di;
typedef Math::Range3D<Int> Range3Di;
typedef Math::Frustum<Float> Frustum;
typedef Math::Vector2<Half> Vector2h;
typedef Math::Vector3<Half> Vector3h;
typedef Math::Vector4<Half> Vector4h;
typedef Math::Color3<Half> Color3h;
typedef Math::Color4<Half> Color4h;
typedef Math::Matrix2x2<Half> Matrix2x2h;
typedef Math::Matrix2x3<Half> Matrix2x3h;
typedef Math::Matrix2x4<Half> Matrix2x4h;
typedef Math::Matrix3x2<Half> Matrix3x2h;
typedef Math::Matrix3x3<Half> Matrix3x3h;
typedef Math::Matrix3x4<Half> Matrix3x4h;
typedef Math::Matrix4x2<Half> Matrix4x2h;
typedef Math::Matrix4x3<Half> Matrix4x3h;
typedef Math::Matrix4x4<Half> Matrix4x4h;
typedef Math::Deg<Half> Degh;
typedef Math::Rad<Half> Radh;
typedef Math::Range1D<Half> Range1Dh;
typedef Math::Range2D<Half> Range2Dh;
typedef Math::Range3D<Half> Range3Dh;
typedef Math::Vector2<Double> Vector2d;
typedef Math::Vector3<Double> Vector3d;
typedef Math::Vector4<Double> Vector4d;
typedef Math::Matrix3<Double> Matrix3d;
typedef Math::Matrix4<Double> Matrix4d;
typedef Math::Matrix2x2<Double> Matrix2x2d;
typedef Math::Matrix3x3<Double> Matrix3x3d;
typedef Math::Matrix4x4<Double> Matrix4x4d;
typedef Math::Matrix2x3<Double> Matrix2x3d;
typedef Math::Matrix3x2<Double> Matrix3x2d;
typedef Math::Matrix2x4<Double> Matrix2x4d;
typedef Math::Matrix4x2<Double> Matrix4x2d;
typedef Math::Matrix3x4<Double> Matrix3x4d;
typedef Math::Matrix4x3<Double> Matrix4x3d;
typedef Math::QuadraticBezier2D<Double> QuadraticBezier2Dd;
typedef Math::QuadraticBezier3D<Double> QuadraticBezier3Dd;
typedef Math::CubicBezier2D<Double> CubicBezier2Dd;
typedef Math::CubicBezier3D<Double> CubicBezier3Dd;
typedef Math::CubicHermite1D<Double> CubicHermite1Dd;
typedef Math::CubicHermite2D<Double> CubicHermite2Dd;
typedef Math::CubicHermite3D<Double> CubicHermite3Dd;
typedef Math::CubicHermiteComplex<Double> CubicHermiteComplexd;
typedef Math::CubicHermiteQuaternion<Double> CubicHermiteQuaterniond;
typedef Math::Complex<Double> Complexd;
typedef Math::DualComplex<Double> DualComplexd;
typedef Math::Quaternion<Double> Quaterniond;
typedef Math::DualQuaternion<Double> DualQuaterniond;
typedef Math::Constants<Double> Constantsd;
typedef Math::Deg<Double> Degd;
typedef Math::Rad<Double> Radd;
typedef Math::Range1D<Double> Range1Dd;
typedef Math::Range2D<Double> Range2Dd;
typedef Math::Range3D<Double> Range3Dd;
typedef Math::Frustum<Double> Frustumd;
}
#endif
#ifndef Magnum_Math_Constants_h
#define Magnum_Math_Constants_h
namespace Magnum { namespace Math {
template<class> struct Constants;
#ifndef CORRADE_TARGET_EMSCRIPTEN
template<> struct Constants<long double> {
static constexpr long double pi() { return 3.14159265358979323846l; }
};
#endif
template<> struct Constants<Double> {
Constants() = delete;
static constexpr Double pi() { return 3.1415926535897932; }
static constexpr Double piHalf() { return 1.5707963267948966; }
static constexpr Double piQuarter() { return 0.7853981633974483; }
static constexpr Double tau() { return 6.2831853071795864; }
static constexpr Double e() { return 2.7182818284590452; }
static constexpr Double sqrt2() { return 1.4142135623730950; }
static constexpr Double sqrt3() { return 1.7320508075688773; }
static constexpr Double sqrtHalf() { return 0.7071067811865475; }
static constexpr Double nan() {
#ifdef CORRADE_TARGET_CLANG_CL
return __builtin_nan("0");
#else
return Double(NAN);
#endif
}
static constexpr Double inf() {
#if defined(CORRADE_TARGET_CLANG_CL) && __clang_major__ < 9
return __builtin_huge_val();
#else
return HUGE_VAL;
#endif
}
};
template<> struct Constants<Float> {
Constants() = delete;
static constexpr Float pi() { return 3.141592654f; }
static constexpr Float piHalf() { return 1.570796327f; }
static constexpr Float piQuarter() { return 0.785398163f; }
static constexpr Float tau() { return 6.283185307f; }
static constexpr Float e() { return 2.718281828f; }
static constexpr Float sqrt2() { return 1.414213562f; }
static constexpr Float sqrt3() { return 1.732050808f; }
static constexpr Float sqrtHalf() { return 0.707106781f; }
static constexpr Float nan() {
#ifdef CORRADE_TARGET_CLANG_CL
return __builtin_nanf("0");
#else
return NAN;
#endif
}
static constexpr Float inf() {
#if defined(CORRADE_TARGET_CLANG_CL) && __clang_major__ < 9
return __builtin_huge_valf();
#else
return HUGE_VALF;
#endif
}
};
}}
#endif
#ifndef Magnum_Math_TypeTraits_h
#define Magnum_Math_TypeTraits_h
namespace Magnum { namespace Math {
template<class T> struct IsScalar
: std::false_type
{};
template<> struct IsScalar<char>: std::true_type {};
template<> struct IsScalar<signed char>: std::true_type {};
template<> struct IsScalar<unsigned char>: std::true_type {};
template<> struct IsScalar<short>: std::true_type {};
template<> struct IsScalar<unsigned short>: std::true_type {};
template<> struct IsScalar<int>: std::true_type {};
template<> struct IsScalar<unsigned int>: std::true_type {};
template<> struct IsScalar<long>: std::true_type {};
template<> struct IsScalar<unsigned long>: std::true_type {};
template<> struct IsScalar<long long>: std::true_type {};
template<> struct IsScalar<unsigned long long>: std::true_type {};
template<> struct IsScalar<float>: std::true_type {};
template<> struct IsScalar<Half>: std::true_type {};
template<> struct IsScalar<double>: std::true_type {};
template<> struct IsScalar<long double>: std::true_type {};
template<template<class> class Derived, class T> struct IsScalar<Unit<Derived, T>>: std::true_type {};
template<class T> struct IsScalar<Deg<T>>: std::true_type {};
template<class T> struct IsScalar<Rad<T>>: std::true_type {};
template<class T> struct IsVector
: std::false_type
{};
template<std::size_t size, class T> struct IsVector<Vector<size, T>>: std::true_type {};
template<class T> struct IsVector<Vector2<T>>: std::true_type {};
template<class T> struct IsVector<Vector3<T>>: std::true_type {};
template<class T> struct IsVector<Vector4<T>>: std::true_type {};
template<class T> struct IsVector<Color3<T>>: std::true_type {};
template<class T> struct IsVector<Color4<T>>: std::true_type {};
template<class T> struct IsIntegral
: std::false_type
{};
template<> struct IsIntegral<char>: std::true_type {};
template<> struct IsIntegral<signed char>: std::true_type {};
template<> struct IsIntegral<unsigned char>: std::true_type {};
template<> struct IsIntegral<short>: std::true_type {};
template<> struct IsIntegral<unsigned short>: std::true_type {};
template<> struct IsIntegral<int>: std::true_type {};
template<> struct IsIntegral<unsigned int>: std::true_type {};
template<> struct IsIntegral<long>: std::true_type {};
template<> struct IsIntegral<unsigned long>: std::true_type {};
template<> struct IsIntegral<long long>: std::true_type {};
template<> struct IsIntegral<unsigned long long>: std::true_type {};
template<std::size_t size, class T> struct IsIntegral<Vector<size, T>>: IsIntegral<T> {};
template<class T> struct IsIntegral<Vector2<T>>: IsIntegral<T> {};
template<class T> struct IsIntegral<Vector3<T>>: IsIntegral<T> {};
template<class T> struct IsIntegral<Vector4<T>>: IsIntegral<T> {};
template<class T> struct IsIntegral<Color3<T>>: IsIntegral<T> {};
template<class T> struct IsIntegral<Color4<T>>: IsIntegral<T> {};
template<class T> struct IsFloatingPoint
: std::false_type
{};
template<> struct IsFloatingPoint<Float>: std::true_type {};
template<> struct IsFloatingPoint<Half>: std::true_type {};
template<> struct IsFloatingPoint<Double>: std::true_type {};
template<> struct IsFloatingPoint<long double>: std::true_type {};
template<std::size_t size, class T> struct IsFloatingPoint<Vector<size, T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Vector2<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Vector3<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Vector4<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Color3<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Color4<T>>: IsFloatingPoint<T> {};
template<template<class> class Derived, class T> struct IsFloatingPoint<Unit<Derived, T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Deg<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Rad<T>>: IsFloatingPoint<T> {};
template<class T> struct IsUnitless
: std::integral_constant<bool, IsScalar<T>::value || IsVector<T>::value>
{};
template<template<class> class Derived, class T> struct IsUnitless<Unit<Derived, T>>: std::false_type {};
template<class T> struct IsUnitless<Deg<T>>: std::false_type {};
template<class T> struct IsUnitless<Rad<T>>: std::false_type {};
namespace Implementation {
template<class T> struct UnderlyingType {
static_assert(IsScalar<T>::value, "type is not scalar");
typedef T Type;
};
template<template<class> class Derived, class T> struct UnderlyingType<Unit<Derived, T>> {
typedef T Type;
};
template<class T> struct UnderlyingType<Deg<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Rad<T>> { typedef T Type; };
template<std::size_t size, class T> struct UnderlyingType<Vector<size, T>> {
typedef T Type;
};
template<class T> struct UnderlyingType<Vector2<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Vector3<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Vector4<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Color3<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Color4<T>> { typedef T Type; };
template<std::size_t cols, std::size_t rows, class T> struct UnderlyingType<RectangularMatrix<cols, rows, T>> {
typedef T Type;
};
template<std::size_t size, class T> struct UnderlyingType<Matrix<size, T>> {
typedef T Type;
};
template<class T> struct UnderlyingType<Matrix3<T>> { typedef T Type; };
template<class T> struct UnderlyingType<Matrix4<T>> { typedef T Type; };
}
template<class T> using UnderlyingTypeOf = typename Implementation::UnderlyingType<T>::Type;
namespace Implementation {
template<class T> struct TypeTraitsDefault {
TypeTraitsDefault() = delete;
constexpr static bool equals(T a, T b) {
return a == b;
}
constexpr static bool equalsZero(T a, T) {
return !a;
}
};
}
template<class T> struct TypeTraits: Implementation::TypeTraitsDefault<T> {
};
template<class T> inline typename std::enable_if<IsScalar<T>::value, bool>::type equal(T a, T b) {
return TypeTraits<T>::equals(a, b);
}
template<class T> inline typename std::enable_if<IsScalar<T>::value, bool>::type notEqual(T a, T b) {
return !TypeTraits<T>::equals(a, b);
}
namespace Implementation {
template<class> struct TypeTraitsName;
#define _c(type) template<> struct TypeTraitsName<type> { \
constexpr static const char* name() { return #type; } \
};
_c(UnsignedByte)
_c(Byte)
_c(UnsignedShort)
_c(Short)
_c(UnsignedInt)
_c(Int)
_c(UnsignedLong)
_c(Long)
_c(Float)
_c(Half)
_c(Double)
_c(long double)
#undef _c
template<class T> struct TypeTraitsIntegral: TypeTraitsDefault<T>, TypeTraitsName<T> {
constexpr static T epsilon() { return T(1); }
};
}
template<> struct TypeTraits<UnsignedByte>: Implementation::TypeTraitsIntegral<UnsignedByte> {
typedef Float FloatingPointType;
};
template<> struct TypeTraits<Byte>: Implementation::TypeTraitsIntegral<Byte> {
typedef Float FloatingPointType;
};
template<> struct TypeTraits<UnsignedShort>: Implementation::TypeTraitsIntegral<UnsignedShort> {
typedef Float FloatingPointType;
};
template<> struct TypeTraits<Short>: Implementation::TypeTraitsIntegral<Short> {
typedef Float FloatingPointType;
};
template<> struct TypeTraits<UnsignedInt>: Implementation::TypeTraitsIntegral<UnsignedInt> {
typedef Double FloatingPointType;
};
template<> struct TypeTraits<Int>: Implementation::TypeTraitsIntegral<Int> {
typedef Double FloatingPointType;
};
template<> struct TypeTraits<UnsignedLong>: Implementation::TypeTraitsIntegral<UnsignedLong> {
typedef long double FloatingPointType;
};
template<> struct TypeTraits<Long>: Implementation::TypeTraitsIntegral<Long> {
typedef long double FloatingPointType;
};
namespace Implementation {
template<class T> struct TypeTraitsFloatingPoint: TypeTraitsName<T> {
TypeTraitsFloatingPoint() = delete;
static bool equals(T a, T b);
static bool equalsZero(T a, T epsilon);
};
template<class T> bool TypeTraitsFloatingPoint<T>::equals(const T a, const T b) {
if(a == b) return true;
const T absA = std::abs(a);
const T absB = std::abs(b);
const T difference = std::abs(a - b);
if(a == T{} || b == T{} || difference < TypeTraits<T>::epsilon())
return difference < TypeTraits<T>::epsilon();
return difference/(absA + absB) < TypeTraits<T>::epsilon();
}
template<class T> bool TypeTraitsFloatingPoint<T>::equalsZero(const T a, const T magnitude) {
if(a == T(0.0)) return true;
const T absA = std::abs(a);
if(absA < TypeTraits<T>::epsilon())
return absA < TypeTraits<T>::epsilon();
return absA*T(0.5)/magnitude < TypeTraits<T>::epsilon();
}
}
template<> struct TypeTraits<Float>: Implementation::TypeTraitsFloatingPoint<Float> {
typedef Float FloatingPointType;
constexpr static Float epsilon() { return 1.0e-5f; }
};
template<> struct TypeTraits<Half>: Implementation::TypeTraitsName<Half>, Implementation::TypeTraitsDefault<Half> {
typedef Half FloatingPointType;
};
template<> struct TypeTraits<Double>: Implementation::TypeTraitsFloatingPoint<Double> {
typedef Double FloatingPointType;
constexpr static Double epsilon() { return 1.0e-14; }
};
template<> struct TypeTraits<long double>: Implementation::TypeTraitsFloatingPoint<long double> {
typedef long double FloatingPointType;
#ifndef CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
constexpr static long double epsilon() { return 1.0e-17l; }
#else
constexpr static long double epsilon() { return 1.0e-14l; }
#endif
};
namespace Implementation {
template<class T> inline bool isNormalizedSquared(T lengthSquared) {
return std::abs(lengthSquared - T(1)) < T(2)*TypeTraits<T>::epsilon();
}
}
}}
#endif
#ifndef Corrade_Tags_h
#define Corrade_Tags_h
namespace Corrade {
struct DefaultInitT {
struct Init {};
constexpr explicit DefaultInitT(Init) {}
};
struct ValueInitT {
struct Init {};
constexpr explicit ValueInitT(Init) {}
};
struct NoInitT {
struct Init {};
constexpr explicit NoInitT(Init) {}
};
struct NoCreateT {
struct Init {};
constexpr explicit NoCreateT(Init) {}
};
struct DirectInitT {
struct Init {};
constexpr explicit DirectInitT(Init) {}
};
struct InPlaceInitT {
struct Init {};
constexpr explicit InPlaceInitT(Init) {}
};
constexpr DefaultInitT DefaultInit{DefaultInitT::Init{}};
constexpr ValueInitT ValueInit{ValueInitT::Init{}};
constexpr NoInitT NoInit{NoInitT::Init{}};
constexpr NoCreateT NoCreate{NoCreateT::Init{}};
constexpr DirectInitT DirectInit{DirectInitT::Init{}};
constexpr InPlaceInitT InPlaceInit{InPlaceInitT::Init{}};
}
#endif
#ifndef Magnum_Tags_h
#define Magnum_Tags_h
namespace Magnum {
using Corrade::DefaultInitT;
using Corrade::NoInitT;
using Corrade::NoCreateT;
struct NoAllocateT {
struct Init {};
constexpr explicit NoAllocateT(Init) {}
};
using Corrade::DefaultInit;
using Corrade::NoInit;
using Corrade::NoCreate;
constexpr NoAllocateT NoAllocate{NoAllocateT::Init{}};
}
#endif
#ifndef Magnum_Math_Tags_h
#define Magnum_Math_Tags_h
namespace Magnum { namespace Math {
struct ZeroInitT {
struct Init{};
constexpr explicit ZeroInitT(Init) {}
};
struct IdentityInitT {
struct Init{};
constexpr explicit IdentityInitT(Init) {}
};
constexpr ZeroInitT ZeroInit{ZeroInitT::Init{}};
constexpr IdentityInitT IdentityInit{IdentityInitT::Init{}};
}}
#endif
#ifndef Magnum_Math_Unit_h
#define Magnum_Math_Unit_h
namespace Magnum { namespace Math {
template<template<class> class Derived, class T> class Unit {
template<template<class> class, class> friend class Unit;
public:
typedef T Type;
constexpr /*implicit*/ Unit() noexcept: _value(T(0)) {}
constexpr explicit Unit(ZeroInitT) noexcept: _value(T(0)) {}
explicit Unit(Magnum::NoInitT) noexcept {}
constexpr explicit Unit(T value) noexcept: _value(value) {}
template<class U> constexpr explicit Unit(Unit<Derived, U> value) noexcept: _value(T(value._value)) {}
constexpr explicit operator T() const { return _value; }
constexpr bool operator==(Unit<Derived, T> other) const {
return TypeTraits<T>::equals(_value, other._value);
}
constexpr bool operator!=(Unit<Derived, T> other) const {
return !operator==(other);
}
constexpr bool operator<(Unit<Derived, T> other) const {
return _value < other._value;
}
constexpr bool operator>(Unit<Derived, T> other) const {
return _value > other._value;
}
constexpr bool operator<=(Unit<Derived, T> other) const {
return !operator>(other);
}
constexpr bool operator>=(Unit<Derived, T> other) const {
return !operator<(other);
}
constexpr Unit<Derived, T> operator+() const { return *this; }
constexpr Unit<Derived, T> operator-() const {
return Unit<Derived, T>(-_value);
}
Unit<Derived, T>& operator+=(Unit<Derived, T> other) {
_value += other._value;
return *this;
}
constexpr Unit<Derived, T> operator+(Unit<Derived, T> other) const {
return Unit<Derived, T>(_value + other._value);
}
Unit<Derived, T>& operator-=(Unit<Derived, T> other) {
_value -= other._value;
return *this;
}
constexpr Unit<Derived, T> operator-(Unit<Derived, T> other) const {
return Unit<Derived, T>(_value - other._value);
}
Unit<Derived, T>& operator*=(T number) {
_value *= number;
return *this;
}
constexpr Unit<Derived, T> operator*(T number) const {
return Unit<Derived, T>(_value*number);
}
Unit<Derived, T>& operator/=(T number) {
_value /= number;
return *this;
}
constexpr Unit<Derived, T> operator/(T number) const {
return Unit<Derived, T>(_value/number);
}
constexpr T operator/(Unit<Derived, T> other) const {
return _value/other._value;
}
private:
T _value;
};
template<template<class> class Derived, class T> constexpr Unit<Derived, T> operator*(typename std::common_type<T>::type number, const Unit<Derived, T>& value) {
return value*number;