1
// Wild Magic Source Code
3
// http://www.geometrictools.com
4
// Copyright (c) 1998-2008
6
// This library is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License as published by
8
// the Free Software Foundation; either version 2.1 of the License, or (at
9
// your option) any later version. The license is available for reading at
10
// either of the locations:
11
// http://www.gnu.org/copyleft/lgpl.html
12
// http://www.geometrictools.com/License/WildMagicLicense.pdf
14
// Version: 4.0.3 (2007/03/07)
19
#include "Wm4FoundationLIB.h"
30
Vector2 (); // uninitialized
31
Vector2 (Real fX, Real fY);
32
Vector2 (const Real* afTuple);
33
Vector2 (const Vector2& rkV);
36
inline operator const Real* () const;
37
inline operator Real* ();
38
inline Real operator[] (int i) const;
39
inline Real& operator[] (int i);
40
inline Real X () const;
42
inline Real Y () const;
46
inline Vector2& operator= (const Vector2& rkV);
49
bool operator== (const Vector2& rkV) const;
50
bool operator!= (const Vector2& rkV) const;
51
bool operator< (const Vector2& rkV) const;
52
bool operator<= (const Vector2& rkV) const;
53
bool operator> (const Vector2& rkV) const;
54
bool operator>= (const Vector2& rkV) const;
56
// arithmetic operations
57
inline Vector2 operator+ (const Vector2& rkV) const;
58
inline Vector2 operator- (const Vector2& rkV) const;
59
inline Vector2 operator* (Real fScalar) const;
60
inline Vector2 operator/ (Real fScalar) const;
61
inline Vector2 operator- () const;
64
inline Vector2& operator+= (const Vector2& rkV);
65
inline Vector2& operator-= (const Vector2& rkV);
66
inline Vector2& operator*= (Real fScalar);
67
inline Vector2& operator/= (Real fScalar);
70
inline Real Length () const;
71
inline Real SquaredLength () const;
72
inline Real Dot (const Vector2& rkV) const;
73
inline Real Normalize ();
76
inline Vector2 Perp () const;
78
// returns (y,-x)/sqrt(x*x+y*y)
79
inline Vector2 UnitPerp () const;
81
// returns DotPerp((x,y),(V.x,V.y)) = x*V.y - y*V.x
82
inline Real DotPerp (const Vector2& rkV) const;
84
// Compute the barycentric coordinates of the point with respect to the
85
// triangle <V0,V1,V2>, P = b0*V0 + b1*V1 + b2*V2, where b0 + b1 + b2 = 1.
86
void GetBarycentrics (const Vector2& rkV0, const Vector2& rkV1,
87
const Vector2& rkV2, Real afBary[3]) const;
89
// Gram-Schmidt orthonormalization. Take linearly independent vectors U
90
// and V and compute an orthonormal set (unit length, mutually
92
static void Orthonormalize (Vector2& rkU, Vector2& rkV);
94
// Input V must be a nonzero vector. The output is an orthonormal basis
95
// {U,V}. The input V is normalized by this function. If you know V is
96
// already unit length, use U = V.Perp().
97
static void GenerateOrthonormalBasis (Vector2& rkU, Vector2& rkV);
99
// Compute the extreme values.
100
static void ComputeExtremes (int iVQuantity, const Vector2* akPoint,
101
Vector2& rkMin, Vector2& rkMax);
104
WM4_FOUNDATION_ITEM static const Vector2 ZERO; // (0,0)
105
WM4_FOUNDATION_ITEM static const Vector2 UNIT_X; // (1,0)
106
WM4_FOUNDATION_ITEM static const Vector2 UNIT_Y; // (0,1)
107
WM4_FOUNDATION_ITEM static const Vector2 ONE; // (1,1)
110
// support for comparisons
111
int CompareArrays (const Vector2& rkV) const;
116
// arithmetic operations
117
template <class Real>
118
Vector2<Real> operator* (Real fScalar, const Vector2<Real>& rkV);
121
template <class Real>
122
std::ostream& operator<< (std::ostream& rkOStr, const Vector2<Real>& rkV);
124
#include "Wm4Vector2.inl"
126
typedef Vector2<float> Vector2f;
127
typedef Vector2<double> Vector2d;
128
typedef Vector2<long double> Vector2ld;