Changeset 1052
- Timestamp:
- Nov 7, 2011, 1:36:25 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/matrix.cpp
r1048 r1052 108 108 } 109 109 110 template<> void cmplx::printf() const 111 { 112 Log::Debug("[ %6.6f %6.6f ]\n", x, y); 113 } 114 110 115 template<> void vec3::printf() const 111 116 { … … 153 158 } 154 159 160 template<> std::ostream &operator<<(std::ostream &stream, icmplx const &v) 161 { 162 return stream << "(" << v.x << ", " << v.y << ")"; 163 } 164 155 165 template<> std::ostream &operator<<(std::ostream &stream, ivec3 const &v) 156 166 { … … 171 181 172 182 template<> std::ostream &operator<<(std::ostream &stream, vec2 const &v) 183 { 184 return stream << "(" << v.x << ", " << v.y << ")"; 185 } 186 187 template<> std::ostream &operator<<(std::ostream &stream, cmplx const &v) 173 188 { 174 189 return stream << "(" << v.x << ", " << v.y << ")"; -
trunk/src/matrix.h
r1048 r1052 39 39 40 40 VECTOR_TYPES(Vec2, vec2) 41 VECTOR_TYPES(Cmplx, cmplx) 41 42 VECTOR_TYPES(Vec3, vec3) 42 43 VECTOR_TYPES(Vec4, vec4) … … 117 118 \ 118 119 void printf() const; 120 121 #define COMPLEX_OPS() \ 122 inline type_t operator *(type_t const &val) const \ 123 { \ 124 return type_t(x * val.x - y * val.y, x * val.y + y * val.x); \ 125 } \ 126 \ 127 inline type_t operator *=(type_t const &val) \ 128 { \ 129 return *this = (*this) * val; \ 130 } \ 131 \ 132 inline type_t operator ~() const \ 133 { \ 134 return type_t(x, -y); \ 135 } \ 136 \ 137 inline T norm() const { return len(); } 119 138 120 139 #define QUATERNION_OPS() \ … … 259 278 260 279 /* 280 * 2-element complexes 281 */ 282 283 template <typename T> struct Cmplx 284 { 285 typedef Cmplx<T> type_t; 286 287 inline Cmplx() { } 288 inline Cmplx(T val) : x(val), y(0) { } 289 inline Cmplx(T _x, T _y) : x(_x), y(_y) { } 290 291 LINEAR_OPS() 292 COMPLEX_OPS() 293 294 #if !defined __ANDROID__ 295 template<typename U> 296 friend std::ostream &operator<<(std::ostream &stream, Cmplx<U> const &v); 297 #endif 298 299 T x, y; 300 }; 301 302 template<typename T> 303 static inline Cmplx<T> re(Cmplx<T> const &val) 304 { 305 return ~val / val.sqlen(); 306 } 307 308 template<typename T> 309 static inline Cmplx<T> operator /(T x, Cmplx<T> const &y) 310 { 311 return x * re(y); 312 } 313 314 template<typename T> 315 static inline Cmplx<T> operator /(Cmplx<T> x, Cmplx<T> const &y) 316 { 317 return x * re(y); 318 } 319 320 /* 261 321 * 3-element vectors 262 322 */ … … 400 460 401 461 GLOBALS(Vec2) 462 GLOBALS(Cmplx) 402 463 GLOBALS(Vec3) 403 464 GLOBALS(Vec4) -
trunk/test/Makefile.am
r1047 r1052 25 25 testsuite_SOURCES = testsuite.cpp \ 26 26 unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp \ 27 unit/real.cpp unit/image.cpp unit/quat.cpp 27 unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp 28 28 testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ 29 29 testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
Note: See TracChangeset
for help on using the changeset viewer.