2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
4 * Permission to use, copy, modify, distribute and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies.
7 * Erin Catto makes no representations about the suitability
8 * of this software for any purpose.
9 * It is provided "as is" without express or implied warranty.
11 module b2dlite
.mathutils
;
15 public alias Vec2
= VecN
!(2, float);
16 public alias VFloat
= Vec2
.VFloat
;
17 public alias VFloatNum
= Vec2
.VFloatNum
;
20 // ////////////////////////////////////////////////////////////////////////// //
29 import core
.stdc
.math
: cosf
, sinf
;
30 immutable VFloat c
= cosf(angle
), s
= sinf(angle
);
31 col1
.x
= c
; col1
.y
= s
;
32 col2
.x
= -s
; col2
.y
= c
;
36 this() (in auto ref Vec2 acol1
, in auto ref Vec2 acol2
) { pragma(inline
, true); col1
= acol1
; col2
= acol2
; }
38 Mat22
transpose () const { pragma(inline
, true); return Mat22(Vec2(col1
.x
, col2
.x
), Vec2(col1
.y
, col2
.y
)); }
40 Mat22
invert () const {
42 immutable VFloat a
= col1
.x
, b
= col2
.x
, c
= col1
.y
, d
= col2
.y
;
45 assert(det
!= VFloatNum
!(0.0));
46 det
= VFloatNum
!(1.0)/det
;
54 Vec2
opBinary(string op
:"*") (in auto ref Vec2 v
) const { pragma(inline
, true); return Vec2(col1
.x
*v
.x
+col2
.x
*v
.y
, col1
.y
*v
.x
+col2
.y
*v
.y
); }
56 Mat22
opBinary(string op
:"+") (in auto ref Mat22 B
) const { pragma(inline
, true); return Mat22(col1
+B
.col1
, col2
+B
.col2
); }
57 Mat22
opBinary(string op
:"*") (in auto ref Mat22 B
) const { pragma(inline
, true); return Mat22(this*B
.col1
, this*B
.col2
); }
59 Mat22
abs() () { pragma(inline
, true); return Mat22(col1
.abs
, col2
.abs
); }
63 // ////////////////////////////////////////////////////////////////////////// //
64 package(b2dlite
) Vec2
fcross() (VFloat s
, in auto ref Vec2 a
) { pragma(inline
, true); return Vec2(-s
*a
.y
, s
*a
.x
); }