Browse Source

Math: matrix/vector rework, part 3: conversion as explicit constructor.

Also updated all dependent classes to follow the change, such as Color
and Rectangle. Backwards compatibility for GCC 4.6 (with lack of support
for delegating constructors) will be done as non-constexpr constructor
using operator=().
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
5819dd4bd7
  1. 4
      doc/matrix-vector.dox
  2. 6
      src/Color.h
  3. 6
      src/Math/Functions.h
  4. 37
      src/Math/Geometry/Rectangle.h
  5. 3
      src/Math/Geometry/Test/RectangleTest.cpp
  6. 3
      src/Math/Matrix.h
  7. 3
      src/Math/Matrix3.h
  8. 3
      src/Math/Matrix4.h
  9. 3
      src/Math/Point2D.h
  10. 3
      src/Math/Point3D.h
  11. 37
      src/Math/RectangularMatrix.h
  12. 4
      src/Math/Test/RectangularMatrixTest.cpp
  13. 4
      src/Math/Test/VectorTest.cpp
  14. 37
      src/Math/Vector.h
  15. 3
      src/Math/Vector2.h
  16. 3
      src/Math/Vector3.h
  17. 3
      src/Math/Vector4.h
  18. 2
      src/SceneGraph/AbstractCamera.hpp
  19. 6
      src/Text/Font.cpp

4
doc/matrix-vector.dox

@ -99,10 +99,10 @@ RectangularMatrix<2, 3, int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 }
Note that unlike constructors, this function has no way to check whether the Note that unlike constructors, this function has no way to check whether the
array is long enough to contain all elements, so use with caution. array is long enough to contain all elements, so use with caution.
You can also convert between data types: You can also *explicitly* convert between data types:
@code @code
Vector4<float> floating(1.3f, 2.7f, -15.0f, 7.0f); Vector4<float> floating(1.3f, 2.7f, -15.0f, 7.0f);
Vector4<int> integral(Vector4<int>::from(floating)); // {1, 2, -15, 7} Vector4<int> integral(floating); // {1, 2, -15, 7}
@endcode @endcode
@section matrix-vector-component-access Accessing matrix and vector components @section matrix-vector-component-access Accessing matrix and vector components

6
src/Color.h

