Added axis angle accessors, removed == operator.

This commit is contained in:
James Goppert
2016-08-16 11:05:01 -04:00
parent 19554c4470
commit 4f13809420
6 changed files with 53 additions and 27 deletions
+9
View File
@@ -153,6 +153,15 @@ public:
v(1) = a(1)*angle;
v(2) = a(2)*angle;
}
Vector<Type, 3> axis() {
return Vector<Type, 3>::unit();
}
Type angle() {
return Vector<Type, 3>::norm();
}
};
typedef AxisAngle<float> AxisAnglef;
+35 -19
View File
@@ -134,22 +134,6 @@ public:
return res;
}
bool operator==(const Matrix<Type, M, N> &other) const
{
const Matrix<Type, M, N> &self = *this;
static const Type eps = Type(1e-4);
for (size_t i = 0; i < M; i++) {
for (size_t j = 0; j < N; j++) {
if (fabs(self(i , j) - other(i, j)) > eps) {
return false;
}
}
}
return true;
}
Matrix<Type, M, N> operator-(const Matrix<Type, M, N> &other) const
{
Matrix<Type, M, N> res;
@@ -469,15 +453,47 @@ Matrix<Type, M, N> operator*(Type scalar, const Matrix<Type, M, N> &other)
template<typename Type, size_t M, size_t N>
bool isEqual(const Matrix<Type, M, N> &x,
const Matrix<Type, M, N> & y) {
if (!(x == y)) {
const Matrix<Type, M, N> &y, const Type eps=1e-4f) {
bool equal = true;
for (size_t i = 0; i < M; i++) {
for (size_t j = 0; j < N; j++) {
if (fabs(x(i , j) - y(i, j)) > eps) {
equal = false;
break;
}
}
if (equal == false) break;
}
if (!equal) {
char buf_x[100];
char buf_y[100];
x.write_string(buf_x, 100);
y.write_string(buf_y, 100);
printf("not equal\nx:\n%s\ny:\n%s\n", buf_x, buf_y);
}
return x == y;
return equal;
}
bool isEqual(float x,
float y, float eps);
bool isEqual(float x,
float y, float eps=1e-4f) {
bool equal = true;
if (fabs(x - y) > eps) {
equal = false;
}
if (!equal) {
printf("not equal\nx:\n%g\ny:\n%g\n", x, y);
}
return equal;
}
#if defined(SUPPORT_STDIOSTREAM)
+2 -1
View File
@@ -276,7 +276,8 @@ int main()
AxisAnglef aa_axis_angle_init(Vector3f(1.0f, 2.0f, 3.0f), 3.0f);
TEST(isEqual(aa_axis_angle_init, Vector3f(0.80178373f, 1.60356745f, 2.40535118f)));
TEST(isEqual(aa_axis_angle_init.axis(), Vector3f(0.26726124f, 0.53452248f, 0.80178373f)));
TEST(isEqual(aa_axis_angle_init.angle(), 3.0f));
TEST(isEqual(Quatf((AxisAnglef(Vector3f(0.0f, 0.0f, 1.0f), 0.0f))),
Quatf(1.0f, 0.0f, 0.0f, 0.0f)));
};
+1 -1
View File
@@ -30,7 +30,7 @@ int main()
Matrix3f m3(data_times_2);
TEST(isEqual(m, m2));
TEST(!(m == m3));
TEST(!(isEqual(m, m3)));
m2 *= 2;
TEST(isEqual(m2, m3));
+2 -2
View File
@@ -17,10 +17,10 @@ int main()
TEST(fabs(v1.dot(v2) - 130.0f) < 1e-5);
v2.normalize();
Vector<float, 5> v3(v2);
TEST(v2 == v3);
TEST(isEqual(v2, v3));
float data1_sq[] = {1,4,9,16,25};
Vector<float, 5> v4(data1_sq);
TEST(v1 == v4.pow(0.5));
TEST(isEqual(v1, v4.pow(0.5)));
return 0;
}
+4 -4
View File
@@ -12,15 +12,15 @@ int main()
Vector3f a(1, 0, 0);
Vector3f b(0, 1, 0);
Vector3f c = a.cross(b);
TEST (c == Vector3f(0,0,1));
TEST(isEqual(c, Vector3f(0,0,1)));
c = a % b;
TEST (c == Vector3f(0,0,1));
TEST (isEqual(c, Vector3f(0,0,1)));
Matrix<float, 3, 1> d(c);
Vector3f e(d);
TEST (e == d);
TEST (isEqual(e, d));
float data[] = {4, 5, 6};
Vector3f f(data);
TEST (f == Vector3f(4, 5, 6));
TEST(isEqual(f, Vector3f(4, 5, 6)));
return 0;
}