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 ){
25 return vector3_added( a, vector3_added( a, b ) );
28 Vector3 testAdded2( const Vector3& a, const Vector3& b ){
29 return vector3_for_expression( vector_added( vector3_identity( a ), vector_added( vector3_identity( a ), vector3_identity( b ) ) ) );
32 Vector3 testMultiplied1( const Vector3& a, const Vector3& b ){
33 return vector3_scaled( a, b );
36 Vector3 testMultiplied2( const Vector3& a, const Vector3& b ){
37 return vector3_for_expression( vector_multiplied( vector3_identity( a ), vector3_identity( b ) ) );
40 Vector3 testCross1( const Vector3& a, const Vector3& b ){
41 return vector3_cross( a, b );
44 Vector3 testCross2( const Vector3& a, const Vector3& b ){
45 return vector3_for_expression( vector_cross( vector3_identity( a ), vector3_identity( b ) ) );
48 double testDot1( const Vector3& a, const Vector3& b ){
49 return vector3_dot( a, b );
52 double testDot2( const Vector3& a, const Vector3& b ){
53 return float_for_expression( vector_dot( vector3_identity( a ), vector3_identity( b ) ) );
56 double testLength1( const Vector3& a ){
57 return vector3_length( a );
60 double testLength2( const Vector3& a ){
61 return float_for_expression( vector_length( vector3_identity( a ) ) );
64 Vector3 testNormalised1( const Vector3& a ){
65 return vector3_normalised( a );
68 Vector3 testNormalised2( const Vector3& a ){
69 return vector3_for_expression( vector_normalised( vector3_identity( a ) ) );
72 Vector3 testNegated1( const Vector3& a ){
73 return vector3_negated( a );
76 Vector3 testNegated2( const Vector3& a ){
77 return vector3_for_expression( vector_negated( vector3_identity( a ) ) );
80 Vector3 testScaled1( const Vector3& a, const double& b ){
81 return vector3_scaled( a, b );
84 Vector3 testScaled2( const Vector3& a, const double& b ){
85 return vector3_for_expression( vector_scaled( vector3_identity( a ), float_literal( b ) ) );
88 Vector3 testMatrixMultiplied1( const Vector3& a, const Matrix4& b ){
89 return matrix4_transformed_point( b, vector3_added( a, Vector3( 1, 0, 0 ) ) );
92 Vector3 testMatrixMultiplied2( const Vector3& a, const Matrix4& b ){
93 return vector3_for_expression(
96 vector3_identity( a ),
97 vector3_literal( Vector3( 1, 0, 0 ) )
104 Matrix4 testMatrix4Multiplied1( const Matrix4& a, const Matrix4& b ){
105 return matrix4_multiplied_by_matrix4( a, matrix4_multiplied_by_matrix4( a, b ) );
108 Matrix4 testMatrix4Multiplied2( const Matrix4& a, const Matrix4& b ){
109 return matrix4_for_expression(
111 matrix4_identity( a ),
112 matrix4_identity( b )
117 Matrix4 testMatrix4AffineMultiplied1( const Matrix4& a, const Matrix4& b ){
118 return matrix4_affine_multiplied_by_matrix4( a, b );
121 Matrix4 testMatrix4AffineMultiplied2( const Matrix4& a, const Matrix4& b ){
122 return matrix4_affine_for_expression(
124 matrix4_identity( a ),
125 matrix4_identity( b )
130 Matrix4 testMatrix4MultipliedConstant1( const Matrix4& a ){
131 return matrix4_multiplied_by_matrix4( a, g_matrix4_identity );
134 Matrix4 testMatrix4MultipliedConstant2( const Matrix4& a ){
135 return matrix4_for_expression(
137 matrix4_identity( a ),
138 matrix4_identity( g_matrix4_identity )
142 Matrix4 testMatrix4Transposed1( const Matrix4& a ){
143 return matrix4_transposed( a );
146 Matrix4 testMatrix4Transposed2( const Matrix4& a ){
147 return matrix4_for_expression( matrix_transposed( matrix4_identity( a ) ) );
150 Vector3 testMulti1( const Matrix4& a, const Vector3& b, const Vector3& c ){
151 return vector3_added( matrix4_transformed_point( matrix4_transposed( a ), b ), c );
154 Vector3 testMulti2( const Matrix4& a, const Vector3& b, const Vector3& c ){
155 return vector3_for_expression(
158 vector3_identity( b ),
159 matrix_transposed( matrix4_identity( a ) )
161 vector3_identity( c )
166 template<typename Value, typename First, typename Second>
167 class TestBinaryFunction
169 typedef Value ( *Function )( const First&, const Second& );
173 TestBinaryFunction( Function function ) : m_function( function ){
175 Value run( const First& first, const Second& second ) const {
176 return m_function( first, second );
180 template<typename Value, typename First>
181 class TestUnaryFunction
183 typedef Value ( *Function )( const First& );
187 TestUnaryFunction( Function function ) : m_function( function ){
189 Value run( const First& first ) const {
190 return m_function( first );
198 Vector3 result1 = TestBinaryFunction<Vector3, Vector3, Vector3>( testAdded1 ).run( Vector3( 0, 0, 0 ), Vector3( 1, 1, 1 ) );
199 Vector3 result2 = TestBinaryFunction<Vector3, Vector3, Vector3>( testAdded2 ).run( Vector3( 0, 0, 0 ), Vector3( 1, 1, 1 ) );
200 Vector3 result3 = TestBinaryFunction<Vector3, Vector3, Vector3>( testMultiplied1 ).run( Vector3( 1, 2, 3 ), Vector3( 2, 1, 0.5f ) );
201 Vector3 result4 = TestBinaryFunction<Vector3, Vector3, Vector3>( testMultiplied2 ).run( Vector3( 1, 2, 3 ), Vector3( 2, 1, 0.5f ) );
202 Vector3 result5 = TestBinaryFunction<Vector3, Vector3, double>( testScaled1 ).run( Vector3( 1, 2, 3 ), 2.0 );
203 Vector3 result6 = TestBinaryFunction<Vector3, Vector3, double>( testScaled2 ).run( Vector3( 1, 2, 3 ), 2.0 );
204 Vector3 result7 = TestBinaryFunction<Vector3, Vector3, Matrix4>( testMatrixMultiplied1 ).run( Vector3( 1, 2, 3 ), matrix4_rotation_for_x_degrees( 90 ) );
205 Vector3 result8 = TestBinaryFunction<Vector3, Vector3, Matrix4>( testMatrixMultiplied2 ).run( Vector3( 1, 2, 3 ), matrix4_rotation_for_x_degrees( 90 ) );
206 Vector3 result9 = TestUnaryFunction<Vector3, Vector3>( testNormalised1 ).run( Vector3( 1, 2, 3 ) );
207 Vector3 result10 = TestUnaryFunction<Vector3, Vector3>( testNormalised2 ).run( Vector3( 1, 2, 3 ) );