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_B2IBOX_HXX 25 #define _BGFX_RANGE_B2IBOX_HXX 26 27 #include <basegfx/point/b2ipoint.hxx> 28 #include <basegfx/point/b2dpoint.hxx> 29 #include <basegfx/tuple/b2ituple.hxx> 30 #include <basegfx/tuple/b2i64tuple.hxx> 31 #include <basegfx/range/basicbox.hxx> 32 #include <vector> 33 #include <basegfx/basegfxdllapi.h> 34 35 36 namespace basegfx 37 { 38 class BASEGFX_DLLPUBLIC B2IBox 39 { 40 public: 41 typedef sal_Int32 ValueType; 42 typedef Int32Traits TraitsType; 43 B2IBox()44 B2IBox() 45 { 46 } 47 B2IBox(const B2ITuple & rTuple)48 explicit B2IBox(const B2ITuple& rTuple) 49 : maRangeX(rTuple.getX()), 50 maRangeY(rTuple.getY()) 51 { 52 } 53 B2IBox(sal_Int32 x1,sal_Int32 y1,sal_Int32 x2,sal_Int32 y2)54 B2IBox(sal_Int32 x1, 55 sal_Int32 y1, 56 sal_Int32 x2, 57 sal_Int32 y2) : 58 maRangeX(x1), 59 maRangeY(y1) 60 { 61 maRangeX.expand(x2); 62 maRangeY.expand(y2); 63 } 64 B2IBox(const B2ITuple & rTuple1,const B2ITuple & rTuple2)65 B2IBox(const B2ITuple& rTuple1, 66 const B2ITuple& rTuple2) : 67 maRangeX(rTuple1.getX()), 68 maRangeY(rTuple1.getY()) 69 { 70 expand( rTuple2 ); 71 } 72 B2IBox(const B2IBox & rBox)73 B2IBox(const B2IBox& rBox) : 74 maRangeX(rBox.maRangeX), 75 maRangeY(rBox.maRangeY) 76 { 77 } 78 isEmpty() const79 bool isEmpty() const 80 { 81 return maRangeX.isEmpty() || maRangeY.isEmpty(); 82 } 83 reset()84 void reset() 85 { 86 maRangeX.reset(); 87 maRangeY.reset(); 88 } 89 operator ==(const B2IBox & rBox) const90 bool operator==( const B2IBox& rBox ) const 91 { 92 return (maRangeX == rBox.maRangeX 93 && maRangeY == rBox.maRangeY); 94 } 95 operator !=(const B2IBox & rBox) const96 bool operator!=( const B2IBox& rBox ) const 97 { 98 return (maRangeX != rBox.maRangeX 99 || maRangeY != rBox.maRangeY); 100 } 101 operator =(const B2IBox & rBox)102 void operator=(const B2IBox& rBox) 103 { 104 maRangeX = rBox.maRangeX; 105 maRangeY = rBox.maRangeY; 106 } 107 getMinX() const108 sal_Int32 getMinX() const 109 { 110 return maRangeX.getMinimum(); 111 } 112 getMinY() const113 sal_Int32 getMinY() const 114 { 115 return maRangeY.getMinimum(); 116 } 117 getMaxX() const118 sal_Int32 getMaxX() const 119 { 120 return maRangeX.getMaximum(); 121 } 122 getMaxY() const123 sal_Int32 getMaxY() const 124 { 125 return maRangeY.getMaximum(); 126 } 127 getWidth() const128 sal_Int64 getWidth() const 129 { 130 return maRangeX.getRange(); 131 } 132 getHeight() const133 sal_Int64 getHeight() const 134 { 135 return maRangeY.getRange(); 136 } 137 getMinimum() const138 B2IPoint getMinimum() const 139 { 140 return B2IPoint( 141 maRangeX.getMinimum(), 142 maRangeY.getMinimum() 143 ); 144 } 145 getMaximum() const146 B2IPoint getMaximum() const 147 { 148 return B2IPoint( 149 maRangeX.getMaximum(), 150 maRangeY.getMaximum() 151 ); 152 } 153 getRange() const154 B2I64Tuple getRange() const 155 { 156 return B2I64Tuple( 157 maRangeX.getRange(), 158 maRangeY.getRange() 159 ); 160 } 161 getCenter() const162 B2DPoint getCenter() const 163 { 164 return B2DPoint( 165 maRangeX.getCenter(), 166 maRangeY.getCenter() 167 ); 168 } 169 isInside(const B2ITuple & rTuple) const170 bool isInside(const B2ITuple& rTuple) const 171 { 172 return ( 173 maRangeX.isInside(rTuple.getX()) 174 && maRangeY.isInside(rTuple.getY()) 175 ); 176 } 177 isInside(const B2IBox & rBox) const178 bool isInside(const B2IBox& rBox) const 179 { 180 return ( 181 maRangeX.isInside(rBox.maRangeX) 182 && maRangeY.isInside(rBox.maRangeY) 183 ); 184 } 185 overlaps(const B2IBox & rBox) const186 bool overlaps(const B2IBox& rBox) const 187 { 188 return ( 189 maRangeX.overlaps(rBox.maRangeX) 190 && maRangeY.overlaps(rBox.maRangeY) 191 ); 192 } 193 expand(const B2ITuple & rTuple)194 void expand(const B2ITuple& rTuple) 195 { 196 maRangeX.expand(rTuple.getX()); 197 maRangeY.expand(rTuple.getY()); 198 } 199 expand(const B2IBox & rBox)200 void expand(const B2IBox& rBox) 201 { 202 maRangeX.expand(rBox.maRangeX); 203 maRangeY.expand(rBox.maRangeY); 204 } 205 intersect(const B2IBox & rBox)206 void intersect(const B2IBox& rBox) 207 { 208 maRangeX.intersect(rBox.maRangeX); 209 maRangeY.intersect(rBox.maRangeY); 210 } 211 grow(sal_Int32 nValue)212 void grow(sal_Int32 nValue) 213 { 214 maRangeX.grow(nValue); 215 maRangeY.grow(nValue); 216 } 217 218 private: 219 BasicBox maRangeX; 220 BasicBox maRangeY; 221 }; 222 223 /** Compute the set difference of the two given boxes 224 225 This method calculates the symmetric difference (aka XOR) 226 between the two given boxes, and returning the resulting 227 boxes. Thus, the result will contain all areas where one, but 228 not both boxes lie. 229 230 @param o_rResult 231 Result vector. The up to four difference boxes are returned 232 within this vector 233 234 @param rFirst 235 The first box 236 237 @param rSecond 238 The second box 239 240 @return the input vector 241 */ 242 ::std::vector< B2IBox >& computeSetDifference( ::std::vector< B2IBox >& o_rResult, 243 const B2IBox& rFirst, 244 const B2IBox& rSecond ); 245 246 } // end of namespace basegfx 247 248 #endif /* _BGFX_RANGE_B2IBOX_HXX */ 249