=== modified file 'src/libmatrix/Makefile'
@@ -1,17 +1,35 @@
-TARGETS = libmatrix.a matrix_inverse_test
-SRCS = mat.cc program.cc matrix_inverse_test.cc
-OBJS = $(SRCS:.cc=.o)
CXXFLAGS = -Wall -Werror -pedantic -O3
-
-default: $(TARGETS)
-
-mat.o : mat.cc mat.h
-program.o: program.cc program.h
-matrix_inverse_test.o: matrix_inverse_test.cc mat.h
-matrix_inverse_test: matrix_inverse_test.o libmatrix.a
- $(CXX) -o $@ $?
+LIBMATRIX = libmatrix.a
+LIBSRCS = mat.cc program.cc
+LIBOBJS = $(LIBSRCS:.cc=.o)
+TESTDIR = test
+LIBMATRIX_TESTS = $(TESTDIR)/libmatrix_test
+TESTSRCS = $(TESTDIR)/options.cc \
+ $(TESTDIR)/const_vec_test.cc \
+ $(TESTDIR)/inverse_test.cc \
+ $(TESTDIR)/transpose_test.cc \
+ $(TESTDIR)/libmatrix_test.cc
+TESTOBJS = $(TESTSRCS:.cc=.o)
+
+# Make sure to build both the library targets and the tests, and generate
+# a make failure if the tests don't pass.
+default: $(LIBMATRIX) $(LIBMATRIX_TESTS) run_tests
+
+# Main library targets here.
+mat.o : mat.cc mat.h vec.h
+program.o: program.cc program.h mat.h vec.h
libmatrix.a : mat.o mat.h stack.h vec.h program.o program.h
- $(AR) -r $@ $(OBJS)
+ $(AR) -r $@ $(LIBOBJS)
+# Tests and execution targets here.
+$(TESTDIR)/options.o: $(TESTDIR)/options.cc $(TESTDIR)/libmatrix_test.h
+$(TESTDIR)/libmatrix_test.o: $(TESTDIR)/libmatrix_test.cc $(TESTDIR)/libmatrix_test.h $(TESTDIR)/inverse_test.h $(TESTDIR)/transpose_test.h
+$(TESTDIR)/const_vec_test.o: $(TESTDIR)/const_vec_test.cc $(TESTDIR)/const_vec_test.h $(TESTDIR)/libmatrix_test.h vec.h
+$(TESTDIR)/inverse_test.o: $(TESTDIR)/inverse_test.cc $(TESTDIR)/inverse_test.h $(TESTDIR)/libmatrix_test.h mat.h
+$(TESTDIR)/transpose_test.o: $(TESTDIR)/transpose_test.cc $(TESTDIR)/transpose_test.h $(TESTDIR)/libmatrix_test.h mat.h
+$(TESTDIR)/libmatrix_test: $(TESTOBJS) libmatrix.a
+ $(CXX) -o $@ $^
+run_tests: $(LIBMATRIX_TESTS)
+ $(LIBMATRIX_TESTS)
clean :
- $(RM) $(OBJS) $(TARGETS)
+ $(RM) $(LIBOBJS) $(TESTOBJS) $(LIBMATRIX) $(LIBMATRIX_TESTS)
=== modified file 'src/libmatrix/mat.h'
@@ -299,8 +299,8 @@
m_[8] = m.m_[8];
}
tmat3(const T& c0r0, const T& c0r1, const T& c0r2,
- const T& c1r0, const T& c1r1, const T& c1r2,
- const T& c2r0, const T& c2r1, const T& c2r2)
+ const T& c1r0, const T& c1r1, const T& c1r2,
+ const T& c2r0, const T& c2r1, const T& c2r2)
{
m_[0] = c0r0;
m_[1] = c0r1;
=== modified file 'src/libmatrix/vec.h'
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2010 Linaro Limited
+// Copyright (c) 2010-2011 Linaro Limited
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License which accompanies
@@ -64,7 +64,19 @@
return *this;
}
- const tvec2 operator/(const T& rhs)
+ const tvec2 operator/(const T& rhs) const
+ {
+ return tvec2(*this) /= rhs;
+ }
+
+ tvec2& operator/=(const tvec2& rhs)
+ {
+ x_ /= rhs.x_;
+ y_ /= rhs.y_;
+ return *this;
+ }
+
+ const tvec2 operator/(const tvec2& rhs) const
{
return tvec2(*this) /= rhs;
}
@@ -76,7 +88,19 @@
return *this;
}
- const tvec2 operator*(const T& rhs)
+ const tvec2 operator*(const T& rhs) const
+ {
+ return tvec2(*this) *= rhs;
+ }
+
+ tvec2& operator*=(const tvec2& rhs)
+ {
+ x_ *= rhs.x_;
+ y_ *= rhs.y_;
+ return *this;
+ }
+
+ const tvec2 operator*(const tvec2& rhs) const
{
return tvec2(*this) *= rhs;
}
@@ -88,7 +112,7 @@
return *this;
}
- const tvec2 operator+(const T& rhs)
+ const tvec2 operator+(const T& rhs) const
{
return tvec2(*this) += rhs;
}
@@ -100,7 +124,7 @@
return *this;
}
- const tvec2 operator+(const tvec2& rhs)
+ const tvec2 operator+(const tvec2& rhs) const
{
return tvec2(*this) += rhs;
}
@@ -112,7 +136,7 @@
return *this;
}
- const tvec2 operator-(const T& rhs)
+ const tvec2 operator-(const T& rhs) const
{
return tvec2(*this) -= rhs;
}
@@ -124,7 +148,7 @@
return *this;
}
- const tvec2 operator-(const tvec2& rhs)
+ const tvec2 operator-(const tvec2& rhs) const
{
return tvec2(*this) -= rhs;
}
@@ -206,7 +230,20 @@
return *this;
}
- const tvec3 operator/(const T& rhs)
+ const tvec3 operator/(const T& rhs) const
+ {
+ return tvec3(*this) /= rhs;
+ }
+
+ tvec3& operator/=(const tvec3& rhs)
+ {
+ x_ /= rhs.x_;
+ y_ /= rhs.y_;
+ z_ /= rhs.z_;
+ return *this;
+ }
+
+ const tvec3 operator/(const tvec3& rhs) const
{
return tvec3(*this) /= rhs;
}
@@ -219,7 +256,20 @@
return *this;
}
- const tvec3 operator*(const T& rhs)
+ const tvec3 operator*(const T& rhs) const
+ {
+ return tvec3(*this) *= rhs;
+ }
+
+ tvec3& operator*=(const tvec3& rhs)
+ {
+ x_ *= rhs.x_;
+ y_ *= rhs.y_;
+ z_ *= rhs.z_;
+ return *this;
+ }
+
+ const tvec3 operator*(const tvec3& rhs) const
{
return tvec3(*this) *= rhs;
}
@@ -232,7 +282,7 @@
return *this;
}
- const tvec3 operator+(const T& rhs)
+ const tvec3 operator+(const T& rhs) const
{
return tvec3(*this) += rhs;
}
@@ -245,7 +295,7 @@
return *this;
}
- const tvec3 operator+(const tvec3& rhs)
+ const tvec3 operator+(const tvec3& rhs) const
{
return tvec3(*this) += rhs;
}
@@ -258,7 +308,7 @@
return *this;
}
- const tvec3 operator-(const T& rhs)
+ const tvec3 operator-(const T& rhs) const
{
return tvec3(*this) -= rhs;
}
@@ -271,7 +321,7 @@
return *this;
}
- const tvec3 operator-(const tvec3& rhs)
+ const tvec3 operator-(const tvec3& rhs) const
{
return tvec3(*this) -= rhs;
}
@@ -370,7 +420,21 @@
return *this;
}
- const tvec4 operator/(const T& rhs)
+ const tvec4 operator/(const T& rhs) const
+ {
+ return tvec4(*this) /= rhs;
+ }
+
+ tvec4& operator/=(const tvec4& rhs)
+ {
+ x_ /= rhs.x_;
+ y_ /= rhs.y_;
+ z_ /= rhs.z_;
+ w_ /= rhs.w_;
+ return *this;
+ }
+
+ const tvec4 operator/(const tvec4& rhs) const
{
return tvec4(*this) /= rhs;
}
@@ -384,7 +448,21 @@
return *this;
}
- const tvec4 operator*(const T& rhs)
+ const tvec4 operator*(const T& rhs) const
+ {
+ return tvec4(*this) *= rhs;
+ }
+
+ tvec4& operator*=(const tvec4& rhs)
+ {
+ x_ *= rhs.x_;
+ y_ *= rhs.y_;
+ z_ *= rhs.z_;
+ w_ *= rhs.w_;
+ return *this;
+ }
+
+ const tvec4 operator*(const tvec4& rhs) const
{
return tvec4(*this) *= rhs;
}
@@ -398,7 +476,7 @@
return *this;
}
- const tvec4 operator+(const T& rhs)
+ const tvec4 operator+(const T& rhs) const
{
return tvec4(*this) += rhs;
}
@@ -412,7 +490,7 @@
return *this;
}
- const tvec4 operator+(const tvec4& rhs)
+ const tvec4 operator+(const tvec4& rhs) const
{
return tvec4(*this) += rhs;
}
@@ -426,7 +504,7 @@
return *this;
}
- const tvec4 operator-(const T& rhs)
+ const tvec4 operator-(const T& rhs) const
{
return tvec4(*this) -= rhs;
}
@@ -440,7 +518,7 @@
return *this;
}
- const tvec4 operator-(const tvec4& rhs)
+ const tvec4 operator-(const tvec4& rhs) const
{
return tvec4(*this) -= rhs;
}