2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "expression.h"
24 Vector3 testAdded1(const Vector3& a, const Vector3& b)
26 return vector3_added(a, vector3_added(a, b));
29 Vector3 testAdded2(const Vector3& a, const Vector3& b)
31 return vector3_for_expression( vector_added( vector3_identity(a), vector_added( vector3_identity(a), vector3_identity(b) ) ) );
34 Vector3 testMultiplied1(const Vector3& a, const Vector3& b)
36 return vector3_scaled(a, b);
39 Vector3 testMultiplied2(const Vector3& a, const Vector3& b)
41 return vector3_for_expression( vector_multiplied( vector3_identity(a), vector3_identity(b) ) );
44 Vector3 testCross1(const Vector3& a, const Vector3& b)
46 return vector3_cross(a, b);
49 Vector3 testCross2(const Vector3& a, const Vector3& b)
51 return vector3_for_expression( vector_cross( vector3_identity(a), vector3_identity(b) ) );
54 double testDot1(const Vector3& a, const Vector3& b)
56 return vector3_dot(a, b);
59 double testDot2(const Vector3& a, const Vector3& b)
61 return float_for_expression( vector_dot( vector3_identity(a), vector3_identity(b) ) );
64 double testLength1(const Vector3& a)
66 return vector3_length(a);
69 double testLength2(const Vector3& a)
71 return float_for_expression( vector_length( vector3_identity(a) ) );
74 Vector3 testNormalised1(const Vector3& a)
76 return vector3_normalised(a);
79 Vector3 testNormalised2(const Vector3& a)
81 return vector3_for_expression( vector_normalised( vector3_identity(a) ) );
84 Vector3 testNegated1(const Vector3& a)
86 return vector3_negated(a);
89 Vector3 testNegated2(const Vector3& a)
91 return vector3_for_expression( vector_negated( vector3_identity(a) ) );
94 Vector3 testScaled1(const Vector3& a, const double& b)
96 return vector3_scaled(a, b);
99 Vector3 testScaled2(const Vector3& a, const double& b)
101 return vector3_for_expression( vector_scaled( vector3_identity(a), float_literal(b) ) );
104 Vector3 testMatrixMultiplied1(const Vector3& a, const Matrix4& b)
106 return matrix4_transformed_point(b, vector3_added(a, Vector3(1, 0, 0)));
109 Vector3 testMatrixMultiplied2(const Vector3& a, const Matrix4& b)
111 return vector3_for_expression(
115 vector3_literal(Vector3(1, 0, 0))
122 Matrix4 testMatrix4Multiplied1(const Matrix4& a, const Matrix4& b)
124 return matrix4_multiplied_by_matrix4(a, matrix4_multiplied_by_matrix4(a, b));
127 Matrix4 testMatrix4Multiplied2(const Matrix4& a, const Matrix4& b)
129 return matrix4_for_expression(
137 Matrix4 testMatrix4AffineMultiplied1(const Matrix4& a, const Matrix4& b)
139 return matrix4_affine_multiplied_by_matrix4(a, b);
142 Matrix4 testMatrix4AffineMultiplied2(const Matrix4& a, const Matrix4& b)
144 return matrix4_affine_for_expression(
152 Matrix4 testMatrix4MultipliedConstant1(const Matrix4& a)
154 return matrix4_multiplied_by_matrix4(a, g_matrix4_identity);
157 Matrix4 testMatrix4MultipliedConstant2(const Matrix4& a)
159 return matrix4_for_expression(
162 matrix4_identity(g_matrix4_identity)
166 Matrix4 testMatrix4Transposed1(const Matrix4& a)
168 return matrix4_transposed(a);
171 Matrix4 testMatrix4Transposed2(const Matrix4& a)
173 return matrix4_for_expression( matrix_transposed( matrix4_identity(a) ) );
176 Vector3 testMulti1(const Matrix4& a, const Vector3& b, const Vector3& c)
178 return vector3_added(matrix4_transformed_point(matrix4_transposed(a), b), c);
181 Vector3 testMulti2(const Matrix4& a, const Vector3& b, const Vector3& c)
183 return vector3_for_expression(
187 matrix_transposed(matrix4_identity(a))
194 template<typename Value, typename First, typename Second>
195 class TestBinaryFunction
197 typedef Value(*Function)(const First&, const Second&);
201 TestBinaryFunction(Function function) : m_function(function)
204 Value run(const First& first, const Second& second) const
206 return m_function(first, second);
210 template<typename Value, typename First>
211 class TestUnaryFunction
213 typedef Value(*Function)(const First&);
217 TestUnaryFunction(Function function) : m_function(function)
220 Value run(const First& first) const
222 return m_function(first);
231 Vector3 result1 = TestBinaryFunction<Vector3, Vector3, Vector3>(testAdded1).run(Vector3(0, 0, 0), Vector3(1, 1, 1));
232 Vector3 result2 = TestBinaryFunction<Vector3, Vector3, Vector3>(testAdded2).run(Vector3(0, 0, 0), Vector3(1, 1, 1));
233 Vector3 result3 = TestBinaryFunction<Vector3, Vector3, Vector3>(testMultiplied1).run(Vector3(1, 2, 3), Vector3(2, 1, 0.5f));
234 Vector3 result4 = TestBinaryFunction<Vector3, Vector3, Vector3>(testMultiplied2).run(Vector3(1, 2, 3), Vector3(2, 1, 0.5f));
235 Vector3 result5 = TestBinaryFunction<Vector3, Vector3, double>(testScaled1).run(Vector3(1, 2, 3), 2.0);
236 Vector3 result6 = TestBinaryFunction<Vector3, Vector3, double>(testScaled2).run(Vector3(1, 2, 3), 2.0);
237 Vector3 result7 = TestBinaryFunction<Vector3, Vector3, Matrix4>(testMatrixMultiplied1).run(Vector3(1, 2, 3), matrix4_rotation_for_x_degrees(90));
238 Vector3 result8 = TestBinaryFunction<Vector3, Vector3, Matrix4>(testMatrixMultiplied2).run(Vector3(1, 2, 3), matrix4_rotation_for_x_degrees(90));
239 Vector3 result9 = TestUnaryFunction<Vector3, Vector3>(testNormalised1).run(Vector3(1, 2, 3));
240 Vector3 result10 = TestUnaryFunction<Vector3, Vector3>(testNormalised2).run(Vector3(1, 2, 3));