xref: /trunk/main/basegfx/inc/basegfx/range/b3ibox.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
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 #include <basegfx/basegfxdllapi.h>
33 
34 namespace basegfx
35 {
36     class BASEGFX_DLLPUBLIC B3IBox
37     {
38         BasicBox            maRangeX;
39         BasicBox            maRangeY;
40         BasicBox            maRangeZ;
41 
42     public:
B3IBox()43         B3IBox()
44         {
45         }
46 
B3IBox(const B3ITuple & rTuple)47         explicit B3IBox(const B3ITuple& rTuple) :
48             maRangeX(rTuple.getX()),
49             maRangeY(rTuple.getY()),
50             maRangeZ(rTuple.getZ())
51         {
52         }
53 
B3IBox(sal_Int32 x1,sal_Int32 y1,sal_Int32 z1,sal_Int32 x2,sal_Int32 y2,sal_Int32 z2)54         B3IBox(sal_Int32 x1,
55                sal_Int32 y1,
56                sal_Int32 z1,
57                sal_Int32 x2,
58                sal_Int32 y2,
59                sal_Int32 z2) :
60             maRangeX(x1),
61             maRangeY(y1),
62             maRangeZ(z1)
63         {
64             maRangeX.expand(x2);
65             maRangeY.expand(y2);
66             maRangeZ.expand(z2);
67         }
68 
B3IBox(const B3ITuple & rTuple1,const B3ITuple & rTuple2)69         B3IBox(const B3ITuple& rTuple1,
70                const B3ITuple& rTuple2) :
71             maRangeX(rTuple1.getX()),
72             maRangeY(rTuple1.getY()),
73             maRangeZ(rTuple1.getZ())
74         {
75             expand(rTuple2);
76         }
77 
B3IBox(const B3IBox & rBox)78         B3IBox(const B3IBox& rBox) :
79             maRangeX(rBox.maRangeX),
80             maRangeY(rBox.maRangeY),
81             maRangeZ(rBox.maRangeZ)
82         {
83         }
84 
isEmpty() const85         bool isEmpty() const
86         {
87             return maRangeX.isEmpty() || maRangeY.isEmpty() || maRangeZ.isEmpty();
88         }
89 
reset()90         void reset()
91         {
92             maRangeX.reset();
93             maRangeY.reset();
94             maRangeZ.reset();
95         }
96 
operator ==(const B3IBox & rBox) const97         bool operator==( const B3IBox& rBox ) const
98         {
99             return (maRangeX == rBox.maRangeX
100                 && maRangeY == rBox.maRangeY
101                 && maRangeZ == rBox.maRangeZ);
102         }
103 
operator !=(const B3IBox & rBox) const104         bool operator!=( const B3IBox& rBox ) const
105         {
106             return (maRangeX != rBox.maRangeX
107                 || maRangeY != rBox.maRangeY
108                 || maRangeZ != rBox.maRangeZ);
109         }
110 
operator =(const B3IBox & rBox)111         void operator=(const B3IBox& rBox)
112         {
113             maRangeX = rBox.maRangeX;
114             maRangeY = rBox.maRangeY;
115             maRangeZ = rBox.maRangeZ;
116         }
117 
getMinX() const118         sal_Int32 getMinX() const
119         {
120             return maRangeX.getMinimum();
121         }
122 
getMinY() const123         sal_Int32 getMinY() const
124         {
125             return maRangeY.getMinimum();
126         }
127 
getMinZ() const128         sal_Int32 getMinZ() const
129         {
130             return maRangeZ.getMinimum();
131         }
132 
getMaxX() const133         sal_Int32 getMaxX() const
134         {
135             return maRangeX.getMaximum();
136         }
137 
getMaxY() const138         sal_Int32 getMaxY() const
139         {
140             return maRangeY.getMaximum();
141         }
142 
getMaxZ() const143         sal_Int32 getMaxZ() const
144         {
145             return maRangeZ.getMaximum();
146         }
147 
getWidth() const148         sal_Int64 getWidth() const
149         {
150             return maRangeX.getRange();
151         }
152 
getHeight() const153         sal_Int64 getHeight() const
154         {
155             return maRangeY.getRange();
156         }
157 
getDepth() const158         sal_Int64 getDepth() const
159         {
160             return maRangeZ.getRange();
161         }
162 
getMinimum() const163         B3IPoint getMinimum() const
164         {
165             return B3IPoint(
166                 maRangeX.getMinimum(),
167                 maRangeY.getMinimum(),
168                 maRangeZ.getMinimum()
169                 );
170         }
171 
getMaximum() const172         B3IPoint getMaximum() const
173         {
174             return B3IPoint(
175                 maRangeX.getMaximum(),
176                 maRangeY.getMaximum(),
177                 maRangeZ.getMaximum()
178                 );
179         }
180 
getRange() const181         B3I64Tuple getRange() const
182         {
183             return B3I64Tuple(
184                 maRangeX.getRange(),
185                 maRangeY.getRange(),
186                 maRangeZ.getRange()
187                 );
188         }
189 
getCenter() const190         B3DPoint getCenter() const
191         {
192             return B3DPoint(
193                 maRangeX.getCenter(),
194                 maRangeY.getCenter(),
195                 maRangeZ.getCenter()
196                 );
197         }
198 
isInside(const B3ITuple & rTuple) const199         bool isInside(const B3ITuple& rTuple) const
200         {
201             return (
202                 maRangeX.isInside(rTuple.getX())
203                 && maRangeY.isInside(rTuple.getY())
204                 && maRangeZ.isInside(rTuple.getZ())
205                 );
206         }
207 
isInside(const B3IBox & rBox) const208         bool isInside(const B3IBox& rBox) const
209         {
210             return (
211                 maRangeX.isInside(rBox.maRangeX)
212                 && maRangeY.isInside(rBox.maRangeY)
213                 && maRangeZ.isInside(rBox.maRangeZ)
214                 );
215         }
216 
overlaps(const B3IBox & rBox) const217         bool overlaps(const B3IBox& rBox) const
218         {
219             return (
220                 maRangeX.overlaps(rBox.maRangeX)
221                 && maRangeY.overlaps(rBox.maRangeY)
222                 && maRangeZ.overlaps(rBox.maRangeZ)
223                 );
224         }
225 
expand(const B3ITuple & rTuple)226         void expand(const B3ITuple& rTuple)
227         {
228             maRangeX.expand(rTuple.getX());
229             maRangeY.expand(rTuple.getY());
230             maRangeZ.expand(rTuple.getZ());
231         }
232 
expand(const B3IBox & rBox)233         void expand(const B3IBox& rBox)
234         {
235             maRangeX.expand(rBox.maRangeX);
236             maRangeY.expand(rBox.maRangeY);
237             maRangeZ.expand(rBox.maRangeZ);
238         }
239 
intersect(const B3IBox & rBox)240         void intersect(const B3IBox& rBox)
241         {
242             maRangeX.intersect(rBox.maRangeX);
243             maRangeY.intersect(rBox.maRangeY);
244             maRangeZ.intersect(rBox.maRangeZ);
245         }
246 
grow(sal_Int32 nValue)247         void grow(sal_Int32 nValue)
248         {
249             maRangeX.grow(nValue);
250             maRangeY.grow(nValue);
251             maRangeZ.grow(nValue);
252         }
253     };
254 } // end of namespace basegfx
255 
256 #endif /* _BGFX_RANGE_B3IBOX_HXX */
257