Browse Source

Math: removed Point2D/Point3D altogether.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
58d156bc47
  1. 11
      doc/matrix-vector.dox
  2. 6
      src/Magnum.h
  3. 2
      src/Math/CMakeLists.txt
  4. 3
      src/Math/Math.h
  5. 10
      src/Math/Matrix3.h
  6. 10
      src/Math/Matrix4.h
  7. 105
      src/Math/Point2D.h
  8. 105
      src/Math/Point3D.h
  9. 2
      src/Math/Test/CMakeLists.txt
  10. 1
      src/Math/Test/Matrix3Test.cpp
  11. 1
      src/Math/Test/Matrix4Test.cpp
  12. 66
      src/Math/Test/Point2DTest.cpp
  13. 66
      src/Math/Test/Point3DTest.cpp
  14. 3
      src/Math/Vector3.h
  15. 3
      src/Math/Vector4.h

11
doc/matrix-vector.dox

@ -26,16 +26,14 @@ return the most specialized type known to make subsequent operations more
convenient - columns of %RectangularMatrix are returned as %Vector, but when
accessing columns of e.g. %Matrix3, they are returned as %Vector3.
There are also even more specialized subclasses - Point2D, Point3D for
creating points with homogeneous coordinates and Color3, Color4 for color
handling and conversion.
There are also even more specialized subclasses, e.g. Color3 and Color4 for
color handling and conversion.
@section matrix-vector-construction Constructing matrices and vectors
Default constructors of RectangularMatrix and Vector (and Vector2, Vector3,
Vector4, Color3) create zero-filled objects. Matrix (and Matrix3, Matrix4) is
by default constructed as identity matrix. Point2D and Point3D have
homogeneous component set to one, Color4 has alpha value set to opaque.
by default constructed as identity matrix. Color4 has alpha value set to opaque.
@code
RectangularMatrix<2, 3, int> a; // zero-filled
Vector<3, int> b; // zero-filled
@ -43,9 +41,6 @@ Vector<3, int> b; // zero-filled
Matrix<3, int> identity; // diagonal set to 1
Matrix<3, int> zero(Matrix<3, int>::Zero); // zero-filled
Point2D<int> c; // {0, 0, 1}
Point3D<int> d; // {0, 0, 0, 1}
Color4<float> black1; // {0.0f, 0.0f, 0.0f, 1.0f}
Color4<unsigned char> black2; // {0, 0, 0, 255}
@endcode

6
src/Magnum.h

@ -103,12 +103,6 @@ typedef Math::Vector3<GLdouble> Vector3d;
typedef Math::Vector4<GLdouble> Vector4d;
#endif
/** @brief Two-dimensional floating-point homogeneous coordinates */
typedef Math::Point2D<GLfloat> Point2D;
/** @brief Three-dimensional floating-point homogeneous coordinates */
typedef Math::Point3D<GLfloat> Point3D;
/** @brief 3x3 float matrix */
typedef Math::Matrix3<GLfloat> Matrix3;

2
src/Math/CMakeLists.txt

@ -11,8 +11,6 @@ set(MagnumMath_HEADERS
Matrix.h
Matrix3.h
Matrix4.h
Point2D.h
Point3D.h
Quaternion.h
RectangularMatrix.h
Swizzle.h

3
src/Math/Math.h

@ -34,9 +34,6 @@ template<std::size_t, class> class Matrix;
template<class> class Matrix3;
template<class> class Matrix4;
template<class> class Point2D;
template<class> class Point3D;
template<class> class Quaternion;
template<std::size_t, std::size_t, class> class RectangularMatrix;

10
src/Math/Matrix3.h

@ -19,8 +19,8 @@
* @brief Class Magnum::Math::Matrix3
*/
#include "Matrix.h"
#include "Point2D.h"
#include "Math/Matrix.h"
#include "Math/Vector3.h"
namespace Magnum { namespace Math {
@ -226,12 +226,6 @@ template<class T> class Matrix3: public Matrix<3, T> {
return ((*this)*Vector3<T>(vector, T(1))).xy();
}
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Point2D<T> operator*(const Point2D<T>& other) const {
return Matrix<3, T>::operator*(other);
}
#endif
MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(3, 3, Matrix3<T>)
MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3)
};

10
src/Math/Matrix4.h

@ -19,8 +19,8 @@
* @brief Class Magnum::Math::Matrix4
*/
#include "Matrix.h"
#include "Point3D.h"
#include "Math/Matrix.h"
#include "Math/Vector4.h"
#ifdef _WIN32 /* I so HATE windows.h */
#undef near
@ -375,12 +375,6 @@ template<class T> class Matrix4: public Matrix<4, T> {
return ((*this)*Vector4<T>(vector, T(1))).xyz();
}
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Point3D<T> operator*(const Point3D<T>& other) const {
return Matrix<4, T>::operator*(other);
}
#endif
MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(4, 4, Matrix4<T>)
MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4)
};

