aboutsummaryrefslogtreecommitdiff
path: root/tool_src/BspLib/Vertex.h
blob: 7a4db5f9345bfcd4d49c6ff468d83e747555bc65 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//-----------------------------------------------------------------------------
//	BSPLIB HEADER: Vertex.h
//
//  Copyright (c) 1997 by Markus Hadwiger
//  All Rights Reserved.
//-----------------------------------------------------------------------------

#ifndef _VERTEX_H_
#define _VERTEX_H_

// bsplib header files
#include "BspLibDefs.h"


BSPLIB_NAMESPACE_BEGIN


// single 3-D vertex ----------------------------------------------------------
//
class Vertex3 {

	friend class Vector3;
	friend class LineSeg3;

	friend int operator ==( const Vertex3 v1, const Vertex3 v2 );
	friend int operator !=( const Vertex3 v1, const Vertex3 v2 );

	friend class Vector3 operator -( const Vertex3 v1, const Vertex3 v2 );

	friend Vertex3 operator +( const Vertex3 v1, const class ector3 v2 );
	friend Vertex3 operator +( const class Vector3 v1, const Vertex3 v2 );
	friend Vertex3 operator -( const Vertex3 v1, const class Vector3 v2 );

public:
	Vertex3( hprec_t x = 0, hprec_t y = 0, hprec_t z = 0, hprec_t w = 1.0 );
	~Vertex3() { }

	Vertex3& operator +=( const Vector3 v );
	Vertex3& operator -=( const Vector3 v );

	int  IsInVicinity( const Vertex3& vertex ) const;
	void ChangeAxes( const char *xchangecmd, const Vertex3& ads );

	hprec_t getX() const { return X; }
	hprec_t getY() const { return Y; }
	hprec_t getZ() const { return Z; }
 	hprec_t getW() const { return W; }

	void setX( hprec_t x ) { X = x; }
	void setY( hprec_t y ) { Y = y; }
	void setZ( hprec_t z ) { Z = z; }
	void setW( hprec_t w ) { W = w; }
	hprec_t X;
	hprec_t Y;
	hprec_t Z;
	hprec_t W;

private:
	void ChangeAxis( const char xchar, const hprec_t src );

protected: 
};


// single 3-D vector ----------------------------------------------------------
//
class Vector3 : public Vertex3 {

	friend class LineSeg3;

	friend Vector3 operator -( const Vertex3 v1, const Vertex3 v2 );

	friend Vertex3 operator +( const Vertex3 v1, const Vector3 v2 );
	friend Vertex3 operator +( const Vector3 v1, const Vertex3 v2 );
	friend Vertex3 operator -( const Vertex3 v1, const Vector3 v2 );

	friend Vector3 operator +( const Vector3 v1, const Vector3 v2 );
	friend Vector3 operator -( const Vector3 v1, const Vector3 v2 );

	friend Vector3 operator *( const Vector3 v1, double t );
	friend Vector3 operator *( double t, const Vector3 v1 );

public:
	Vector3( hprec_t x = 0, hprec_t y = 0, hprec_t z = 0, hprec_t w = 1.0 )
		: Vertex3( x, y, z, w ) { }
	// initialize as direction vector
	Vector3( const Vertex3& v1, const Vertex3& v2 )
		: Vertex3( v2.X - v1.X, v2.Y - v1.Y, v2.Z - v1.Z ) { }
	// initialize as cross product
	Vector3( const Vector3& v1, const Vector3& v2 );
	// conversion from Vertex3
	Vector3( const Vertex3& vtx ) { *(Vertex3*)this = vtx; }
	~Vector3() { }

	Vector3& operator +=( const Vector3 v );
	Vector3& operator -=( const Vector3 v );

	Vector3& operator *=( double t );

	int			Normalize();
	int			Homogenize();
	int			IsNullVector() const;
	hprec_t		VecLength() const;
	hprec_t		DotProduct( const Vector3& vect ) const;
	void		CrossProduct( const Vector3& vect1, const Vector3& vect2 );
	void		CreateDirVec( const Vertex3& vertex1, const Vertex3& vertex2 );
};


// single 2-D vertex ----------------------------------------------------------
//
class Vertex2 {

	friend class Vector2;
	friend class LineSeg2;

	friend int operator ==( const Vertex2 v1, const Vertex2 v2 );
	friend int operator !=( const Vertex2 v1, const Vertex2 v2 );

	friend class Vector2 operator -( const Vertex2 v1, const Vertex2 v2 );

	friend Vertex2 operator +( const Vertex2 v1, const class Vector2 v2 );
	friend Vertex2 operator +( const class Vector2 v1, const Vertex2 v2 );
	friend Vertex2 operator -( const Vertex2 v1, const class Vector2 v2 );

public:
	Vertex2( hprec_t x = 0, hprec_t y = 0, hprec_t w = 1.0 ) { X = x; Y = y; W = w; }
	// conversion Vector2 -> Vertex2
	Vertex2( const Vector2& vect );
	~Vertex2() { }

	Vertex2& operator +=( const Vector2 v );
	Vertex2& operator -=( const Vector2 v );

	int  IsInVicinity( const Vertex2& vertex ) const;
	void InitFromVertex3( const Vertex3& vertex );

	hprec_t getX() const { return X; }
	hprec_t getY() const { return Y; }
 	hprec_t getW() const { return W; }

	void setX( hprec_t x ) { X = x; }
	void setY( hprec_t y ) { Y = y; }
	void setW( hprec_t w ) { W = w; }

protected:
	hprec_t X;
	hprec_t Y;
	hprec_t W;
};


// single 2-D vector ----------------------------------------------------------
//
class Vector2 : public Vertex2 {

	friend class LineSeg2;

	friend Vector2 operator -( const Vertex2 v1, const Vertex2 v2 );

	friend Vertex2 operator +( const Vertex2 v1, const Vector2 v2 );
	friend Vertex2 operator +( const Vector2 v1, const Vertex2 v2 );
	friend Vertex2 operator -( const Vertex2 v1, const Vector2 v2 );

	friend Vector2 operator +( const Vector2 v1, const Vector2 v2 );
	friend Vector2 operator -( const Vector2 v1, const Vector2 v2 );

	friend Vector2 operator *( const Vector2 v1, double t );
	friend Vector2 operator *( double t, const Vector2 v1 );

public:
	Vector2( hprec_t x = 0, hprec_t y = 0, hprec_t w = 1.0 )
		: Vertex2( x, y, w ) { }
	// initialize as direction vector
	Vector2( const Vertex2& v1, const Vertex2& v2 )
		: Vertex2( v2.X - v1.X, v2.Y - v1.Y ) { }
	// conversion from Vertex2
	Vector2( const Vertex2& vtx ) { *(Vertex2*)this = vtx; }
	~Vector2() { }

	Vector2& operator +=( const Vector2 v );
	Vector2& operator -=( const Vector2 v );

	Vector2& operator *=( double t );

	int			Normalize();
	int			Homogenize();
	int			IsNullVector() const;
	hprec_t		VecLength() const;
	hprec_t		DotProduct( const Vector2& vect ) const;
	void		CreateDirVec( const Vertex2& vertex, const Vertex2& dirvec );
};


BSPLIB_NAMESPACE_END


// include vector and lineseg capability, and chunks of vertices
#include "Vector.h"
#include "LineSeg2.h"
#include "LineSeg3.h"
#include "VertexChunk.h"


#endif // _VERTEX_H_