mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
415 lines
14 KiB
415 lines
14 KiB
|
15 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 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.
|
||
|
15 years ago
|
|
||
|
13 years ago
|
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.
|
||
|
15 years ago
|
*/
|
||
|
|
|
||
|
14 years ago
|
#include <sstream>
|
||
|
14 years ago
|
#include <TestSuite/Tester.h>
|
||
|
14 years ago
|
#include <Utility/Configuration.h>
|
||
|
15 years ago
|
|
||
|
14 years ago
|
#include "Math/Matrix3.h"
|
||
|
15 years ago
|
|
||
|
13 years ago
|
struct Mat3 {
|
||
|
|
float a[9];
|
||
|
|
};
|
||
|
|
|
||
|
|
namespace Magnum { namespace Math {
|
||
|
|
|
||
|
|
namespace Implementation {
|
||
|
|
|
||
|
|
template<> struct RectangularMatrixConverter<3, 3, float, Mat3> {
|
||
|
13 years ago
|
constexpr static RectangularMatrix<3, 3, Float> from(const Mat3& other) {
|
||
|
13 years ago
|
return RectangularMatrix<3, 3, Float>(
|
||
|
|
Vector<3, Float>(other.a[0], other.a[1], other.a[2]),
|
||
|
|
Vector<3, Float>(other.a[3], other.a[4], other.a[5]),
|
||
|
|
Vector<3, Float>(other.a[6], other.a[7], other.a[8]));
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
constexpr static Mat3 to(const RectangularMatrix<3, 3, Float>& other) {
|
||
|
13 years ago
|
return Mat3{{other[0][0], other[0][1], other[0][2],
|
||
|
|
other[1][0], other[1][1], other[1][2],
|
||
|
|
other[2][0], other[2][1], other[2][2]}};
|
||
|
13 years ago
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
namespace Test {
|
||
|
15 years ago
|
|
||
|
14 years ago
|
class Matrix3Test: public Corrade::TestSuite::Tester {
|
||
|
|
public:
|
||
|
|
Matrix3Test();
|
||
|
|
|
||
|
13 years ago
|
void construct();
|
||
|
14 years ago
|
void constructIdentity();
|
||
|
13 years ago
|
void constructZero();
|
||
|
|
void constructConversion();
|
||
|
|
void constructCopy();
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void convert();
|
||
|
|
|
||
|
13 years ago
|
void isRigidTransformation();
|
||
|
|
|
||
|
14 years ago
|
void translation();
|
||
|
|
void scaling();
|
||
|
|
void rotation();
|
||
|
|
void reflection();
|
||
|
14 years ago
|
void projection();
|
||
|
14 years ago
|
void fromParts();
|
||
|
|
void rotationScalingPart();
|
||
|
13 years ago
|
void rotationNormalizedPart();
|
||
|
14 years ago
|
void rotationPart();
|
||
|
13 years ago
|
void uniformScalingPart();
|
||
|
14 years ago
|
void vectorParts();
|
||
|
13 years ago
|
void invertedRigid();
|
||
|
13 years ago
|
void transform();
|
||
|
14 years ago
|
|
||
|
|
void debug();
|
||
|
|
void configuration();
|
||
|
|
};
|
||
|
|
|
||
|
13 years ago
|
typedef Math::Deg<Float> Deg;
|
||
|
|
typedef Math::Matrix3<Float> Matrix3;
|
||
|
13 years ago
|
typedef Math::Matrix3<Int> Matrix3i;
|
||
|
13 years ago
|
typedef Math::Matrix<2, Float> Matrix2x2;
|
||
|
13 years ago
|
typedef Math::Vector3<Float> Vector3;
|
||
|
13 years ago
|
typedef Math::Vector2<Float> Vector2;
|
||
|
15 years ago
|
|
||
|
14 years ago
|
Matrix3Test::Matrix3Test() {
|
||
|
13 years ago
|
addTests({&Matrix3Test::construct,
|
||
|
|
&Matrix3Test::constructIdentity,
|
||
|
|
&Matrix3Test::constructZero,
|
||
|
|
&Matrix3Test::constructConversion,
|
||
|
|
&Matrix3Test::constructCopy,
|
||
|
13 years ago
|
|
||
|
13 years ago
|
&Matrix3Test::convert,
|
||
|
|
|
||
|
13 years ago
|
&Matrix3Test::isRigidTransformation,
|
||
|
|
|
||
|
13 years ago
|
&Matrix3Test::translation,
|
||
|
|
&Matrix3Test::scaling,
|
||
|
|
&Matrix3Test::rotation,
|
||
|
|
&Matrix3Test::reflection,
|
||
|
|
&Matrix3Test::projection,
|
||
|
|
&Matrix3Test::fromParts,
|
||
|
|
&Matrix3Test::rotationScalingPart,
|
||
|
13 years ago
|
&Matrix3Test::rotationNormalizedPart,
|
||
|
13 years ago
|
&Matrix3Test::rotationPart,
|
||
|
13 years ago
|
&Matrix3Test::uniformScalingPart,
|
||
|
13 years ago
|
&Matrix3Test::vectorParts,
|
||
|
13 years ago
|
&Matrix3Test::invertedRigid,
|
||
|
13 years ago
|
&Matrix3Test::transform,
|
||
|
13 years ago
|
|
||
|
13 years ago
|
&Matrix3Test::debug,
|
||
|
|
&Matrix3Test::configuration});
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::construct() {
|
||
|
13 years ago
|
constexpr Matrix3 a = {{3.0f, 5.0f, 8.0f},
|
||
|
|
{4.5f, 4.0f, 7.0f},
|
||
|
|
{7.9f, -1.0f, 8.0f}};
|
||
|
13 years ago
|
CORRADE_COMPARE(a, Matrix3({3.0f, 5.0f, 8.0f},
|
||
|
|
{4.5f, 4.0f, 7.0f},
|
||
|
|
{7.9f, -1.0f, 8.0f}));
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::constructIdentity() {
|
||
|
13 years ago
|
constexpr Matrix3 identity;
|
||
|
|
constexpr Matrix3 identity2(Matrix3::Identity);
|
||
|
|
constexpr Matrix3 identity3(Matrix3::Identity, 4.0f);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Matrix3 identityExpected({1.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.0f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 1.0f});
|
||
|
|
|
||
|
|
Matrix3 identity3Expected({4.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 4.0f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 4.0f});
|
||
|
14 years ago
|
|
||
|
14 years ago
|
CORRADE_COMPARE(identity, identityExpected);
|
||
|
|
CORRADE_COMPARE(identity2, identityExpected);
|
||
|
|
CORRADE_COMPARE(identity3, identity3Expected);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::constructZero() {
|
||
|
|
constexpr Matrix3 a(Matrix3::Zero);
|
||
|
|
CORRADE_COMPARE(a, Matrix3({0.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 0.0f}));
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Matrix3Test::constructConversion() {
|
||
|
|
constexpr Matrix3 a({3.0f, 5.0f, 8.0f},
|
||
|
|
{4.5f, 4.0f, 7.0f},
|
||
|
|
{7.9f, -1.0f, 8.0f});
|
||
|
|
#ifndef CORRADE_GCC46_COMPATIBILITY
|
||
|
13 years ago
|
constexpr /* Not constexpr under GCC < 4.7 */
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
Matrix3i b(a);
|
||
|
13 years ago
|
CORRADE_COMPARE(b, Matrix3i({3, 5, 8},
|
||
|
|
{4, 4, 7},
|
||
|
|
{7, -1, 8}));
|
||
|
13 years ago
|
|
||
|
|
/* Implicit conversion is not allowed */
|
||
|
|
CORRADE_VERIFY(!(std::is_convertible<Matrix3, Matrix3i>::value));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::constructCopy() {
|
||
|
13 years ago
|
constexpr RectangularMatrix<3, 3, Float> a(Vector<3, Float>(3.0f, 5.0f, 8.0f),
|
||
|
|
Vector<3, Float>(4.5f, 4.0f, 7.0f),
|
||
|
|
Vector<3, Float>(7.9f, -1.0f, 8.0f));
|
||
|
13 years ago
|
constexpr Matrix3 b(a);
|
||
|
|
CORRADE_COMPARE(b, Matrix3({3.0f, 5.0f, 8.0f},
|
||
|
|
{4.5f, 4.0f, 7.0f},
|
||
|
|
{7.9f, -1.0f, 8.0f}));
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
void Matrix3Test::convert() {
|
||
|
13 years ago
|
constexpr Mat3 a{{1.5f, 2.0f, -3.5f,
|
||
|
|
2.0f, -3.1f, 0.4f,
|
||
|
|
9.5f, -1.5f, 0.1f}};
|
||
|
13 years ago
|
constexpr Matrix3 b(Vector3(1.5f, 2.0f, -3.5f),
|
||
|
|
Vector3(2.0f, -3.1f, 0.4f),
|
||
|
|
Vector3(9.5f, -1.5f, 0.1f));
|
||
|
|
|
||
|
|
constexpr Matrix3 c(b);
|
||
|
|
CORRADE_COMPARE(c, b);
|
||
|
|
|
||
|
|
#ifndef CORRADE_GCC46_COMPATIBILITY
|
||
|
|
constexpr /* Not constexpr under GCC < 4.7 */
|
||
|
|
#endif
|
||
|
|
Mat3 d(b);
|
||
|
|
for(std::size_t i = 0; i != 9; ++i)
|
||
|
|
CORRADE_COMPARE(d.a[0], a.a[0]);
|
||
|
|
|
||
|
|
/* Implicit conversion is not allowed */
|
||
|
|
CORRADE_VERIFY(!(std::is_convertible<Mat3, Matrix3>::value));
|
||
|
|
CORRADE_VERIFY(!(std::is_convertible<Matrix3, Mat3>::value));
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::isRigidTransformation() {
|
||
|
|
CORRADE_VERIFY(!Matrix3({1.0f, 0.0f, 0.0f},
|
||
|
|
{0.1f, 1.0f, 0.0f},
|
||
|
|
{5.0f, 4.0f, 1.0f}).isRigidTransformation());
|
||
|
|
CORRADE_VERIFY(!Matrix3({1.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.0f, 1.0f},
|
||
|
|
{5.0f, 4.0f, 0.0f}).isRigidTransformation());
|
||
|
|
CORRADE_VERIFY(Matrix3({1.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.0f, 0.0f},
|
||
|
|
{5.0f, 4.0f, 1.0f}).isRigidTransformation());
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::translation() {
|
||
|
|
constexpr Matrix3 a = Matrix3::translation({3.0f, 1.0f});
|
||
|
|
CORRADE_COMPARE(a, Matrix3({1.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.0f, 0.0f},
|
||
|
|
{3.0f, 1.0f, 1.0f}));
|
||
|
|
}
|
||
|
|
|
||
|
|
void Matrix3Test::scaling() {
|
||
|
|
constexpr Matrix3 a = Matrix3::scaling({3.0f, 1.5f});
|
||
|
|
CORRADE_COMPARE(a, Matrix3({3.0f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.5f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 1.0f}));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
void Matrix3Test::rotation() {
|
||
|
13 years ago
|
Matrix3 matrix({ 0.965926f, 0.258819f, 0.0f},
|
||
|
|
{-0.258819f, 0.965926f, 0.0f},
|
||
|
|
{ 0.0f, 0.0f, 1.0f});
|
||
|
14 years ago
|
|
||
|
13 years ago
|
CORRADE_COMPARE(Matrix3::rotation(Deg(15.0f)), matrix);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::reflection() {
|
||
|
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
|
|
||
|
|
Vector2 normal(-1.0f, 2.0f);
|
||
|
|
|
||
|
|
CORRADE_COMPARE(Matrix3::reflection(normal), Matrix3());
|
||
|
|
CORRADE_COMPARE(o.str(), "Math::Matrix3::reflection(): normal must be normalized\n");
|
||
|
|
|
||
|
|
Matrix3 actual = Matrix3::reflection(normal.normalized());
|
||
|
13 years ago
|
Matrix3 expected({0.6f, 0.8f, 0.0f},
|
||
|
|
{0.8f, -0.6f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 1.0f});
|
||
|
14 years ago
|
|
||
|
|
CORRADE_COMPARE(actual*actual, Matrix3());
|
||
|
13 years ago
|
CORRADE_COMPARE(actual.transformVector(normal), -normal);
|
||
|
14 years ago
|
CORRADE_COMPARE(actual, expected);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::projection() {
|
||
|
13 years ago
|
Matrix3 expected({2.0f/4.0f, 0.0f, 0.0f},
|
||
|
|
{ 0.0f, 2.0f/3.0f, 0.0f},
|
||
|
|
{ 0.0f, 0.0f, 1.0f});
|
||
|
14 years ago
|
|
||
|
|
CORRADE_COMPARE(Matrix3::projection({4.0f, 3.0f}), expected);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::fromParts() {
|
||
|
13 years ago
|
constexpr Matrix2x2 rotationScaling(Vector2(3.0f, 5.0f),
|
||
|
|
Vector2(4.0f, 4.0f));
|
||
|
13 years ago
|
constexpr Vector2 translation(7.0f, -1.0f);
|
||
|
|
constexpr Matrix3 a = Matrix3::from(rotationScaling, translation);
|
||
|
|
|
||
|
|
CORRADE_COMPARE(a, Matrix3({3.0f, 5.0f, 0.0f},
|
||
|
|
{4.0f, 4.0f, 0.0f},
|
||
|
|
{7.0f, -1.0f, 1.0f}));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::rotationScalingPart() {
|
||
|
13 years ago
|
constexpr Matrix3 a({3.0f, 5.0f, 8.0f},
|
||
|
|
{4.0f, 4.0f, 7.0f},
|
||
|
|
{7.0f, -1.0f, 8.0f});
|
||
|
13 years ago
|
constexpr Matrix2x2 b = a.rotationScaling();
|
||
|
14 years ago
|
|
||
|
13 years ago
|
CORRADE_COMPARE(b, Matrix2x2(Vector2(3.0f, 5.0f),
|
||
|
|
Vector2(4.0f, 4.0f)));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::rotationNormalizedPart() {
|
||
|
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
|
|
||
|
|
Matrix3 a({1.0f, 0.0f, 8.0f},
|
||
|
|
{1.0f, 0.1f, 7.0f},
|
||
|
|
{7.0f, -1.0f, 8.0f});
|
||
|
|
a.rotationNormalized();
|
||
|
|
|
||
|
|
CORRADE_COMPARE(o.str(), "Math::Matrix3::rotationNormalized(): the rotation part is not normalized\n");
|
||
|
|
|
||
|
|
Matrix3 b({ 0.965926f, 0.258819f, 1.0f},
|
||
|
|
{-0.258819f, 0.965926f, 3.0f},
|
||
|
|
{ 0.0f, 0.0f, 1.0f});
|
||
|
13 years ago
|
CORRADE_COMPARE(b.rotationNormalized(), Matrix2x2(Vector2( 0.965926f, 0.258819f),
|
||
|
|
Vector2(-0.258819f, 0.965926f)));
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::rotationPart() {
|
||
|
13 years ago
|
Matrix3 rotation = Matrix3::rotation(Deg(15.0f));
|
||
|
13 years ago
|
Matrix2x2 expectedRotationPart(Vector2( 0.965926f, 0.258819f),
|
||
|
|
Vector2(-0.258819f, 0.965926f));
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* For rotation and translation this is the same as rotationScaling() */
|
||
|
|
Matrix3 rotationTranslation = rotation*Matrix3::translation({2.0f, 5.0f});
|
||
|
13 years ago
|
Matrix2x2 rotationTranslationPart = rotationTranslation.rotation();
|
||
|
13 years ago
|
CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling());
|
||
|
|
CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart);
|
||
|
|
|
||
|
|
/* Test uniform scaling */
|
||
|
13 years ago
|
Matrix3 rotationScaling = rotation*Matrix3::scaling(Vector2(3.0f));
|
||
|
13 years ago
|
Matrix2x2 rotationScalingPart = rotationScaling.rotation();
|
||
|
13 years ago
|
CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f);
|
||
|
13 years ago
|
CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix2x2());
|
||
|
13 years ago
|
CORRADE_COMPARE(rotationScalingPart, expectedRotationPart);
|
||
|
|
|
||
|
|
/* Fails on non-uniform scaling */
|
||
|
13 years ago
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
13 years ago
|
Matrix2x2 rotationScaling2 = (rotation*Matrix3::scaling(Vector2::yScale(3.5f))).rotation();
|
||
|
13 years ago
|
CORRADE_COMPARE(o.str(), "Math::Matrix3::rotation(): the matrix doesn't have uniform scaling\n");
|
||
|
13 years ago
|
CORRADE_COMPARE(rotationScaling2, Matrix2x2());
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::uniformScalingPart() {
|
||
|
|
const Matrix3 rotation = Matrix3::rotation(Deg(-74.0f));
|
||
|
|
|
||
|
|
/* Test uniform scaling */
|
||
|
|
CORRADE_COMPARE((rotation*Matrix3::scaling(Vector2(3.0f))).uniformScaling(), 3.0f);
|
||
|
|
|
||
|
|
/* Fails on non-uniform scaling */
|
||
|
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
|
const Float nonUniformScaling = (rotation*Matrix3::scaling(Vector2::yScale(3.0f))).uniformScaling();
|
||
|
|
CORRADE_COMPARE(o.str(), "Math::Matrix3::uniformScaling(): the matrix doesn't have uniform scaling\n");
|
||
|
|
CORRADE_COMPARE(nonUniformScaling, 0.0f);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::vectorParts() {
|
||
|
13 years ago
|
constexpr Matrix3 a({15.0f, 0.0f, 0.0f},
|
||
|
|
{ 0.0f, -3.0f, 0.0f},
|
||
|
|
{-5.0f, 12.0f, 1.0f});
|
||
|
|
constexpr Vector2 right = a.right();
|
||
|
|
constexpr Vector2 up = a.up();
|
||
|
|
constexpr Vector2 translation = a.translation();
|
||
|
|
|
||
|
|
CORRADE_COMPARE(right, Vector2::xAxis(15.0f));
|
||
|
|
CORRADE_COMPARE(up, Vector2::yAxis(-3.0f));
|
||
|
|
CORRADE_COMPARE(translation, Vector2(-5.0f, 12.0f));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::invertedRigid() {
|
||
|
13 years ago
|
Matrix3 actual = Matrix3::rotation(Deg(-74.0f))*
|
||
|
14 years ago
|
Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())*
|
||
|
|
Matrix3::translation({2.0f, -3.0f});
|
||
|
|
Matrix3 expected = Matrix3::translation({-2.0f, 3.0f})*
|
||
|
|
Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())*
|
||
|
13 years ago
|
Matrix3::rotation(Deg(74.0f));
|
||
|
14 years ago
|
|
||
|
13 years ago
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
|
(2*actual).invertedRigid();
|
||
|
|
CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedRigid(): the matrix doesn't represent rigid transformation\n");
|
||
|
|
|
||
|
|
CORRADE_COMPARE(actual.invertedRigid(), expected);
|
||
|
|
CORRADE_COMPARE(actual.invertedRigid(), actual.inverted());
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void Matrix3Test::transform() {
|
||
|
13 years ago
|
Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(Deg(90.0f));
|
||
|
13 years ago
|
Vector2 v(1.0f, -2.0f);
|
||
|
|
|
||
|
|
CORRADE_COMPARE(a.transformVector(v), Vector2(2.0f, 1.0f));
|
||
|
|
CORRADE_COMPARE(a.transformPoint(v), Vector2(3.0f, -4.0f));
|
||
|
|
}
|
||
|
|
|
||
|
15 years ago
|
void Matrix3Test::debug() {
|
||
|
13 years ago
|
Matrix3 m({3.0f, 5.0f, 8.0f},
|
||
|
|
{4.0f, 4.0f, 7.0f},
|
||
|
|
{7.0f, -1.0f, 8.0f});
|
||
|
15 years ago
|
|
||
|
14 years ago
|
std::ostringstream o;
|
||
|
14 years ago
|
Debug(&o) << m;
|
||
|
14 years ago
|
CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7,\n"
|
||
|
|
" 5, 4, -1,\n"
|
||
|
|
" 8, 7, 8)\n");
|
||
|
15 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void Matrix3Test::configuration() {
|
||
|
13 years ago
|
Corrade::Utility::Configuration c;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Matrix3 m({5.0f, 8.0f, 4.0f},
|
||
|
|
{4.0f, 7.0f, 3.125f},
|
||
|
|
{4.0f, 5.0f, 9.55f});
|
||
|
14 years ago
|
std::string value("5 4 4 8 7 5 4 3.125 9.55");
|
||
|
14 years ago
|
|
||
|
|
c.setValue("matrix", m);
|
||
|
14 years ago
|
CORRADE_COMPARE(c.value("matrix"), value);
|
||
|
14 years ago
|
CORRADE_COMPARE(c.value<Matrix3>("matrix"), m);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
15 years ago
|
}}}
|
||
|
14 years ago
|
|
||
|
|
CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test)
|