105
src/Math/Point2D.h

@ -1,105 +0,0 @@
#ifndef Magnum_Math_Point2D_h
#define Magnum_Math_Point2D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Math::Point2D
*/
#include "Vector3.h"
namespace Magnum { namespace Math {
/**
@brief Two-dimensional homogeneous coordinates
@tparam T Data type
Same as Vector3, except that constructors have default value for Z component
set to one. See also @ref matrix-vector for brief introduction.
@see Magnum::Point2D, Point3D
@configurationvalueref{Magnum::Math::Point2D}
*/
template<class T> class Point2D: public Vector3<T> {
public:
/**
* @brief Default constructor
*
* @f[
* \boldsymbol p = (0, 0, 1)^T
* @f]
*/
inline constexpr /*implicit*/ Point2D(): Vector3<T>(T(0), T(0), T(1)) {}
/**
* @brief Constructor
*
* @f[
* \boldsymbol p = (x, y, z)^T
* @f]
*/
inline constexpr /*implicit*/ Point2D(T x, T y, T z = T(1)): Vector3<T>(x, y, z) {}
/**
* @brief Constructor
*
* @f[
* \boldsymbol p = (v_x, v_y, z)^T
* @f]
*/
inline constexpr /*implicit*/ Point2D(const Vector2<T>& xy, T z): Vector3<T>(xy, z) {}
/**
* @brief Construct 2D point from 2D vector
*
* @f[
* \boldsymbol p = (v_x, v_y, 1)^T
* @f]
*/
inline constexpr explicit Point2D(const Vector2<T>& xy): Vector3<T>(xy, T(1)) {}
/** @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 */
inline constexpr Point2D(const Vector<3, T>& other): Vector3<T>(other) {}
/**
* @brief Vector part of the point
*
* Equivalent to calling xy(). Useful for seamless 2D/3D integration.
* @see Point3D::vector()
*/
inline Vector2<T>& vector() { return Vector3<T>::xy(); }
inline constexpr Vector2<T> vector() const { return Vector3<T>::xy(); } /**< @overload */
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3)
};
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3)
/** @debugoperator{Magnum::Math::Point2D} */
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point2D<T>& value) {
return debug << static_cast<const Vector<3, T>&>(value);
}
}}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Point2D} */
template<class T> struct ConfigurationValue<Magnum::Math::Point2D<T>>: public ConfigurationValue<Magnum::Math::Vector<3, T>> {};
}}
#endif

105
src/Math/Point3D.h

@ -1,105 +0,0 @@
#ifndef Magnum_Math_Point3D_h
#define Magnum_Math_Point3D_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Math::Point3D
*/
#include "Vector4.h"
namespace Magnum { namespace Math {
/**
@brief Three-dimensional homogeneous coordinates
@tparam T Data type
Same as Vector4, except that constructors have default value for W component
set to one. See also @ref matrix-vector for brief introduction.
@see Magnum::Point3D, Point2D
@configurationvalueref{Magnum::Math::Point3D}
*/
template<class T> class Point3D: public Vector4<T> {
public:
/**
* @brief Default constructor
*
* @f[
* \boldsymbol p = (0, 0, 0, 1)^T
* @f]
*/
inline constexpr /*implicit*/ Point3D(): Vector4<T>(T(0), T(0), T(0), T(1)) {}
/**
* @brief Constructor
*
* @f[
* \boldsymbol p = (x, y, z, w)^T
* @f]
*/
inline constexpr /*implicit*/ Point3D(T x, T y, T z, T w = T(1)): Vector4<T>(x, y, z, w) {}
/**
* @brief Constructor
*
* @f[
* \boldsymbol p = (v_x, v_y, v_z, w)^T
* @f]
*/
inline constexpr /*implicit*/ Point3D(const Vector3<T>& xyz, T w): Vector4<T>(xyz, w) {}
/**
* @brief Construct 3D point from 3D vector
*
* @f[
* \boldsymbol p = (v_x, v_y, v_z, 1)^T
* @f]
*/
inline constexpr explicit Point3D(const Vector3<T>& xyz): Vector4<T>(xyz, T(1)) {}
/** @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 */
inline constexpr Point3D(const Vector<4, T>& other): Vector4<T>(other) {}
/**
* @brief Vector part of the point
*
* Equivalent to calling xyz(). Useful for seamless 2D/3D integration.
* @see Point2D::vector()
*/
inline Vector3<T>& vector() { return Vector4<T>::xyz(); }
inline constexpr Vector3<T> vector() const { return Vector4<T>::xyz(); } /**< @overload */
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4)
};
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4)
/** @debugoperator{Magnum::Math::Point3D} */
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point3D<T>& value) {
return debug << static_cast<const Vector<4, T>&>(value);
}
}}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Point3D} */
template<class T> struct ConfigurationValue<Magnum::Math::Point3D<T>>: public ConfigurationValue<Magnum::Math::Vector<4, T>> {};
}}
#endif