@ -195,6 +195,9 @@ class Color3: public Math::Vector3<T> {
*/ */
inline constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3<T>(r, g, b) {} inline constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3<T>(r, g, b) {}
/** @copydoc Math::Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Color3(const Math::Vector<3, U>& other): Math::Vector3<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3<T>(other) {} inline constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3<T>(other) {}
@ -322,6 +325,9 @@ class Color4: public Math::Vector4<T> {
is fairly common, nearly always with A set to 1 */ is fairly common, nearly always with A set to 1 */
inline constexpr /*implicit*/ Color4(const Math::Vector3<T>& rgb, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {} inline constexpr /*implicit*/ Color4(const Math::Vector3<T>& rgb, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
/** @copydoc Math::Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Color4(const Math::Vector<4, U>& other): Math::Vector4<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4<T>(other) {} inline constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4<T>(other) {}

6
src/Math/Functions.h

@ -177,12 +177,12 @@ template<class FloatingPoint, class Integral> inline typename std::enable_if<std
template<class FloatingPoint, class Integral> inline typename std::enable_if<std::is_unsigned<typename Integral::Type>::value, FloatingPoint>::type normalize(const Integral& value) { template<class FloatingPoint, class Integral> inline typename std::enable_if<std::is_unsigned<typename Integral::Type>::value, FloatingPoint>::type normalize(const Integral& value) {
static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value, static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value,
"Math::normalize(): normalization must be done from integral to floating-point type"); "Math::normalize(): normalization must be done from integral to floating-point type");
return FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits<typename Integral::Type>::max()); return FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits<typename Integral::Type>::max());
} }
template<class FloatingPoint, class Integral> inline typename std::enable_if<std::is_signed<typename Integral::Type>::value, FloatingPoint>::type normalize(const Integral& value) { template<class FloatingPoint, class Integral> inline typename std::enable_if<std::is_signed<typename Integral::Type>::value, FloatingPoint>::type normalize(const Integral& value) {
static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value, static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value,
"Math::normalize(): normalization must be done from integral to floating-point type"); "Math::normalize(): normalization must be done from integral to floating-point type");
return Math::max(FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits<typename Integral::Type>::max()), FloatingPoint(-1)); return Math::max(FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits<typename Integral::Type>::max()), FloatingPoint(-1));
} }
#endif #endif
@ -213,7 +213,7 @@ template<class Integral, class FloatingPoint> inline typename std::enable_if<std
template<class Integral, class FloatingPoint> inline typename std::enable_if<std::is_arithmetic<typename Integral::Type>::value, Integral>::type denormalize(const FloatingPoint& value) { template<class Integral, class FloatingPoint> inline typename std::enable_if<std::is_arithmetic<typename Integral::Type>::value, Integral>::type denormalize(const FloatingPoint& value) {
static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value, static_assert(std::is_floating_point<typename FloatingPoint::Type>::value && std::is_integral<typename Integral::Type>::value,
"Math::denormalize(): denormalization must be done from floating-point to integral type"); "Math::denormalize(): denormalization must be done from floating-point to integral type");
return Integral::from(value*std::numeric_limits<typename Integral::Type>::max()); return Integral(value*std::numeric_limits<typename Integral::Type>::max());
} }
#endif #endif

37
src/Math/Geometry/Rectangle.h

@ -32,6 +32,8 @@ are inclusive, while top/right positions are exclusive.
@see Magnum::Rectangle, Magnum::Rectanglei @see Magnum::Rectangle, Magnum::Rectanglei
*/ */
template<class T> class Rectangle { template<class T> class Rectangle {
template<class> friend class Rectangle;
public: public:
/** /**
* Create rectangle from position and size * Create rectangle from position and size
@ -43,33 +45,32 @@ template<class T> class Rectangle {
} }
/** /**
* @brief %Rectangle from another of different type * @brief Construct zero rectangle
*
* Construct zero-area rectangle positioned at origin.
*/
inline constexpr Rectangle() = default;
/** @brief Construct rectangle from two corners */
inline constexpr Rectangle(const Vector2<T>& bottomLeft, const Vector2<T>& topRight): _bottomLeft(bottomLeft), _topRight(topRight) {}
/**
* @brief Construct rectangle from another of different type
* *
* Performs only default casting on the values, no rounding or * Performs only default casting on the values, no rounding or
* anything else. Example usage: * anything else. Example usage:
* @code * @code
* Rectangle<float> floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f}); * Rectangle<float> floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f});
* auto integral = Rectangle<std::int8_t>::from(floatingPoint); * Rectangle<std::int8_t> integral(floatingPoint); // {{1, 2}, {-15, 7}}
* // integral == {{1, 2}, {-15, 7}}
* @endcode * @endcode
*/ */
template<class U> inline constexpr static Rectangle<T> from(const Rectangle<U>& other) { template<class U> inline constexpr explicit Rectangle(const Rectangle<U>& other): _bottomLeft(other._bottomLeft), _topRight(other._topRight) {}
return {Vector2<T>::from(other.bottomLeft()), Vector2<T>::from(other.topRight())};
}
/** /** @brief Copy constructor */
* @brief Default constructor inline constexpr Rectangle(const Rectangle<T>&) = default;
*
* Construct zero-area rectangle positioned at origin.
*/
inline constexpr Rectangle() = default;
/** /** @brief Assignment operator */
* @brief Constructor inline Rectangle<T>& operator=(const Rectangle<T>&) = default;
* @param bottomLeft Bottom left rectangle corner
* @param topRight Top right rectangle corner
*/
inline constexpr Rectangle(const Vector2<T>& bottomLeft, const Vector2<T>& topRight): _bottomLeft(bottomLeft), _topRight(topRight) {}
/** @brief Equality operator */ /** @brief Equality operator */
inline constexpr bool operator==(const Rectangle<T>& other) const { inline constexpr bool operator==(const Rectangle<T>& other) const {

3
src/Math/Geometry/Test/RectangleTest.cpp

@ -74,8 +74,7 @@ void RectangleTest::compare() {
void RectangleTest::construct() { void RectangleTest::construct() {
CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0})); CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0}));
CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83})); CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83}));
CORRADE_COMPARE(Rectanglei::from(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})), CORRADE_COMPARE(Rectanglei(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})), Rectanglei({1, 2}, {-15, 7}));
Rectanglei({1, 2}, {-15, 7}));
} }
void RectangleTest::size() { void RectangleTest::size() {

3
src/Math/Matrix.h

@ -74,6 +74,9 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
*/ */
template<class ...U> inline constexpr /*implicit*/ Matrix(const Vector<size, T>& first, const U&... next): RectangularMatrix<size, size, T>(first, next...) {} template<class ...U> inline constexpr /*implicit*/ Matrix(const Vector<size, T>& first, const U&... next): RectangularMatrix<size, size, T>(first, next...) {}
/** @copydoc RectangularMatrix::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
template<class U> inline constexpr explicit Matrix(const RectangularMatrix<size, size, U>& other): RectangularMatrix<size, size, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Matrix(const RectangularMatrix<size, size, T>& other): RectangularMatrix<size, size, T>(other) {} inline constexpr Matrix(const RectangularMatrix<size, size, T>& other): RectangularMatrix<size, size, T>(other) {}

3
src/Math/Matrix3.h

@ -128,6 +128,9 @@ template<class T> class Matrix3: public Matrix<3, T> {
/** @brief %Matrix from column vectors */ /** @brief %Matrix from column vectors */
inline constexpr /*implicit*/ Matrix3(const Vector3<T>& first, const Vector3<T>& second, const Vector3<T>& third): Matrix<3, T>(first, second, third) {} inline constexpr /*implicit*/ Matrix3(const Vector3<T>& first, const Vector3<T>& second, const Vector3<T>& third): Matrix<3, T>(first, second, third) {}
/** @copydoc Matrix::Matrix(const RectangularMatrix<cols, rows, U>&) */
template<class U> inline constexpr explicit Matrix3(const RectangularMatrix<3, 3, U>& other): Matrix<3, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {}

3
src/Math/Matrix4.h

@ -253,6 +253,9 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** @brief %Matrix from column vectors */ /** @brief %Matrix from column vectors */
inline constexpr /*implicit*/ Matrix4(const Vector4<T>& first, const Vector4<T>& second, const Vector4<T>& third, const Vector4<T>& fourth): Matrix<4, T>(first, second, third, fourth) {} inline constexpr /*implicit*/ Matrix4(const Vector4<T>& first, const Vector4<T>& second, const Vector4<T>& third, const Vector4<T>& fourth): Matrix<4, T>(first, second, third, fourth) {}
/** @copydoc Matrix::Matrix(const RectangularMatrix<cols, rows, U>&) */
template<class U> inline constexpr explicit Matrix4(const RectangularMatrix<4, 4, U>& other): Matrix<4, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {}

3
src/Math/Point2D.h

@ -56,6 +56,9 @@ template<class T> class Point2D: public Vector3<T> {
*/ */
inline constexpr /*implicit*/ Point2D(const Vector2<T>& xy, T z = T(1)): Vector3<T>(xy, z) {} inline constexpr /*implicit*/ Point2D(const Vector2<T>& xy, T z = T(1)): Vector3<T>(xy, z) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Point2D(const Vector<3, U>& other): Vector3<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Point2D(const Vector<3, T>& other): Vector3<T>(other) {} inline constexpr Point2D(const Vector<3, T>& other): Vector3<T>(other) {}

3
src/Math/Point3D.h

@ -57,6 +57,9 @@ template<class T> class Point3D: public Vector4<T> {
*/ */
inline constexpr /*implicit*/ Point3D(const Vector3<T>& xyz, T w = T(1)): Vector4<T>(xyz, w) {} inline constexpr /*implicit*/ Point3D(const Vector3<T>& xyz, T w = T(1)): Vector4<T>(xyz, w) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Point3D(const Vector<4, U>& other): Vector4<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Point3D(const Vector<4, T>& other): Vector4<T>(other) {} inline constexpr Point3D(const Vector<4, T>& other): Vector4<T>(other) {}

37
src/Math/RectangularMatrix.h

@ -62,21 +62,6 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
return *reinterpret_cast<const RectangularMatrix<cols, rows, T>*>(data); return *reinterpret_cast<const RectangularMatrix<cols, rows, T>*>(data);
} }
/**
* @brief %Matrix from another of different type
*
* Performs only default casting on the values, no rounding or
* anything else. Example usage:
* @code
* RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
* RectangularMatrix<4, 1, std::int8_t> integral(RectangularMatrix<4, 1, std::int8_t>::from(floatingPoint));
* // integral == {1, 2, -15, 7}
* @endcode
*/
template<class U> inline constexpr static RectangularMatrix<cols, rows, T> from(const RectangularMatrix<cols, rows, U>& other) {
return from(typename Implementation::GenerateSequence<cols>::Type(), other);
}
/** @brief Construct zero-filled matrix */ /** @brief Construct zero-filled matrix */
inline constexpr /*implicit*/ RectangularMatrix() {} inline constexpr /*implicit*/ RectangularMatrix() {}
@ -91,6 +76,19 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to RectangularMatrix constructor"); static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to RectangularMatrix constructor");
} }
/**
* @brief Construct matrix from another of different type
*
* Performs only default casting on the values, no rounding or
* anything else. Example usage:
* @code
* RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
* RectangularMatrix<4, 1, std::int8_t> integral(floatingPoint);
* // integral == {1, 2, -15, 7}
* @endcode
*/
template<class U> inline constexpr explicit RectangularMatrix(const RectangularMatrix<cols, rows, U>& other): RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr RectangularMatrix(const RectangularMatrix<cols, rows, T>&) = default; inline constexpr RectangularMatrix(const RectangularMatrix<cols, rows, T>&) = default;
@ -310,10 +308,8 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
} }
private: private:
/* Implementation for RectangularMatrix<cols, rows, T>::from(const RectangularMatrix<cols, rows, U>&) */ /* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
template<class U, std::size_t c, std::size_t ...sequence> inline constexpr static Math::RectangularMatrix<c, sizeof...(sequence), T> from(Implementation::Sequence<sequence...>, const Math::RectangularMatrix<c, sizeof...(sequence), U>& matrix) { template<class U, std::size_t ...sequence> inline constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix): _data{Vector<rows, T>(matrix[sequence])...} {}
return {Vector<sizeof...(sequence), T>::from(matrix[sequence])...};
}
Vector<rows, T> _data[cols]; Vector<rows, T> _data[cols];
}; };
@ -414,9 +410,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit
} \ } \
inline constexpr static const __VA_ARGS__& from(const T* data) { \ inline constexpr static const __VA_ARGS__& from(const T* data) { \
return *reinterpret_cast<const __VA_ARGS__*>(data); \ return *reinterpret_cast<const __VA_ARGS__*>(data); \
} \
template<class U> inline constexpr static RectangularMatrix<cols, rows, T> from(const Math::RectangularMatrix<cols, rows, U>& other) { \
return Math::RectangularMatrix<cols, rows, T>::from(other); \
} \ } \
\ \
inline __VA_ARGS__& operator=(const Math::RectangularMatrix<cols, rows, T>& other) { \ inline __VA_ARGS__& operator=(const Math::RectangularMatrix<cols, rows, T>& other) { \

4
src/Math/Test/RectangularMatrixTest.cpp

@ -108,8 +108,8 @@ void RectangularMatrixTest::constructConversion() {
Matrix2i integral(Vector2i( 1, 2), Matrix2i integral(Vector2i( 1, 2),
Vector2i(-15, 7)); Vector2i(-15, 7));
CORRADE_COMPARE(Matrix2i::from(floatingPoint), integral); CORRADE_COMPARE(Matrix2i(floatingPoint), integral);
CORRADE_COMPARE(Matrix2::from(integral), floatingPointRounded); CORRADE_COMPARE(Matrix2(integral), floatingPointRounded);
} }
void RectangularMatrixTest::constructFromVectors() { void RectangularMatrixTest::constructFromVectors() {

4
src/Math/Test/VectorTest.cpp

@ -109,8 +109,8 @@ void VectorTest::constructConversion() {
Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f);
Vector4i integral(1, 2, -15, 7); Vector4i integral(1, 2, -15, 7);
CORRADE_COMPARE(Vector4i::from(floatingPoint), integral); CORRADE_COMPARE(Vector4i(floatingPoint), integral);
CORRADE_COMPARE(Vector4::from(integral), floatingPointRounded); CORRADE_COMPARE(Vector4(integral), floatingPointRounded);
} }
void VectorTest::data() { void VectorTest::data() {

37
src/Math/Vector.h

@ -78,21 +78,6 @@ template<std::size_t size, class T> class Vector {
return *reinterpret_cast<const Vector<size, T>*>(data); return *reinterpret_cast<const Vector<size, T>*>(data);
} }
/**
* @brief %Vector from another of different type
*
* Performs only default casting on the values, no rounding or
* anything else. Example usage:
* @code
* Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
* Vector<4, std::int8_t> integral(Vector<4, std::int8_t>::from(floatingPoint));
* // integral == {1, 2, -15, 7}
* @endcode
*/
template<class U> inline constexpr static Vector<size, T> from(const Vector<size, U>& other) {
return from(typename Implementation::GenerateSequence<size>::Type(), other);
}
/** /**
* @brief Dot product * @brief Dot product
* *
@ -163,6 +148,19 @@ template<std::size_t size, class T> class Vector {
_data[i] = value; _data[i] = value;
} }
/**
* @brief Construct vector from another of different type
*
* Performs only default casting on the values, no rounding or
* anything else. Example usage:
* @code
* Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
* Vector<4, std::int8_t> integral(floatingPoint);
* // integral == {1, 2, -15, 7}
* @endcode
*/
template<class U> inline constexpr explicit Vector(const Vector<size, U>& other): Vector(typename Implementation::GenerateSequence<size>::Type(), other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Vector(const Vector<size, T>&) = default; inline constexpr Vector(const Vector<size, T>&) = default;
@ -500,10 +498,8 @@ template<std::size_t size, class T> class Vector {
} }
private: private:
/* Implementation for from(const Vector<size, U>&) */ /* Implementation for Vector<size, T>::Vector(const Vector<size, U>&) */
template<class U, std::size_t ...sequence> inline constexpr static Vector<sizeof...(sequence), T> from(Implementation::Sequence<sequence...>, const Vector<sizeof...(sequence), U>& vector) { template<class U, std::size_t ...sequence> inline constexpr explicit Vector(Implementation::Sequence<sequence...>, const Vector<sizeof...(sequence), U>& vector): _data{T(vector.data()[sequence])...} {}
return {T(vector.data()[sequence])...};
}
T _data[size]; T _data[size];
}; };
@ -581,9 +577,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit
inline constexpr static const Type<T>& from(const T* data) { \ inline constexpr static const Type<T>& from(const T* data) { \
return *reinterpret_cast<const Type<T>*>(data); \ return *reinterpret_cast<const Type<T>*>(data); \
} \ } \
template<class U> inline constexpr static Type<T> from(const Math::Vector<size, U>& other) { \
return Math::Vector<size, T>::from(other); \
} \
template<class U> inline static const Type<T> lerp(const Math::Vector<size, T>& a, const Math::Vector<size, T>& b, U t) { \ template<class U> inline static const Type<T> lerp(const Math::Vector<size, T>& a, const Math::Vector<size, T>& b, U t) { \
return Math::Vector<size, T>::lerp(a, b, t); \ return Math::Vector<size, T>::lerp(a, b, t); \
} \ } \

