40 |
template <class T>class Vector; |
template <class T>class Vector; |
41 |
template <class T>class Vector3; |
template <class T>class Vector3; |
42 |
|
|
43 |
|
inline float finitize(float f) { |
44 |
|
return finitef(f) ? f : 0; |
45 |
|
} |
46 |
|
|
47 |
/** A 2D vector. |
/** A 2D vector. |
48 |
*/ |
*/ |
49 |
template <class T>class Vector { |
template <class T>class Vector { |
63 |
/** Create from an array. |
/** Create from an array. |
64 |
*/ |
*/ |
65 |
Vector(T *v) : x(v[0]), y(v[1]) { } |
Vector(T *v) : x(v[0]), y(v[1]) { } |
66 |
|
|
67 |
|
/** Making all components finite. |
68 |
|
*/ |
69 |
|
Vector finitized() const { |
70 |
|
return Vector(finitize(x), finitize(y)); |
71 |
|
} |
72 |
|
|
73 |
/** Multiplication by scalar. |
/** Multiplication by scalar. |
74 |
*/ |
*/ |
75 |
Vector operator*(const double &s) const { return Vector(s * x, s * y); } |
Vector operator*(const double &s) const { return Vector(s * x, s * y); } |
128 |
/** From a 2D vector and an optional Z-component. |
/** From a 2D vector and an optional Z-component. |
129 |
*/ |
*/ |
130 |
Vector3(const Vector<T> &v, float z = 0) : x(v.x), y(v.y), z(z) { } |
Vector3(const Vector<T> &v, float z = 0) : x(v.x), y(v.y), z(z) { } |
131 |
|
|
132 |
|
/** Making all components finite. |
133 |
|
*/ |
134 |
|
Vector3 finitized() const { |
135 |
|
return Vector3(finitize(x), finitize(y), finitize(z)); |
136 |
|
} |
137 |
|
|
138 |
/** Multiplication by scalar. |
/** Multiplication by scalar. |
139 |
*/ |
*/ |