1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_RANGE_B3DRANGE_HXX
25 #define _BGFX_RANGE_B3DRANGE_HXX
26 
27 #include <basegfx/vector/b3dvector.hxx>
28 #include <basegfx/point/b3dpoint.hxx>
29 #include <basegfx/tuple/b3dtuple.hxx>
30 #include <basegfx/range/basicrange.hxx>
31 #include <basegfx/basegfxdllapi.h>
32 
33 namespace basegfx
34 {
35 	// predeclarations
36 	class B3IRange;
37 	class B3DHomMatrix;
38 
39 	class BASEGFX_DLLPUBLIC B3DRange
40 	{
41         typedef ::basegfx::BasicRange< double, DoubleTraits >	MyBasicRange;
42 
43 		MyBasicRange			maRangeX;
44 		MyBasicRange			maRangeY;
45 		MyBasicRange			maRangeZ;
46 
47 	public:
B3DRange()48 		B3DRange()
49 		{
50 		}
51 
B3DRange(const B3DTuple & rTuple)52 		explicit B3DRange(const B3DTuple& rTuple)
53 		:	maRangeX(rTuple.getX()),
54 			maRangeY(rTuple.getY()),
55 			maRangeZ(rTuple.getZ())
56 		{
57 		}
58 
B3DRange(double x1,double y1,double z1,double x2,double y2,double z2)59 		B3DRange(double x1,
60                  double y1,
61                  double z1,
62                  double x2,
63                  double y2,
64                  double z2)
65 		:	maRangeX(x1),
66 			maRangeY(y1),
67 			maRangeZ(z1)
68 		{
69 			maRangeX.expand(x2);
70 			maRangeY.expand(y2);
71 			maRangeZ.expand(z2);
72 		}
73 
B3DRange(const B3DTuple & rTuple1,const B3DTuple & rTuple2)74 		B3DRange(const B3DTuple& rTuple1,
75                  const B3DTuple& rTuple2)
76 		:	maRangeX(rTuple1.getX()),
77 			maRangeY(rTuple1.getY()),
78 			maRangeZ(rTuple1.getZ())
79 		{
80             expand(rTuple2);
81 		}
82 
B3DRange(const B3DRange & rRange)83 		B3DRange(const B3DRange& rRange)
84 		:	maRangeX(rRange.maRangeX),
85 			maRangeY(rRange.maRangeY),
86 			maRangeZ(rRange.maRangeZ)
87 		{
88 		}
89 
90 		explicit B3DRange(const B3IRange& rRange);
91 
isEmpty() const92 		bool isEmpty() const
93 		{
94 			return (
95 				maRangeX.isEmpty()
96 				|| maRangeY.isEmpty()
97 				|| maRangeZ.isEmpty()
98 				);
99 		}
100 
reset()101 		void reset()
102 		{
103 			maRangeX.reset();
104 			maRangeY.reset();
105 			maRangeZ.reset();
106 		}
107 
operator ==(const B3DRange & rRange) const108 		bool operator==( const B3DRange& rRange ) const
109 		{
110 			return (maRangeX == rRange.maRangeX
111 				&& maRangeY == rRange.maRangeY
112 				&& maRangeZ == rRange.maRangeZ);
113 		}
114 
operator !=(const B3DRange & rRange) const115 		bool operator!=( const B3DRange& rRange ) const
116 		{
117 			return (maRangeX != rRange.maRangeX
118 				|| maRangeY != rRange.maRangeY
119 				|| maRangeZ != rRange.maRangeZ);
120 		}
121 
operator =(const B3DRange & rRange)122 		B3DRange& operator=(const B3DRange& rRange)
123 		{
124 			maRangeX = rRange.maRangeX;
125 			maRangeY = rRange.maRangeY;
126 			maRangeZ = rRange.maRangeZ;
127 			return *this;
128 		}
129 
equal(const B3DRange & rRange) const130 		bool equal(const B3DRange& rRange) const
131         {
132 			return (maRangeX.equal(rRange.maRangeX)
133                     && maRangeY.equal(rRange.maRangeY)
134                     && maRangeZ.equal(rRange.maRangeZ));
135         }
136 
getMinX() const137         double getMinX() const
138         {
139             return maRangeX.getMinimum();
140         }
141 
getMinY() const142         double getMinY() const
143         {
144             return maRangeY.getMinimum();
145         }
146 
getMinZ() const147         double getMinZ() const
148         {
149             return maRangeZ.getMinimum();
150         }
151 
getMaxX() const152         double getMaxX() const
153         {
154             return maRangeX.getMaximum();
155         }
156 
getMaxY() const157         double getMaxY() const
158         {
159             return maRangeY.getMaximum();
160         }
161 
getMaxZ() const162         double getMaxZ() const
163         {
164             return maRangeZ.getMaximum();
165         }
166 
getWidth() const167         double getWidth() const
168         {
169             return maRangeX.getRange();
170         }
171 
getHeight() const172         double getHeight() const
173         {
174             return maRangeY.getRange();
175         }
176 
getDepth() const177         double getDepth() const
178         {
179             return maRangeZ.getRange();
180         }
181 
getMinimum() const182 		B3DPoint getMinimum() const
183 		{
184 			return B3DPoint(
185 				maRangeX.getMinimum(),
186 				maRangeY.getMinimum(),
187 				maRangeZ.getMinimum()
188 				);
189 		}
190 
getMaximum() const191 		B3DPoint getMaximum() const
192 		{
193 			return B3DPoint(
194 				maRangeX.getMaximum(),
195 				maRangeY.getMaximum(),
196 				maRangeZ.getMaximum()
197 				);
198 		}
199 
getRange() const200 		B3DVector getRange() const
201 		{
202 			return B3DVector(
203 				maRangeX.getRange(),
204 				maRangeY.getRange(),
205 				maRangeZ.getRange()
206 				);
207 		}
208 
getCenter() const209 		B3DPoint getCenter() const
210 		{
211 			return B3DPoint(
212 				maRangeX.getCenter(),
213 				maRangeY.getCenter(),
214 				maRangeZ.getCenter()
215 				);
216 		}
217 
getCenterX() const218 		double getCenterX() const
219 		{
220 			return maRangeX.getCenter();
221 		}
222 
getCenterY() const223 		double getCenterY() const
224 		{
225 			return maRangeY.getCenter();
226 		}
227 
getCenterZ() const228 		double getCenterZ() const
229 		{
230 			return maRangeZ.getCenter();
231 		}
232 
isInside(const B3DTuple & rTuple) const233 		bool isInside(const B3DTuple& rTuple) const
234 		{
235 			return (
236 				maRangeX.isInside(rTuple.getX())
237 				&& maRangeY.isInside(rTuple.getY())
238 				&& maRangeZ.isInside(rTuple.getZ())
239 				);
240 		}
241 
isInside(const B3DRange & rRange) const242 		bool isInside(const B3DRange& rRange) const
243 		{
244 			return (
245 				maRangeX.isInside(rRange.maRangeX)
246 				&& maRangeY.isInside(rRange.maRangeY)
247 				&& maRangeZ.isInside(rRange.maRangeZ)
248 				);
249 		}
250 
overlaps(const B3DRange & rRange) const251 		bool overlaps(const B3DRange& rRange) const
252 		{
253 			return (
254 				maRangeX.overlaps(rRange.maRangeX)
255 				&& maRangeY.overlaps(rRange.maRangeY)
256 				&& maRangeZ.overlaps(rRange.maRangeZ)
257 				);
258 		}
259 
expand(const B3DTuple & rTuple)260 		void expand(const B3DTuple& rTuple)
261 		{
262 			maRangeX.expand(rTuple.getX());
263 			maRangeY.expand(rTuple.getY());
264 			maRangeZ.expand(rTuple.getZ());
265 		}
266 
expand(const B3DRange & rRange)267 		void expand(const B3DRange& rRange)
268 		{
269 			maRangeX.expand(rRange.maRangeX);
270 			maRangeY.expand(rRange.maRangeY);
271 			maRangeZ.expand(rRange.maRangeZ);
272 		}
273 
intersect(const B3DRange & rRange)274 		void intersect(const B3DRange& rRange)
275 		{
276 			maRangeX.intersect(rRange.maRangeX);
277 			maRangeY.intersect(rRange.maRangeY);
278 			maRangeZ.intersect(rRange.maRangeZ);
279 		}
280 
grow(double fValue)281 		void grow(double fValue)
282 		{
283 			maRangeX.grow(fValue);
284 			maRangeY.grow(fValue);
285 			maRangeZ.grow(fValue);
286 		}
287 
288 		void transform(const B3DHomMatrix& rMatrix);
289 	};
290 
291 	/** Round double to nearest integer for 3D range
292 
293 		@return the nearest integer for this range
294 	*/
295 	BASEGFX_DLLPUBLIC B3IRange fround(const B3DRange& rRange);
296 } // end of namespace basegfx
297 
298 
299 #endif /* _BGFX_RANGE_B3DRANGE_HXX */
300