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 
33 namespace basegfx
34 {
35 	class B3IRange
36 	{
37         typedef ::basegfx::BasicRange< sal_Int32, Int32Traits >	MyBasicRange;
38 
39 		MyBasicRange			maRangeX;
40 		MyBasicRange			maRangeY;
41 		MyBasicRange			maRangeZ;
42 
43 	public:
B3IRange()44 		B3IRange()
45 		{
46 		}
47 
B3IRange(const B3ITuple & rTuple)48 		explicit B3IRange(const B3ITuple& rTuple)
49 		:	maRangeX(rTuple.getX()),
50 			maRangeY(rTuple.getY()),
51 			maRangeZ(rTuple.getZ())
52 		{
53 		}
54 
B3IRange(sal_Int32 x1,sal_Int32 y1,sal_Int32 z1,sal_Int32 x2,sal_Int32 y2,sal_Int32 z2)55 		B3IRange(sal_Int32 x1,
56                  sal_Int32 y1,
57                  sal_Int32 z1,
58                  sal_Int32 x2,
59                  sal_Int32 y2,
60                  sal_Int32 z2)
61 		:	maRangeX(x1),
62 			maRangeY(y1),
63 			maRangeZ(z1)
64 		{
65 			maRangeX.expand(x2);
66 			maRangeY.expand(y2);
67 			maRangeZ.expand(z2);
68 		}
69 
B3IRange(const B3ITuple & rTuple1,const B3ITuple & rTuple2)70 		B3IRange(const B3ITuple& rTuple1,
71                  const B3ITuple& rTuple2)
72 		:	maRangeX(rTuple1.getX()),
73 			maRangeY(rTuple1.getY()),
74 			maRangeZ(rTuple1.getZ())
75 		{
76             expand(rTuple2);
77 		}
78 
B3IRange(const B3IRange & rRange)79 		B3IRange(const B3IRange& rRange)
80 		:	maRangeX(rRange.maRangeX),
81 			maRangeY(rRange.maRangeY),
82 			maRangeZ(rRange.maRangeZ)
83 		{
84 		}
85 
isEmpty() const86 		bool isEmpty() const
87 		{
88 			return maRangeX.isEmpty() || maRangeY.isEmpty() || maRangeZ.isEmpty();
89 		}
90 
reset()91 		void reset()
92 		{
93 			maRangeX.reset();
94 			maRangeY.reset();
95 			maRangeZ.reset();
96 		}
97 
operator ==(const B3IRange & rRange) const98 		bool operator==( const B3IRange& rRange ) const
99 		{
100 			return (maRangeX == rRange.maRangeX
101 				&& maRangeY == rRange.maRangeY
102 				&& maRangeZ == rRange.maRangeZ);
103 		}
104 
operator !=(const B3IRange & rRange) const105 		bool operator!=( const B3IRange& rRange ) const
106 		{
107 			return (maRangeX != rRange.maRangeX
108 				|| maRangeY != rRange.maRangeY
109 				|| maRangeZ != rRange.maRangeZ);
110 		}
111 
operator =(const B3IRange & rRange)112 		B3IRange& operator=(const B3IRange& rRange)
113 		{
114 			maRangeX = rRange.maRangeX;
115 			maRangeY = rRange.maRangeY;
116 			maRangeZ = rRange.maRangeZ;
117 			return *this;
118 		}
119 
getMinX() const120         sal_Int32 getMinX() const
121         {
122             return maRangeX.getMinimum();
123         }
124 
getMinY() const125         sal_Int32 getMinY() const
126         {
127             return maRangeY.getMinimum();
128         }
129 
getMinZ() const130         sal_Int32 getMinZ() const
131         {
132             return maRangeZ.getMinimum();
133         }
134 
getMaxX() const135         sal_Int32 getMaxX() const
136         {
137             return maRangeX.getMaximum();
138         }
139 
getMaxY() const140         sal_Int32 getMaxY() const
141         {
142             return maRangeY.getMaximum();
143         }
144 
getMaxZ() const145         sal_Int32 getMaxZ() const
146         {
147             return maRangeZ.getMaximum();
148         }
149 
getWidth() const150         sal_Int64 getWidth() const
151         {
152             return maRangeX.getRange();
153         }
154 
getHeight() const155         sal_Int64 getHeight() const
156         {
157             return maRangeY.getRange();
158         }
159 
getDepth() const160         sal_Int64 getDepth() const
161         {
162             return maRangeZ.getRange();
163         }
164 
getMinimum() const165 		B3IPoint getMinimum() const
166 		{
167 			return B3IPoint(
168 				maRangeX.getMinimum(),
169 				maRangeY.getMinimum(),
170 				maRangeZ.getMinimum()
171 				);
172 		}
173 
getMaximum() const174 		B3IPoint getMaximum() const
175 		{
176 			return B3IPoint(
177 				maRangeX.getMaximum(),
178 				maRangeY.getMaximum(),
179 				maRangeZ.getMaximum()
180 				);
181 		}
182 
getRange() const183 		B3I64Tuple getRange() const
184 		{
185 			return B3I64Tuple(
186 				maRangeX.getRange(),
187 				maRangeY.getRange(),
188 				maRangeZ.getRange()
189 				);
190 		}
191 
getCenter() const192 		B3DPoint getCenter() const
193 		{
194 			return B3DPoint(
195 				maRangeX.getCenter(),
196 				maRangeY.getCenter(),
197 				maRangeZ.getCenter()
198 				);
199 		}
200 
isInside(const B3ITuple & rTuple) const201 		bool isInside(const B3ITuple& rTuple) const
202 		{
203 			return (
204 				maRangeX.isInside(rTuple.getX())
205 				&& maRangeY.isInside(rTuple.getY())
206 				&& maRangeZ.isInside(rTuple.getZ())
207 				);
208 		}
209 
isInside(const B3IRange & rRange) const210 		bool isInside(const B3IRange& rRange) const
211 		{
212 			return (
213 				maRangeX.isInside(rRange.maRangeX)
214 				&& maRangeY.isInside(rRange.maRangeY)
215 				&& maRangeZ.isInside(rRange.maRangeZ)
216 				);
217 		}
218 
overlaps(const B3IRange & rRange) const219 		bool overlaps(const B3IRange& rRange) const
220 		{
221 			return (
222 				maRangeX.overlaps(rRange.maRangeX)
223 				&& maRangeY.overlaps(rRange.maRangeY)
224 				&& maRangeZ.overlaps(rRange.maRangeZ)
225 				);
226 		}
227 
expand(const B3ITuple & rTuple)228 		void expand(const B3ITuple& rTuple)
229 		{
230 			maRangeX.expand(rTuple.getX());
231 			maRangeY.expand(rTuple.getY());
232 			maRangeZ.expand(rTuple.getZ());
233 		}
234 
expand(const B3IRange & rRange)235 		void expand(const B3IRange& rRange)
236 		{
237 			maRangeX.expand(rRange.maRangeX);
238 			maRangeY.expand(rRange.maRangeY);
239 			maRangeZ.expand(rRange.maRangeZ);
240 		}
241 
intersect(const B3IRange & rRange)242 		void intersect(const B3IRange& rRange)
243 		{
244 			maRangeX.intersect(rRange.maRangeX);
245 			maRangeY.intersect(rRange.maRangeY);
246 			maRangeZ.intersect(rRange.maRangeZ);
247 		}
248 
grow(sal_Int32 nValue)249 		void grow(sal_Int32 nValue)
250 		{
251 			maRangeX.grow(nValue);
252 			maRangeY.grow(nValue);
253 			maRangeZ.grow(nValue);
254 		}
255 	};
256 } // end of namespace basegfx
257 
258 #endif /* _BGFX_RANGE_B3IRANGE_HXX */
259