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_B3IRANGE_HXX
25 #define _BGFX_RANGE_B3IRANGE_HXX
26 
27 #include <basegfx/point/b3ipoint.hxx>
28 #include <basegfx/point/b3dpoint.hxx>
29 #include <basegfx/tuple/b3ituple.hxx>
30 #include <basegfx/tuple/b3i64tuple.hxx>
31 #include <basegfx/range/basicrange.hxx>
32 #include <basegfx/basegfxdllapi.h>
33 
34 namespace basegfx
35 {
36 	class BASEGFX_DLLPUBLIC B3IRange
37 	{
38         typedef ::basegfx::BasicRange< sal_Int32, Int32Traits >	MyBasicRange;
39 
40 		MyBasicRange			maRangeX;
41 		MyBasicRange			maRangeY;
42 		MyBasicRange			maRangeZ;
43 
44 	public:
B3IRange()45 		B3IRange()
46 		{
47 		}
48 
B3IRange(const B3ITuple & rTuple)49 		explicit B3IRange(const B3ITuple& rTuple)
50 		:	maRangeX(rTuple.getX()),
51 			maRangeY(rTuple.getY()),
52 			maRangeZ(rTuple.getZ())
53 		{
54 		}
55 
B3IRange(sal_Int32 x1,sal_Int32 y1,sal_Int32 z1,sal_Int32 x2,sal_Int32 y2,sal_Int32 z2)56 		B3IRange(sal_Int32 x1,
57                  sal_Int32 y1,
58                  sal_Int32 z1,
59                  sal_Int32 x2,
60                  sal_Int32 y2,
61                  sal_Int32 z2)
62 		:	maRangeX(x1),
63 			maRangeY(y1),
64 			maRangeZ(z1)
65 		{
66 			maRangeX.expand(x2);
67 			maRangeY.expand(y2);
68 			maRangeZ.expand(z2);
69 		}
70 
B3IRange(const B3ITuple & rTuple1,const B3ITuple & rTuple2)71 		B3IRange(const B3ITuple& rTuple1,
72                  const B3ITuple& rTuple2)
73 		:	maRangeX(rTuple1.getX()),
74 			maRangeY(rTuple1.getY()),
75 			maRangeZ(rTuple1.getZ())
76 		{
77             expand(rTuple2);
78 		}
79 
B3IRange(const B3IRange & rRange)80 		B3IRange(const B3IRange& rRange)
81 		:	maRangeX(rRange.maRangeX),
82 			maRangeY(rRange.maRangeY),
83 			maRangeZ(rRange.maRangeZ)
84 		{
85 		}
86 
isEmpty() const87 		bool isEmpty() const
88 		{
89 			return maRangeX.isEmpty() || maRangeY.isEmpty() || maRangeZ.isEmpty();
90 		}
91 
reset()92 		void reset()
93 		{
94 			maRangeX.reset();
95 			maRangeY.reset();
96 			maRangeZ.reset();
97 		}
98 
operator ==(const B3IRange & rRange) const99 		bool operator==( const B3IRange& rRange ) const
100 		{
101 			return (maRangeX == rRange.maRangeX
102 				&& maRangeY == rRange.maRangeY
103 				&& maRangeZ == rRange.maRangeZ);
104 		}
105 
operator !=(const B3IRange & rRange) const106 		bool operator!=( const B3IRange& rRange ) const
107 		{
108 			return (maRangeX != rRange.maRangeX
109 				|| maRangeY != rRange.maRangeY
110 				|| maRangeZ != rRange.maRangeZ);
111 		}
112 
operator =(const B3IRange & rRange)113 		B3IRange& operator=(const B3IRange& rRange)
114 		{
115 			maRangeX = rRange.maRangeX;
116 			maRangeY = rRange.maRangeY;
117 			maRangeZ = rRange.maRangeZ;
118 			return *this;
119 		}
120 
getMinX() const121         sal_Int32 getMinX() const
122         {
123             return maRangeX.getMinimum();
124         }
125 
getMinY() const126         sal_Int32 getMinY() const
127         {
128             return maRangeY.getMinimum();
129         }
130 
getMinZ() const131         sal_Int32 getMinZ() const
132         {
133             return maRangeZ.getMinimum();
134         }
135 
getMaxX() const136         sal_Int32 getMaxX() const
137         {
138             return maRangeX.getMaximum();
139         }
140 
getMaxY() const141         sal_Int32 getMaxY() const
142         {
143             return maRangeY.getMaximum();
144         }
145 
getMaxZ() const146         sal_Int32 getMaxZ() const
147         {
148             return maRangeZ.getMaximum();
149         }
150 
getWidth() const151         sal_Int64 getWidth() const
152         {
153             return maRangeX.getRange();
154         }
155 
getHeight() const156         sal_Int64 getHeight() const
157         {
158             return maRangeY.getRange();
159         }
160 
getDepth() const161         sal_Int64 getDepth() const
162         {
163             return maRangeZ.getRange();
164         }
165 
getMinimum() const166 		B3IPoint getMinimum() const
167 		{
168 			return B3IPoint(
169 				maRangeX.getMinimum(),
170 				maRangeY.getMinimum(),
171 				maRangeZ.getMinimum()
172 				);
173 		}
174 
getMaximum() const175 		B3IPoint getMaximum() const
176 		{
177 			return B3IPoint(
178 				maRangeX.getMaximum(),
179 				maRangeY.getMaximum(),
180 				maRangeZ.getMaximum()
181 				);
182 		}
183 
getRange() const184 		B3I64Tuple getRange() const
185 		{
186 			return B3I64Tuple(
187 				maRangeX.getRange(),
188 				maRangeY.getRange(),
189 				maRangeZ.getRange()
190 				);
191 		}
192 
getCenter() const193 		B3DPoint getCenter() const
194 		{
195 			return B3DPoint(
196 				maRangeX.getCenter(),
197 				maRangeY.getCenter(),
198 				maRangeZ.getCenter()
199 				);
200 		}
201 
isInside(const B3ITuple & rTuple) const202 		bool isInside(const B3ITuple& rTuple) const
203 		{
204 			return (
205 				maRangeX.isInside(rTuple.getX())
206 				&& maRangeY.isInside(rTuple.getY())
207 				&& maRangeZ.isInside(rTuple.getZ())
208 				);
209 		}
210 
isInside(const B3IRange & rRange) const211 		bool isInside(const B3IRange& rRange) const
212 		{
213 			return (
214 				maRangeX.isInside(rRange.maRangeX)
215 				&& maRangeY.isInside(rRange.maRangeY)
216 				&& maRangeZ.isInside(rRange.maRangeZ)
217 				);
218 		}
219 
overlaps(const B3IRange & rRange) const220 		bool overlaps(const B3IRange& rRange) const
221 		{
222 			return (
223 				maRangeX.overlaps(rRange.maRangeX)
224 				&& maRangeY.overlaps(rRange.maRangeY)
225 				&& maRangeZ.overlaps(rRange.maRangeZ)
226 				);
227 		}
228 
expand(const B3ITuple & rTuple)229 		void expand(const B3ITuple& rTuple)
230 		{
231 			maRangeX.expand(rTuple.getX());
232 			maRangeY.expand(rTuple.getY());
233 			maRangeZ.expand(rTuple.getZ());
234 		}
235 
expand(const B3IRange & rRange)236 		void expand(const B3IRange& rRange)
237 		{
238 			maRangeX.expand(rRange.maRangeX);
239 			maRangeY.expand(rRange.maRangeY);
240 			maRangeZ.expand(rRange.maRangeZ);
241 		}
242 
intersect(const B3IRange & rRange)243 		void intersect(const B3IRange& rRange)
244 		{
245 			maRangeX.intersect(rRange.maRangeX);
246 			maRangeY.intersect(rRange.maRangeY);
247 			maRangeZ.intersect(rRange.maRangeZ);
248 		}
249 
grow(sal_Int32 nValue)250 		void grow(sal_Int32 nValue)
251 		{
252 			maRangeX.grow(nValue);
253 			maRangeY.grow(nValue);
254 			maRangeZ.grow(nValue);
255 		}
256 	};
257 } // end of namespace basegfx
258 
259 #endif /* _BGFX_RANGE_B3IRANGE_HXX */
260