1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _BGFX_RANGE_B3DRANGE_HXX
29 #define _BGFX_RANGE_B3DRANGE_HXX
30 
31 #include <basegfx/vector/b3dvector.hxx>
32 #include <basegfx/point/b3dpoint.hxx>
33 #include <basegfx/tuple/b3dtuple.hxx>
34 #include <basegfx/range/basicrange.hxx>
35 
36 namespace basegfx
37 {
38 	// predeclarations
39 	class B3IRange;
40 	class B3DHomMatrix;
41 
42 	class B3DRange
43 	{
44         typedef ::basegfx::BasicRange< double, DoubleTraits >	MyBasicRange;
45 
46 		MyBasicRange			maRangeX;
47 		MyBasicRange			maRangeY;
48 		MyBasicRange			maRangeZ;
49 
50 	public:
51 		B3DRange()
52 		{
53 		}
54 
55 		explicit B3DRange(const B3DTuple& rTuple)
56 		:	maRangeX(rTuple.getX()),
57 			maRangeY(rTuple.getY()),
58 			maRangeZ(rTuple.getZ())
59 		{
60 		}
61 
62 		B3DRange(double x1,
63                  double y1,
64                  double z1,
65                  double x2,
66                  double y2,
67                  double z2)
68 		:	maRangeX(x1),
69 			maRangeY(y1),
70 			maRangeZ(z1)
71 		{
72 			maRangeX.expand(x2);
73 			maRangeY.expand(y2);
74 			maRangeZ.expand(z2);
75 		}
76 
77 		B3DRange(const B3DTuple& rTuple1,
78                  const B3DTuple& rTuple2)
79 		:	maRangeX(rTuple1.getX()),
80 			maRangeY(rTuple1.getY()),
81 			maRangeZ(rTuple1.getZ())
82 		{
83             expand(rTuple2);
84 		}
85 
86 		B3DRange(const B3DRange& rRange)
87 		:	maRangeX(rRange.maRangeX),
88 			maRangeY(rRange.maRangeY),
89 			maRangeZ(rRange.maRangeZ)
90 		{
91 		}
92 
93 		explicit B3DRange(const B3IRange& rRange);
94 
95 		bool isEmpty() const
96 		{
97 			return (
98 				maRangeX.isEmpty()
99 				|| maRangeY.isEmpty()
100 				|| maRangeZ.isEmpty()
101 				);
102 		}
103 
104 		void reset()
105 		{
106 			maRangeX.reset();
107 			maRangeY.reset();
108 			maRangeZ.reset();
109 		}
110 
111 		bool operator==( const B3DRange& rRange ) const
112 		{
113 			return (maRangeX == rRange.maRangeX
114 				&& maRangeY == rRange.maRangeY
115 				&& maRangeZ == rRange.maRangeZ);
116 		}
117 
118 		bool operator!=( const B3DRange& rRange ) const
119 		{
120 			return (maRangeX != rRange.maRangeX
121 				|| maRangeY != rRange.maRangeY
122 				|| maRangeZ != rRange.maRangeZ);
123 		}
124 
125 		B3DRange& operator=(const B3DRange& rRange)
126 		{
127 			maRangeX = rRange.maRangeX;
128 			maRangeY = rRange.maRangeY;
129 			maRangeZ = rRange.maRangeZ;
130 			return *this;
131 		}
132 
133 		bool equal(const B3DRange& rRange) const
134         {
135 			return (maRangeX.equal(rRange.maRangeX)
136                     && maRangeY.equal(rRange.maRangeY)
137                     && maRangeZ.equal(rRange.maRangeZ));
138         }
139 
140         double getMinX() const
141         {
142             return maRangeX.getMinimum();
143         }
144 
145         double getMinY() const
146         {
147             return maRangeY.getMinimum();
148         }
149 
150         double getMinZ() const
151         {
152             return maRangeZ.getMinimum();
153         }
154 
155         double getMaxX() const
156         {
157             return maRangeX.getMaximum();
158         }
159 
160         double getMaxY() const
161         {
162             return maRangeY.getMaximum();
163         }
164 
165         double getMaxZ() const
166         {
167             return maRangeZ.getMaximum();
168         }
169 
170         double getWidth() const
171         {
172             return maRangeX.getRange();
173         }
174 
175         double getHeight() const
176         {
177             return maRangeY.getRange();
178         }
179 
180         double getDepth() const
181         {
182             return maRangeZ.getRange();
183         }
184 
185 		B3DPoint getMinimum() const
186 		{
187 			return B3DPoint(
188 				maRangeX.getMinimum(),
189 				maRangeY.getMinimum(),
190 				maRangeZ.getMinimum()
191 				);
192 		}
193 
194 		B3DPoint getMaximum() const
195 		{
196 			return B3DPoint(
197 				maRangeX.getMaximum(),
198 				maRangeY.getMaximum(),
199 				maRangeZ.getMaximum()
200 				);
201 		}
202 
203 		B3DVector getRange() const
204 		{
205 			return B3DVector(
206 				maRangeX.getRange(),
207 				maRangeY.getRange(),
208 				maRangeZ.getRange()
209 				);
210 		}
211 
212 		B3DPoint getCenter() const
213 		{
214 			return B3DPoint(
215 				maRangeX.getCenter(),
216 				maRangeY.getCenter(),
217 				maRangeZ.getCenter()
218 				);
219 		}
220 
221 		double getCenterX() const
222 		{
223 			return maRangeX.getCenter();
224 		}
225 
226 		double getCenterY() const
227 		{
228 			return maRangeY.getCenter();
229 		}
230 
231 		double getCenterZ() const
232 		{
233 			return maRangeZ.getCenter();
234 		}
235 
236 		bool isInside(const B3DTuple& rTuple) const
237 		{
238 			return (
239 				maRangeX.isInside(rTuple.getX())
240 				&& maRangeY.isInside(rTuple.getY())
241 				&& maRangeZ.isInside(rTuple.getZ())
242 				);
243 		}
244 
245 		bool isInside(const B3DRange& rRange) const
246 		{
247 			return (
248 				maRangeX.isInside(rRange.maRangeX)
249 				&& maRangeY.isInside(rRange.maRangeY)
250 				&& maRangeZ.isInside(rRange.maRangeZ)
251 				);
252 		}
253 
254 		bool overlaps(const B3DRange& rRange) const
255 		{
256 			return (
257 				maRangeX.overlaps(rRange.maRangeX)
258 				&& maRangeY.overlaps(rRange.maRangeY)
259 				&& maRangeZ.overlaps(rRange.maRangeZ)
260 				);
261 		}
262 
263 		void expand(const B3DTuple& rTuple)
264 		{
265 			maRangeX.expand(rTuple.getX());
266 			maRangeY.expand(rTuple.getY());
267 			maRangeZ.expand(rTuple.getZ());
268 		}
269 
270 		void expand(const B3DRange& rRange)
271 		{
272 			maRangeX.expand(rRange.maRangeX);
273 			maRangeY.expand(rRange.maRangeY);
274 			maRangeZ.expand(rRange.maRangeZ);
275 		}
276 
277 		void intersect(const B3DRange& rRange)
278 		{
279 			maRangeX.intersect(rRange.maRangeX);
280 			maRangeY.intersect(rRange.maRangeY);
281 			maRangeZ.intersect(rRange.maRangeZ);
282 		}
283 
284 		void grow(double fValue)
285 		{
286 			maRangeX.grow(fValue);
287 			maRangeY.grow(fValue);
288 			maRangeZ.grow(fValue);
289 		}
290 
291 		void transform(const B3DHomMatrix& rMatrix);
292 	};
293 
294 	/** Round double to nearest integer for 3D range
295 
296 		@return the nearest integer for this range
297 	*/
298 	B3IRange fround(const B3DRange& rRange);
299 } // end of namespace basegfx
300 
301 
302 #endif /* _BGFX_RANGE_B3DRANGE_HXX */
303