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_B2IRANGE_HXX 25 #define _BGFX_RANGE_B2IRANGE_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/basicrange.hxx> 32 #include <vector> 33 34 35 namespace basegfx 36 { 37 class B2IRange 38 { 39 public: 40 typedef sal_Int32 ValueType; 41 typedef Int32Traits TraitsType; 42 B2IRange()43 B2IRange() 44 { 45 } 46 B2IRange(const B2ITuple & rTuple)47 explicit B2IRange(const B2ITuple& rTuple) 48 : maRangeX(rTuple.getX()), 49 maRangeY(rTuple.getY()) 50 { 51 } 52 B2IRange(sal_Int32 x1,sal_Int32 y1,sal_Int32 x2,sal_Int32 y2)53 B2IRange(sal_Int32 x1, 54 sal_Int32 y1, 55 sal_Int32 x2, 56 sal_Int32 y2) 57 : maRangeX(x1), 58 maRangeY(y1) 59 { 60 maRangeX.expand(x2); 61 maRangeY.expand(y2); 62 } 63 B2IRange(const B2ITuple & rTuple1,const B2ITuple & rTuple2)64 B2IRange(const B2ITuple& rTuple1, 65 const B2ITuple& rTuple2) 66 : maRangeX(rTuple1.getX()), 67 maRangeY(rTuple1.getY()) 68 { 69 expand( rTuple2 ); 70 } 71 B2IRange(const B2IRange & rRange)72 B2IRange(const B2IRange& rRange) 73 : maRangeX(rRange.maRangeX), 74 maRangeY(rRange.maRangeY) 75 { 76 } 77 isEmpty() const78 bool isEmpty() const 79 { 80 return maRangeX.isEmpty() || maRangeY.isEmpty(); 81 } 82 reset()83 void reset() 84 { 85 maRangeX.reset(); 86 maRangeY.reset(); 87 } 88 operator ==(const B2IRange & rRange) const89 bool operator==( const B2IRange& rRange ) const 90 { 91 return (maRangeX == rRange.maRangeX 92 && maRangeY == rRange.maRangeY); 93 } 94 operator !=(const B2IRange & rRange) const95 bool operator!=( const B2IRange& rRange ) const 96 { 97 return (maRangeX != rRange.maRangeX 98 || maRangeY != rRange.maRangeY); 99 } 100 operator =(const B2IRange & rRange)101 B2IRange& operator=(const B2IRange& rRange) 102 { 103 maRangeX = rRange.maRangeX; 104 maRangeY = rRange.maRangeY; 105 return *this; 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 B2IRange & rRange) const178 bool isInside(const B2IRange& rRange) const 179 { 180 return ( 181 maRangeX.isInside(rRange.maRangeX) 182 && maRangeY.isInside(rRange.maRangeY) 183 ); 184 } 185 overlaps(const B2IRange & rRange) const186 bool overlaps(const B2IRange& rRange) const 187 { 188 return ( 189 maRangeX.overlaps(rRange.maRangeX) 190 && maRangeY.overlaps(rRange.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 B2IRange & rRange)200 void expand(const B2IRange& rRange) 201 { 202 maRangeX.expand(rRange.maRangeX); 203 maRangeY.expand(rRange.maRangeY); 204 } 205 intersect(const B2IRange & rRange)206 void intersect(const B2IRange& rRange) 207 { 208 maRangeX.intersect(rRange.maRangeX); 209 maRangeY.intersect(rRange.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 typedef ::basegfx::BasicRange< ValueType, TraitsType > MyBasicRange; 220 221 MyBasicRange maRangeX; 222 MyBasicRange maRangeY; 223 }; 224 225 /** Compute the set difference of the two given ranges 226 227 This method calculates the symmetric difference (aka XOR) 228 between the two given ranges, and returning the resulting 229 ranges. Thus, the result will contain all areas where one, but 230 not both ranges lie. 231 232 @param o_rResult 233 Result vector. The up to four difference ranges are returned 234 within this vector 235 236 @param rFirst 237 The first range 238 239 @param rSecond 240 The second range 241 242 @return the input vector 243 */ 244 ::std::vector< B2IRange >& computeSetDifference( ::std::vector< B2IRange >& o_rResult, 245 const B2IRange& rFirst, 246 const B2IRange& rSecond ); 247 248 } // end of namespace basegfx 249 250 #endif /* _BGFX_RANGE_B2IRANGE_HXX */ 251