mirror of https://github.com/mosra/magnum.git
Browse Source
Technically speaking there are many more opportunities to mark things as C++14 constexpr, such as various operators, but doing so would make them impossible to optimize with various (SIMD) intrisnics unless basically providing two separate implementations for them, one scalar, slow and constexpr and the other fast but not compile time, and dispatching with std::is_constant_evaluated() or some such from C++20. In other words, such functions cannot and will not be marked as constexpr in C++17 or older anyway, because the preference is and still should be runtime perf rather than doing excessive work at compile time, where it's hard to debug or reasonably test etc etc., and the more you rebuild the more you'll hate the cost of extra compile time caused by that. Co-authored-by: Stanislaw Halik <sthalik@misaki.pl>pull/680/head
27 changed files with 967 additions and 61 deletions
@ -0,0 +1,64 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Bezier.h" |
||||
#include "Magnum/Math/Vector2.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct BezierCpp14Test: TestSuite::Tester { |
||||
explicit BezierCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Vector2; |
||||
using Magnum::QuadraticBezier2D; |
||||
|
||||
BezierCpp14Test::BezierCpp14Test() { |
||||
addTests({&BezierCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr QuadraticBezier2D populate() { |
||||
QuadraticBezier2D a; |
||||
a.data()[1] = {3.0f, 2.0f}; |
||||
a[0] = {0.0f, 1.0f}; |
||||
return a; |
||||
}; |
||||
|
||||
void BezierCpp14Test::accessConstexpr() { |
||||
constexpr QuadraticBezier2D a = populate(); |
||||
CORRADE_COMPARE(a[0], (Vector2{0.0f, 1.0f})); |
||||
CORRADE_COMPARE(a[1], (Vector2{3.0f, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::BezierCpp14Test) |
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/BitVector.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct BitVectorCpp14Test: TestSuite::Tester { |
||||
explicit BitVectorCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
typedef Math::BitVector<19> BitVector19; |
||||
|
||||
BitVectorCpp14Test::BitVectorCpp14Test() { |
||||
addTests({&BitVectorCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr BitVector19 populate() { |
||||
BitVector19 a; |
||||
a.data()[2] = 0xee; |
||||
a.data()[0] = 0xc0; |
||||
a.data()[1] = 0xff; |
||||
return a; |
||||
}; |
||||
|
||||
void BitVectorCpp14Test::accessConstexpr() { |
||||
constexpr BitVector19 a = populate(); |
||||
CORRADE_COMPARE(a, (BitVector19{0xc0, 0xff, 0xee})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::BitVectorCpp14Test) |
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Complex.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct ComplexCpp14Test: TestSuite::Tester { |
||||
explicit ComplexCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Complex; |
||||
|
||||
ComplexCpp14Test::ComplexCpp14Test() { |
||||
addTests({&ComplexCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Complex populate() { |
||||
Complex a; |
||||
a.real() = 3.0f; |
||||
a.imaginary() = 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void ComplexCpp14Test::accessConstexpr() { |
||||
constexpr Complex a = populate(); |
||||
CORRADE_COMPARE(a, (Complex{3.0f, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::ComplexCpp14Test) |
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/CubicHermite.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct CubicHermiteCpp14Test: TestSuite::Tester { |
||||
explicit CubicHermiteCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::CubicHermite2D; |
||||
|
||||
CubicHermiteCpp14Test::CubicHermiteCpp14Test() { |
||||
addTests({&CubicHermiteCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr CubicHermite2D populate() { |
||||
CubicHermite2D a; |
||||
a.inTangent() = {1.0f, 2.0f}; |
||||
a.point() = {3.0f, 4.0f}; |
||||
a.outTangent() = {6.0f, 5.0f}; |
||||
return a; |
||||
}; |
||||
|
||||
void CubicHermiteCpp14Test::accessConstexpr() { |
||||
constexpr CubicHermite2D a = populate(); |
||||
CORRADE_COMPARE(a, (CubicHermite2D{{1.0f, 2.0f}, {3.0f, 4.0f}, {6.0f, 5.0f}})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::CubicHermiteCpp14Test) |
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Dual.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct DualCpp14Test: TestSuite::Tester { |
||||
explicit DualCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
typedef Math::Dual<Float> Dual; |
||||
|
||||
DualCpp14Test::DualCpp14Test() { |
||||
addTests({&DualCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Dual populate() { |
||||
Dual a; |
||||
a.real() = 3.0f; |
||||
a.dual() = 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void DualCpp14Test::accessConstexpr() { |
||||
constexpr Dual a = populate(); |
||||
CORRADE_COMPARE(a, (Dual{3.0f, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::DualCpp14Test) |
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Frustum.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct FrustumCpp14Test: TestSuite::Tester { |
||||
explicit FrustumCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Vector4; |
||||
using Magnum::Frustum; |
||||
|
||||
FrustumCpp14Test::FrustumCpp14Test() { |
||||
addTests({&FrustumCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Frustum populate() { |
||||
Frustum a; |
||||
a.left() = {-2.0f, 2.0f, -3.0f, 0.1f}; /* gets 1 added to X */ |
||||
a.right() = { 1.0f, -4.0f, 3.0f, 0.2f}; /* gets Y divided by 2 */ |
||||
a.bottom() = {-4.0f, 5.0f, -6.0f, 0.3f}; |
||||
a.top() = { 4.0f, -5.0f, 3.0f, 0.4f}; /* gets Z multiplied by 2 */ |
||||
a.near() = {-7.0f, 8.0f, -9.0f, 0.5f}; |
||||
a.far() = { 7.0f, 8.0f, 9.0f, 0.6f}; |
||||
a.begin()->x() += 1.0f; |
||||
a[1].y() /= 2.0f; |
||||
(a.end() - 3)->z() *= 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void FrustumCpp14Test::accessConstexpr() { |
||||
constexpr Frustum a = populate(); |
||||
CORRADE_COMPARE(a, (Frustum{ |
||||
{-1.0f, 2.0f, -3.0f, 0.1f}, |
||||
{ 1.0f, -2.0f, 3.0f, 0.2f}, |
||||
{-4.0f, 5.0f, -6.0f, 0.3f}, |
||||
{ 4.0f, -5.0f, 6.0f, 0.4f}, |
||||
{-7.0f, 8.0f, -9.0f, 0.5f}, |
||||
{ 7.0f, 8.0f, 9.0f, 0.6f}})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::FrustumCpp14Test) |
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Quaternion.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct QuaternionCpp14Test: TestSuite::Tester { |
||||
explicit QuaternionCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Quaternion; |
||||
using Magnum::Vector3; |
||||
|
||||
QuaternionCpp14Test::QuaternionCpp14Test() { |
||||
addTests({&QuaternionCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Quaternion populate() { |
||||
Quaternion a; |
||||
a.vector() = {3.0f, 1.0f, 0.0f}; |
||||
a.scalar() = 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void QuaternionCpp14Test::accessConstexpr() { |
||||
constexpr Quaternion a = populate(); |
||||
CORRADE_COMPARE(a, (Quaternion{{3.0f, 1.0f, 0.0f}, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::QuaternionCpp14Test) |
||||
@ -0,0 +1,102 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Range.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct RangeCpp14Test: TestSuite::Tester { |
||||
explicit RangeCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
/* Range1D doesn't have any dedicated getters on top of the generic base */ |
||||
void accessConstexpr2D(); |
||||
void accessConstexpr3D(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Range1D; |
||||
using Magnum::Range2D; |
||||
using Magnum::Range3D; |
||||
|
||||
RangeCpp14Test::RangeCpp14Test() { |
||||
addTests({&RangeCpp14Test::accessConstexpr, |
||||
&RangeCpp14Test::accessConstexpr2D, |
||||
&RangeCpp14Test::accessConstexpr3D}); |
||||
} |
||||
|
||||
constexpr Range2D populate() { |
||||
Range2D a; |
||||
a.min() = {1.0f, 0.0f}; |
||||
a.max() = {2.0f, 3.0f}; |
||||
return a; |
||||
}; |
||||
|
||||
void RangeCpp14Test::accessConstexpr() { |
||||
constexpr Range2D a = populate(); |
||||
CORRADE_COMPARE(a, (Range2D{{1.0f, 0.0f}, {2.0f, 3.0f}})); |
||||
} |
||||
|
||||
constexpr Range2D populate2D() { |
||||
Range2D a; |
||||
a.bottomLeft() = {0.0f, -2.0f}; |
||||
a.topRight() = {4.0f, 1.5f}; |
||||
a.bottom() += 2.0f; |
||||
a.left() += 1.0f; |
||||
a.top() *= 2.0f; |
||||
a.right() /= 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void RangeCpp14Test::accessConstexpr2D() { |
||||
constexpr Range2D a = populate2D(); |
||||
CORRADE_COMPARE(a, (Range2D{{1.0f, 0.0f}, {2.0f, 3.0f}})); |
||||
} |
||||
|
||||
constexpr Range3D populate3D() { |
||||
Range3D a; |
||||
a.backBottomLeft() = {0.0f, -2.0f, 5.0f}; |
||||
a.frontTopRight() = {4.0f, 1.5f, 4.5f}; |
||||
a.bottom() += 2.0f; |
||||
a.left() += 1.0f; |
||||
a.top() *= 2.0f; |
||||
a.right() /= 2.0f; |
||||
a.back() -= 1.0f; |
||||
a.front() += 0.5f; |
||||
return a; |
||||
}; |
||||
|
||||
void RangeCpp14Test::accessConstexpr3D() { |
||||
constexpr Range3D a = populate3D(); |
||||
CORRADE_COMPARE(a, (Range3D{{1.0f, 0.0f, 4.0f}, {2.0f, 3.0f, 5.0f}})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::RangeCpp14Test) |
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/RectangularMatrix.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct RectangularMatrixCpp14Test: TestSuite::Tester { |
||||
explicit RectangularMatrixCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
typedef RectangularMatrix<2, 2, Float> Matrix2x2; |
||||
typedef Vector<2, Float> Vector2; |
||||
|
||||
RectangularMatrixCpp14Test::RectangularMatrixCpp14Test() { |
||||
addTests({&RectangularMatrixCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Matrix2x2 populate() { |
||||
Matrix2x2 a; |
||||
a[0] = {3.0f, 2.0f}; |
||||
a[1] = {0.0f, 1.0f}; |
||||
return a; |
||||
}; |
||||
|
||||
void RectangularMatrixCpp14Test::accessConstexpr() { |
||||
constexpr Matrix2x2 a = populate(); |
||||
CORRADE_COMPARE(a, (Matrix2x2{{{3.0f, 2.0f}, {0.0f, 1.0f}}})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::RectangularMatrixCpp14Test) |
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Vector2.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct Vector2Cpp14Test: TestSuite::Tester { |
||||
explicit Vector2Cpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Vector2; |
||||
|
||||
Vector2Cpp14Test::Vector2Cpp14Test() { |
||||
addTests({&Vector2Cpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Vector2 populate() { |
||||
Vector2 a; |
||||
a.x() = 6.0f; |
||||
a.y() = 3.0f; |
||||
a.r() *= 0.5f; |
||||
a.g() -= 1.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void Vector2Cpp14Test::accessConstexpr() { |
||||
constexpr Vector2 a = populate(); |
||||
CORRADE_COMPARE(a, (Vector2{3.0f, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::Vector2Cpp14Test) |
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Vector3.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct Vector3Cpp14Test: TestSuite::Tester { |
||||
explicit Vector3Cpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Vector3; |
||||
|
||||
Vector3Cpp14Test::Vector3Cpp14Test() { |
||||
addTests({&Vector3Cpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Vector3 populate() { |
||||
Vector3 a; |
||||
a.x() = 6.0f; |
||||
a.y() = 3.0f; |
||||
a.z() = 2.0f; |
||||
a.r() *= 0.5f; |
||||
a.g() -= 1.0f; |
||||
a.b() /= 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void Vector3Cpp14Test::accessConstexpr() { |
||||
constexpr Vector3 a = populate(); |
||||
CORRADE_COMPARE(a, (Vector3{3.0f, 2.0f, 1.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Cpp14Test) |
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Vector4.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct Vector4Cpp14Test: TestSuite::Tester { |
||||
explicit Vector4Cpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
using Magnum::Vector4; |
||||
|
||||
Vector4Cpp14Test::Vector4Cpp14Test() { |
||||
addTests({&Vector4Cpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Vector4 populate() { |
||||
Vector4 a; |
||||
a.x() = 6.0f; |
||||
a.y() = 3.0f; |
||||
a.z() = -1.0f; |
||||
a.w() = 2.0f; |
||||
a.r() *= 0.5f; |
||||
a.g() -= 1.0f; |
||||
a.b() += 1.0f; |
||||
a.a() /= 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void Vector4Cpp14Test::accessConstexpr() { |
||||
constexpr Vector4 a = populate(); |
||||
CORRADE_COMPARE(a, (Vector4{3.0f, 2.0f, 0.0f, 1.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::Vector4Cpp14Test) |
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022, 2023, 2024, 2025 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/TestSuite/Tester.h> |
||||
|
||||
#include "Magnum/Math/Vector.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { namespace { |
||||
|
||||
struct VectorCpp14Test: TestSuite::Tester { |
||||
explicit VectorCpp14Test(); |
||||
|
||||
void accessConstexpr(); |
||||
}; |
||||
|
||||
/* What's a typedef and not a using differs from the typedefs in root Magnum
|
||||
namespace, or is not present there at all */ |
||||
typedef Vector<2, Float> Vector2; |
||||
|
||||
VectorCpp14Test::VectorCpp14Test() { |
||||
addTests({&VectorCpp14Test::accessConstexpr}); |
||||
} |
||||
|
||||
constexpr Vector2 populate() { |
||||
Vector2 a; |
||||
a[0] = 3.0f; |
||||
a.data()[1] = 2.0f; |
||||
return a; |
||||
}; |
||||
|
||||
void VectorCpp14Test::accessConstexpr() { |
||||
constexpr Vector2 a = populate(); |
||||
CORRADE_COMPARE(a, (Vector2{3.0f, 2.0f})); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::VectorCpp14Test) |
||||
Loading…
Reference in new issue