3
src/Math/Vector2.h

@ -84,6 +84,9 @@ template<class T> class Vector2: public Vector<2, T> {
*/ */
inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Vector2(const Vector<2, U>& other): Vector<2, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {} inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {}

3
src/Math/Vector3.h

@ -125,6 +125,9 @@ template<class T> class Vector3: public Vector<3, T> {
*/ */
inline constexpr /*implicit*/ Vector3(const Vector2<T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} inline constexpr /*implicit*/ Vector3(const Vector2<T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Vector3(const Vector<3, U>& other): Vector<3, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {} inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {}

3
src/Math/Vector4.h

@ -56,6 +56,9 @@ template<class T> class Vector4: public Vector<4, T> {
*/ */
inline constexpr /*implicit*/ Vector4(const Vector3<T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} inline constexpr /*implicit*/ Vector4(const Vector3<T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {}
/** @copydoc Vector::Vector(const Vector<size, U>&) */
template<class U> inline constexpr explicit Vector4(const Vector<4, U>& other): Vector<4, T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {} inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {}

2
src/SceneGraph/AbstractCamera.hpp

@ -50,7 +50,7 @@ template<std::uint8_t dimensions, class T> typename DimensionTraits<dimensions,
if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved) if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
return {}; return {};
Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>::from(viewport)*projectionScale; Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;
/* Extend on larger side = scale larger side down /* Extend on larger side = scale larger side down
Clip on smaller side = scale smaller side up */ Clip on smaller side = scale smaller side up */

6
src/Text/Font.cpp

@ -80,9 +80,9 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co
/* Save character texture position and texture coordinates for given character index */ /* Save character texture position and texture coordinates for given character index */
glyphs.insert({charIndices[i], std::make_tuple( glyphs.insert({charIndices[i], std::make_tuple(
Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size, Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size,
Vector2::from(charPositions[i].size())/size), Vector2(charPositions[i].size())/size),
Rectangle(Vector2::from(charPositions[i].bottomLeft())/atlasSize, Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize,
Vector2::from(charPositions[i].topRight())/atlasSize) Vector2(charPositions[i].topRight())/atlasSize)
)}); )});
} }

Loading…
Cancel
Save