summaryrefslogtreecommitdiff
path: root/cad/src/experimental/oleksandr/box.h
blob: 84982a4dc2c35249b72e9fbb9114f3a7761a73c6 (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
// Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details. 
/*
  Name: box.h
  Author: Oleksandr Shevchenko
  Description: class for box representation
*/

#if !defined(BOX_INCLUDED)
#define BOX_INCLUDED

#include "interval.h"
#include "triple.h"

class Box
{

  public:

	//------------------------------------------------------------------------
	// Constructor
	//
	//  empty Box
	//
	inline Box();

	//------------------------------------------------------------------------
	// Constructor
	//
	//  Box (interval, interval, interval) constructor
	//
	inline Box(
		const Interval & x,
		const Interval & y,
		const Interval & z);

	//------------------------------------------------------------------------
	// Center()
	//
	// calculate center
	//
	inline Triple Center() const;

	//------------------------------------------------------------------------
	// Contains()
	//
	// box contains point
	//
	inline int Contains(
		const Triple & p) const;

	//------------------------------------------------------------------------
	// Empty()
	//
	// clear rectangle
	//
	inline void Empty();

	//------------------------------------------------------------------------
	// Enclose()
	//
	// adjust rectangle
	//
	inline void Enclose(
		const Triple & p);

	//------------------------------------------------------------------------
	// Extent()
	//
	// calculate extent
	//
	inline Triple Extent() const;

	//------------------------------------------------------------------------
	// Max()
	//
	//  get max point
	//
	inline Triple Max() const;

	//------------------------------------------------------------------------
	// Min()
	//
	//  get min point
	//
	inline Triple Min() const;

  private:

	//------------------------------------------------------------------------
	// mX

	Interval mX;						// interval for X

	//------------------------------------------------------------------------
	// mY

	Interval mY;						// interval for Y

	//------------------------------------------------------------------------
	// mZ

	Interval mZ;						// interval for Z
};

//----------------------------------------------------------------------------
// Constructor

inline Box::Box()
{

}

//----------------------------------------------------------------------------
// Constructor

inline Box::Box(
	const Interval & x,
	const Interval & y,
	const Interval & z):

	mX(									// interval for X
		x),
	mY(									// interval for Y
		y),
	mZ(									// interval for Z
		z)
{

}

//----------------------------------------------------------------------------
// Center()

inline Triple Box::Center() const
{
	return Triple(mX.Center(),mY.Center(),mZ.Center());
}

//----------------------------------------------------------------------------
// Contains()

inline int Box::Contains(
	const Triple & p) const
{
	return (mX.Contains(p.X()) && mY.Contains(p.Y()) && mZ.Contains(p.Z()));
}

//----------------------------------------------------------------------------
// Empty()

inline void Box::Empty()
{
	mX.Empty();
	mY.Empty();
	mZ.Empty();
}

//----------------------------------------------------------------------------
// Enclose()

inline void Box::Enclose(
	const Triple & p)
{
	mX.Enclose(p.X());
	mY.Enclose(p.Y());
	mZ.Enclose(p.Z());
}

//----------------------------------------------------------------------------
// Extent()

inline Triple Box::Extent() const
{
	return Triple(mX.Extent(),mY.Extent(),mZ.Extent());
}

//----------------------------------------------------------------------------
// Max()

inline Triple Box::Max() const
{
	return Triple(mX.Max(),mY.Max(),mZ.Max());
}

//----------------------------------------------------------------------------
// Min()

inline Triple Box::Min() const
{
	return Triple(mX.Min(),mY.Min(),mZ.Min());
}
#endif  								// BOX_INCLUDED