blob: 7b9f275d1fa6c6b10f7fc1efaaaf9fb2fd663a0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
//-----------------------------------------------------------------------------
// BSPLIB HEADER: Vector2.h
//
// Copyright (c) 1997 by Markus Hadwiger
// All Rights Reserved.
//-----------------------------------------------------------------------------
#ifndef _VECTOR2_H_
#define _VECTOR2_H_
// bsplib header files
#include "BspLibDefs.h"
#include "Vertex2.h"
BSPLIB_NAMESPACE_BEGIN
// vector times scalar (post-multiply) ----------------------------------------
inline Vector2 operator *( const Vector2 v1, double t )
{
return Vector2( v1.X * t, v1.Y * t, 1.0 );
}
// scalar times vector (pre-multiply) -----------------------------------------
inline Vector2 operator *( double t, const Vector2 v1 )
{
return Vector2( v1.X * t, v1.Y * t, 1.0 );
}
// operator '+=' does memberwise addition for (X,Y) ---------------------------
inline Vector2& Vector2::operator +=( const Vector2 v )
{
X += v.X;
Y += v.Y;
return *this;
}
// operator '-=' does memberwise subtraction for (X,Y) ------------------------
inline Vector2& Vector2::operator -=( const Vector2 v )
{
X -= v.X;
Y -= v.Y;
return *this;
}
// operator '*=' does multiplication with a scalar ----------------------------
inline Vector2& Vector2::operator *=( double t )
{
X *= t;
Y *= t;
return *this;
}
// normalize vector (homogeneous coordinate will be set to one) ---------------
inline int Vector2::Normalize()
{
if ( IsNullVector() )
return FALSE;
double oonorm = 1 / VecLength();
X = X * oonorm;
Y = Y * oonorm;
W = 1.0;
return TRUE;
}
// homogenize vector (divide by homogeneous coordinate) -----------------------
inline int Vector2::Homogenize()
{
if ( fabs( W ) < EPS_DENOM_ZERO )
return FALSE;
double oow = 1 / W;
X = X * oow;
Y = Y * oow;
W = 1.0;
return TRUE;
}
// check if vector has length zero (employs an epsilon area) ------------------
inline int Vector2::IsNullVector() const
{
// the epsilon area is employed componentwise, not for the length itself!
return ( ( fabs( X ) < EPS_COMP_ZERO ) && ( fabs( Y ) < EPS_COMP_ZERO ) );
}
// calculate length of two dimensional vector ---------------------------------
inline hprec_t Vector2::VecLength() const
{
return sqrt( X * X + Y * Y );
}
// calculate floating point scalar-product ------------------------------------
inline hprec_t Vector2::DotProduct( const Vector2& vect ) const
{
return ( vect.X * X ) + ( vect.Y * Y );
}
// calc vector directed from second vertex to first vertex --------------------
inline void Vector2::CreateDirVec( const Vertex2& vertex1, const Vertex2& vertex2 )
{
X = vertex2.X - vertex1.X;
Y = vertex2.Y - vertex1.Y;
W = 1.0;
}
BSPLIB_NAMESPACE_END
#endif // _VECTOR2_H_
|