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_B3IBOX_HXX
25 #define _BGFX_RANGE_B3IBOX_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/basicbox.hxx>
32 
33 namespace basegfx
34 {
35 	class B3IBox
36 	{
37 		BasicBox			maRangeX;
38 		BasicBox			maRangeY;
39 		BasicBox			maRangeZ;
40 
41 	public:
B3IBox()42 		B3IBox()
43 		{
44 		}
45 
B3IBox(const B3ITuple & rTuple)46 		explicit B3IBox(const B3ITuple& rTuple) :
47 			maRangeX(rTuple.getX()),
48 			maRangeY(rTuple.getY()),
49 			maRangeZ(rTuple.getZ())
50 		{
51 		}
52 
B3IBox(sal_Int32 x1,sal_Int32 y1,sal_Int32 z1,sal_Int32 x2,sal_Int32 y2,sal_Int32 z2)53 		B3IBox(sal_Int32 x1,
54                sal_Int32 y1,
55                sal_Int32 z1,
56                sal_Int32 x2,
57                sal_Int32 y2,
58                sal_Int32 z2) :
59 			maRangeX(x1),
60 			maRangeY(y1),
61 			maRangeZ(z1)
62 		{
63 			maRangeX.expand(x2);
64 			maRangeY.expand(y2);
65 			maRangeZ.expand(z2);
66 		}
67 
B3IBox(const B3ITuple & rTuple1,const B3ITuple & rTuple2)68 		B3IBox(const B3ITuple& rTuple1,
69                const B3ITuple& rTuple2) :
70 			maRangeX(rTuple1.getX()),
71 			maRangeY(rTuple1.getY()),
72 			maRangeZ(rTuple1.getZ())
73 		{
74             expand(rTuple2);
75 		}
76 
B3IBox(const B3IBox & rBox)77 		B3IBox(const B3IBox& rBox) :
78 			maRangeX(rBox.maRangeX),
79 			maRangeY(rBox.maRangeY),
80 			maRangeZ(rBox.maRangeZ)
81 		{
82 		}
83 
isEmpty() const84 		bool isEmpty() const
85 		{
86 			return maRangeX.isEmpty() || maRangeY.isEmpty() || maRangeZ.isEmpty();
87 		}
88 
reset()89 		void reset()
90 		{
91 			maRangeX.reset();
92 			maRangeY.reset();
93 			maRangeZ.reset();
94 		}
95 
operator ==(const B3IBox & rBox) const96 		bool operator==( const B3IBox& rBox ) const
97 		{
98 			return (maRangeX == rBox.maRangeX
99 				&& maRangeY == rBox.maRangeY
100 				&& maRangeZ == rBox.maRangeZ);
101 		}
102 
operator !=(const B3IBox & rBox) const103 		bool operator!=( const B3IBox& rBox ) const
104 		{
105 			return (maRangeX != rBox.maRangeX
106 				|| maRangeY != rBox.maRangeY
107 				|| maRangeZ != rBox.maRangeZ);
108 		}
109 
operator =(const B3IBox & rBox)110 		void operator=(const B3IBox& rBox)
111 		{
112 			maRangeX = rBox.maRangeX;
113 			maRangeY = rBox.maRangeY;
114 			maRangeZ = rBox.maRangeZ;
115 		}
116 
getMinX() const117         sal_Int32 getMinX() const
118         {
119             return maRangeX.getMinimum();
120         }
121 
getMinY() const122         sal_Int32 getMinY() const
123         {
124             return maRangeY.getMinimum();
125         }
126 
getMinZ() const127         sal_Int32 getMinZ() const
128         {
129             return maRangeZ.getMinimum();
130         }
131 
getMaxX() const132         sal_Int32 getMaxX() const
133         {
134             return maRangeX.getMaximum();
135         }
136 
getMaxY() const137         sal_Int32 getMaxY() const
138         {
139             return maRangeY.getMaximum();
140         }
141 
getMaxZ() const142         sal_Int32 getMaxZ() const
143         {
144             return maRangeZ.getMaximum();
145         }
146 
getWidth() const147         sal_Int64 getWidth() const
148         {
149             return maRangeX.getRange();
150         }
151 
getHeight() const152         sal_Int64 getHeight() const
153         {
154             return maRangeY.getRange();
155         }
156 
getDepth() const157         sal_Int64 getDepth() const
158         {
159             return maRangeZ.getRange();
160         }
161 
getMinimum() const162 		B3IPoint getMinimum() const
163 		{
164 			return B3IPoint(
165 				maRangeX.getMinimum(),
166 				maRangeY.getMinimum(),
167 				maRangeZ.getMinimum()
168 				);
169 		}
170 
getMaximum() const171 		B3IPoint getMaximum() const
172 		{
173 			return B3IPoint(
174 				maRangeX.getMaximum(),
175 				maRangeY.getMaximum(),
176 				maRangeZ.getMaximum()
177 				);
178 		}
179 
getRange() const180 		B3I64Tuple getRange() const
181 		{
182 			return B3I64Tuple(
183 				maRangeX.getRange(),
184 				maRangeY.getRange(),
185 				maRangeZ.getRange()
186 				);
187 		}
188 
getCenter() const189 		B3DPoint getCenter() const
190 		{
191 			return B3DPoint(
192 				maRangeX.getCenter(),
193 				maRangeY.getCenter(),
194 				maRangeZ.getCenter()
195 				);
196 		}
197 
isInside(const B3ITuple & rTuple) const198 		bool isInside(const B3ITuple& rTuple) const
199 		{
200 			return (
201 				maRangeX.isInside(rTuple.getX())
202 				&& maRangeY.isInside(rTuple.getY())
203 				&& maRangeZ.isInside(rTuple.getZ())
204 				);
205 		}
206 
isInside(const B3IBox & rBox) const207 		bool isInside(const B3IBox& rBox) const
208 		{
209 			return (
210 				maRangeX.isInside(rBox.maRangeX)
211 				&& maRangeY.isInside(rBox.maRangeY)
212 				&& maRangeZ.isInside(rBox.maRangeZ)
213 				);
214 		}
215 
overlaps(const B3IBox & rBox) const216 		bool overlaps(const B3IBox& rBox) const
217 		{
218 			return (
219 				maRangeX.overlaps(rBox.maRangeX)
220 				&& maRangeY.overlaps(rBox.maRangeY)
221 				&& maRangeZ.overlaps(rBox.maRangeZ)
222 				);
223 		}
224 
expand(const B3ITuple & rTuple)225 		void expand(const B3ITuple& rTuple)
226 		{
227 			maRangeX.expand(rTuple.getX());
228 			maRangeY.expand(rTuple.getY());
229 			maRangeZ.expand(rTuple.getZ());
230 		}
231 
expand(const B3IBox & rBox)232 		void expand(const B3IBox& rBox)
233 		{
234 			maRangeX.expand(rBox.maRangeX);
235 			maRangeY.expand(rBox.maRangeY);
236 			maRangeZ.expand(rBox.maRangeZ);
237 		}
238 
intersect(const B3IBox & rBox)239 		void intersect(const B3IBox& rBox)
240 		{
241 			maRangeX.intersect(rBox.maRangeX);
242 			maRangeY.intersect(rBox.maRangeY);
243 			maRangeZ.intersect(rBox.maRangeZ);
244 		}
245 
grow(sal_Int32 nValue)246 		void grow(sal_Int32 nValue)
247 		{
248 			maRangeX.grow(nValue);
249 			maRangeY.grow(nValue);
250 			maRangeZ.grow(nValue);
251 		}
252 	};
253 } // end of namespace basegfx
254 
255 #endif /* _BGFX_RANGE_B3IBOX_HXX */
256