2
src/Math/Test/CMakeLists.txt

@ -7,8 +7,6 @@ corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathPoint2DTest Point2DTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathPoint3DTest Point3DTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib)

1
src/Math/Test/Matrix3Test.cpp

@ -47,7 +47,6 @@ typedef Math::Deg<float> Deg;
typedef Math::Matrix3<float> Matrix3;
typedef Math::Matrix<2, float> Matrix2;
typedef Math::Vector2<float> Vector2;
typedef Math::Point2D<float> Point2D;
Matrix3Test::Matrix3Test() {
addTests(&Matrix3Test::constructIdentity,

1
src/Math/Test/Matrix4Test.cpp

@ -53,7 +53,6 @@ typedef Math::Rad<float> Rad;
typedef Math::Matrix4<float> Matrix4;
typedef Math::Matrix<3, float> Matrix3;
typedef Math::Vector3<float> Vector3;
typedef Math::Point3D<float> Point3D;
Matrix4Test::Matrix4Test() {
addTests(&Matrix4Test::constructIdentity,

66
src/Math/Test/Point2DTest.cpp

@ -1,66 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <sstream>
#include <TestSuite/Tester.h>
#include <Utility/Configuration.h>
#include "Math/Point2D.h"
namespace Magnum { namespace Math { namespace Test {
class Point2DTest: public Corrade::TestSuite::Tester {
public:
Point2DTest();
void construct();
void debug();
void configuration();
};
typedef Math::Point2D<float> Point2D;
Point2DTest::Point2DTest() {
addTests(&Point2DTest::construct,
&Point2DTest::debug,
&Point2DTest::configuration);
}
void Point2DTest::construct() {
CORRADE_COMPARE(Point2D(), (Vector<3, float>(0.0f, 0.0f, 1.0f)));
CORRADE_COMPARE(Point2D(1, 2), (Vector<3, float>(1.0f, 2.0f, 1.0f)));
CORRADE_COMPARE(Point2D(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
}
void Point2DTest::debug() {
std::ostringstream o;
Debug(&o) << Point2D(0.5f, 15.0f, 1.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n");
}
void Point2DTest::configuration() {
Corrade::Utility::Configuration c;
Point2D vec(3.0f, 3.125f, 9.55f);
std::string value("3 3.125 9.55");
c.setValue("point", vec);
CORRADE_COMPARE(c.value("point"), value);
CORRADE_COMPARE(c.value<Point2D>("point"), vec);
}
}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest)

66
src/Math/Test/Point3DTest.cpp

@ -1,66 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <sstream>
#include <TestSuite/Tester.h>
#include <Utility/Configuration.h>
#include "Math/Point3D.h"
namespace Magnum { namespace Math { namespace Test {
class Point3DTest: public Corrade::TestSuite::Tester {
public:
Point3DTest();
void construct();
void debug();
void configuration();
};
typedef Math::Point3D<float> Point3D;
Point3DTest::Point3DTest() {
addTests(&Point3DTest::construct,
&Point3DTest::debug,
&Point3DTest::configuration);
}
void Point3DTest::construct() {
CORRADE_COMPARE(Point3D(), Point3D(0.0f, 0.0f, 0.0f, 1.0f));
CORRADE_COMPARE(Point3D(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
CORRADE_COMPARE(Point3D(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
}
void Point3DTest::debug() {
std::ostringstream o;
Debug(&o) << Point3D(0.5f, 15.0f, 1.0f, 1.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n");
}
void Point3DTest::configuration() {
Corrade::Utility::Configuration c;
Point3D vec(3.0f, 3.125f, 9.0f, 9.55f);
std::string value("3 3.125 9 9.55");
c.setValue("point", vec);
CORRADE_COMPARE(c.value("point"), value);
CORRADE_COMPARE(c.value<Point3D>("point"), vec);
}
}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest)

3
src/Math/Vector3.h

@ -28,8 +28,7 @@ namespace Magnum { namespace Math {
@brief Three-component vector
@tparam T Data type
See @ref matrix-vector for brief introduction. See also Point2D for
homogeneous two-dimensional coordinates.
See @ref matrix-vector for brief introduction.
@see Magnum::Vector3, Magnum::Vector3i, Magnum::Vector3ui, Magnum::Vector3d
@configurationvalueref{Magnum::Math::Vector3}
*/

3
src/Math/Vector4.h

@ -27,8 +27,7 @@ namespace Magnum { namespace Math {
@brief Four-component vector
@tparam T Data type
See @ref matrix-vector for brief introduction. See also Point3D for
homogeneous three-dimensional coordinates.
See @ref matrix-vector for brief introduction.
@see Magnum::Vector4, Magnum::Vector4i, Magnum::Vector4ui, Magnum::Vector4d
@configurationvalueref{Magnum::Math::Vector4}
*/

Loading…
Cancel
Save