Debian Codegraph @

libs/math/expression.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #include "expression.h"
23
24 Vector3 testAdded1( const Vector3& a, const Vector3& b ){
25 return vector3_added( a, vector3_added( a, b ) );
26 }
27
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 ) ) ) );
30 }
31
32 Vector3 testMultiplied1( const Vector3& a, const Vector3& b ){
33 return vector3_scaled( a, b );
34 }
35
36 Vector3 testMultiplied2( const Vector3& a, const Vector3& b ){
37 return vector3_for_expression( vector_multiplied( vector3_identity( a ), vector3_identity( b ) ) );
38 }
39
40 Vector3 testCross1( const Vector3& a, const Vector3& b ){
41 return vector3_cross( a, b );
42 }
43
44 Vector3 testCross2( const Vector3& a, const Vector3& b ){
45 return vector3_for_expression( vector_cross( vector3_identity( a ), vector3_identity( b ) ) );
46 }
47
48 double testDot1( const Vector3& a, const Vector3& b ){
49 return vector3_dot( a, b );
50 }
51
52 double testDot2( const Vector3& a, const Vector3& b ){
53 return float_for_expression( vector_dot( vector3_identity( a ), vector3_identity( b ) ) );
54 }
55
56 double testLength1( const Vector3& a ){
57 return vector3_length( a );
58 }
59
60 double testLength2( const Vector3& a ){
61 return float_for_expression( vector_length( vector3_identity( a ) ) );
62 }
63
64 Vector3 testNormalised1( const Vector3& a ){
65 return vector3_normalised( a );
66 }
67
68 Vector3 testNormalised2( const Vector3& a ){
69 return vector3_for_expression( vector_normalised( vector3_identity( a ) ) );
70 }
71
72 Vector3 testNegated1( const Vector3& a ){
73 return vector3_negated( a );
74 }
75
76 Vector3 testNegated2( const Vector3& a ){
77 return vector3_for_expression( vector_negated( vector3_identity( a ) ) );
78 }
79
80 Vector3 testScaled1( const Vector3& a, const double& b ){
81 return vector3_scaled( a, b );
82 }
83
84 Vector3 testScaled2( const Vector3& a, const double& b ){
85 return vector3_for_expression( vector_scaled( vector3_identity( a ), float_literal( b ) ) );
86 }
87
88 Vector3 testMatrixMultiplied1( const Vector3& a, const Matrix4& b ){
89 return matrix4_transformed_point( b, vector3_added( a, Vector3( 1, 0, 0 ) ) );
90 }
91
92 Vector3 testMatrixMultiplied2( const Vector3& a, const Matrix4& b ){
93 return vector3_for_expression(
94 point_multiplied(
95 vector_added(
96 vector3_identity( a ),
97 vector3_literal( Vector3( 1, 0, 0 ) )
98 ),
99 matrix4_identity( b )
100 )
101 );
102 }
103
104 Matrix4 testMatrix4Multiplied1( const Matrix4& a, const Matrix4& b ){
105 return matrix4_multiplied_by_matrix4( a, matrix4_multiplied_by_matrix4( a, b ) );
106 }
107
108 Matrix4 testMatrix4Multiplied2( const Matrix4& a, const Matrix4& b ){
109 return matrix4_for_expression(
110 matrix4_multiplied(
111 matrix4_identity( a ),
112 matrix4_identity( b )
113 )
114 );
115 }
116
117 Matrix4 testMatrix4AffineMultiplied1( const Matrix4& a, const Matrix4& b ){
118 return matrix4_affine_multiplied_by_matrix4( a, b );
119 }
120
121 Matrix4 testMatrix4AffineMultiplied2( const Matrix4& a, const Matrix4& b ){
122 return matrix4_affine_for_expression(
123 matrix4_multiplied(
124 matrix4_identity( a ),
125 matrix4_identity( b )
126 )
127 );
128 }
129
130 Matrix4 testMatrix4MultipliedConstant1( const Matrix4& a ){
131 return matrix4_multiplied_by_matrix4( a, g_matrix4_identity );
132 }
133
134 Matrix4 testMatrix4MultipliedConstant2( const Matrix4& a ){
135 return matrix4_for_expression(
136 matrix4_multiplied(
137 matrix4_identity( a ),
138 matrix4_identity( g_matrix4_identity )
139 )
140 );
141 }
142 Matrix4 testMatrix4Transposed1( const Matrix4& a ){
143 return matrix4_transposed( a );
144 }
145
146 Matrix4 testMatrix4Transposed2( const Matrix4& a ){
147 return matrix4_for_expression( matrix_transposed( matrix4_identity( a ) ) );
148 }
149
150 Vector3 testMulti1( const Matrix4& a, const Vector3& b, const Vector3& c ){
151 return vector3_added( matrix4_transformed_point( matrix4_transposed( a ), b ), c );
152 }
153
154 Vector3 testMulti2( const Matrix4& a, const Vector3& b, const Vector3& c ){
155 return vector3_for_expression(
156 vector_added(
157 point_multiplied(
158 vector3_identity( b ),
159 matrix_transposed( matrix4_identity( a ) )
160 ),
161 vector3_identity( c )
162 )
163 );
164 }
165
166 template<typename Value, typename First, typename Second>
167 class TestBinaryFunction
168 {
169 typedef Value ( *Function )( const First&, const Second& );
170 Function m_function;
171 public:
172
173 TestBinaryFunction( Function function ) : m_function( function ){
174 }
175 Value run( const First& first, const Second& second ) const {
176 return m_function( first, second );
177 }
178 };
179
180 template<typename Value, typename First>
181 class TestUnaryFunction
182 {
183 typedef Value ( *Function )( const First& );
184 Function m_function;
185 public:
186
187 TestUnaryFunction( Function function ) : m_function( function ){
188 }
189 Value run( const First& first ) const {
190 return m_function( first );
191 }
192 };
193
194 class TestAll
195 {
196 public:
197 TestAll(){
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 ) );
208 }
209 } g_testAll;