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_B2DRANGE_HXX 25 #define _BGFX_RANGE_B2DRANGE_HXX 26 27 #include <basegfx/vector/b2dvector.hxx> 28 #include <basegfx/point/b2dpoint.hxx> 29 #include <basegfx/tuple/b2dtuple.hxx> 30 #include <basegfx/range/basicrange.hxx> 31 #include <vector> 32 33 34 namespace basegfx 35 { 36 // predeclarations 37 class B2IRange; 38 class B2DHomMatrix; 39 40 class B2DRange 41 { 42 public: 43 typedef double ValueType; 44 typedef DoubleTraits TraitsType; 45 B2DRange()46 B2DRange() 47 { 48 } 49 B2DRange(const B2DTuple & rTuple)50 explicit B2DRange(const B2DTuple& rTuple) 51 : maRangeX(rTuple.getX()), 52 maRangeY(rTuple.getY()) 53 { 54 } 55 B2DRange(double x1,double y1,double x2,double y2)56 B2DRange(double x1, 57 double y1, 58 double x2, 59 double y2) 60 : maRangeX(x1), 61 maRangeY(y1) 62 { 63 maRangeX.expand(x2); 64 maRangeY.expand(y2); 65 } 66 B2DRange(const B2DTuple & rTuple1,const B2DTuple & rTuple2)67 B2DRange(const B2DTuple& rTuple1, 68 const B2DTuple& rTuple2) 69 : maRangeX(rTuple1.getX()), 70 maRangeY(rTuple1.getY()) 71 { 72 expand( rTuple2 ); 73 } 74 B2DRange(const B2DRange & rRange)75 B2DRange(const B2DRange& rRange) 76 : maRangeX(rRange.maRangeX), 77 maRangeY(rRange.maRangeY) 78 { 79 } 80 81 explicit B2DRange(const B2IRange& rRange); 82 isEmpty() const83 bool isEmpty() const 84 { 85 return ( 86 maRangeX.isEmpty() 87 || maRangeY.isEmpty() 88 ); 89 } 90 reset()91 void reset() 92 { 93 maRangeX.reset(); 94 maRangeY.reset(); 95 } 96 operator ==(const B2DRange & rRange) const97 bool operator==( const B2DRange& rRange ) const 98 { 99 return (maRangeX == rRange.maRangeX 100 && maRangeY == rRange.maRangeY); 101 } 102 operator !=(const B2DRange & rRange) const103 bool operator!=( const B2DRange& rRange ) const 104 { 105 return (maRangeX != rRange.maRangeX 106 || maRangeY != rRange.maRangeY); 107 } 108 operator =(const B2DRange & rRange)109 B2DRange& operator=(const B2DRange& rRange) 110 { 111 maRangeX = rRange.maRangeX; 112 maRangeY = rRange.maRangeY; 113 return *this; 114 } 115 equal(const B2DRange & rRange) const116 bool equal(const B2DRange& rRange) const 117 { 118 return (maRangeX.equal(rRange.maRangeX) 119 && maRangeY.equal(rRange.maRangeY)); 120 } 121 getMinX() const122 double getMinX() const 123 { 124 return maRangeX.getMinimum(); 125 } 126 getMinY() const127 double getMinY() const 128 { 129 return maRangeY.getMinimum(); 130 } 131 getMaxX() const132 double getMaxX() const 133 { 134 return maRangeX.getMaximum(); 135 } 136 getMaxY() const137 double getMaxY() const 138 { 139 return maRangeY.getMaximum(); 140 } 141 getWidth() const142 double getWidth() const 143 { 144 return maRangeX.getRange(); 145 } 146 getHeight() const147 double getHeight() const 148 { 149 return maRangeY.getRange(); 150 } 151 getMinimum() const152 B2DPoint getMinimum() const 153 { 154 return B2DPoint( 155 maRangeX.getMinimum(), 156 maRangeY.getMinimum() 157 ); 158 } 159 getMaximum() const160 B2DPoint getMaximum() const 161 { 162 return B2DPoint( 163 maRangeX.getMaximum(), 164 maRangeY.getMaximum() 165 ); 166 } 167 getRange() const168 B2DVector getRange() const 169 { 170 return B2DVector( 171 maRangeX.getRange(), 172 maRangeY.getRange() 173 ); 174 } 175 getCenter() const176 B2DPoint getCenter() const 177 { 178 return B2DPoint( 179 maRangeX.getCenter(), 180 maRangeY.getCenter() 181 ); 182 } 183 getCenterX() const184 double getCenterX() const 185 { 186 return maRangeX.getCenter(); 187 } 188 getCenterY() const189 double getCenterY() const 190 { 191 return maRangeY.getCenter(); 192 } 193 isInside(const B2DTuple & rTuple) const194 bool isInside(const B2DTuple& rTuple) const 195 { 196 return ( 197 maRangeX.isInside(rTuple.getX()) 198 && maRangeY.isInside(rTuple.getY()) 199 ); 200 } 201 isInside(const B2DRange & rRange) const202 bool isInside(const B2DRange& rRange) const 203 { 204 return ( 205 maRangeX.isInside(rRange.maRangeX) 206 && maRangeY.isInside(rRange.maRangeY) 207 ); 208 } 209 overlaps(const B2DRange & rRange) const210 bool overlaps(const B2DRange& rRange) const 211 { 212 return ( 213 maRangeX.overlaps(rRange.maRangeX) 214 && maRangeY.overlaps(rRange.maRangeY) 215 ); 216 } 217 overlapsMore(const B2DRange & rRange) const218 bool overlapsMore(const B2DRange& rRange) const 219 { 220 return ( 221 maRangeX.overlapsMore(rRange.maRangeX) 222 && maRangeY.overlapsMore(rRange.maRangeY) 223 ); 224 } 225 expand(const B2DTuple & rTuple)226 void expand(const B2DTuple& rTuple) 227 { 228 maRangeX.expand(rTuple.getX()); 229 maRangeY.expand(rTuple.getY()); 230 } 231 expand(const B2DRange & rRange)232 void expand(const B2DRange& rRange) 233 { 234 maRangeX.expand(rRange.maRangeX); 235 maRangeY.expand(rRange.maRangeY); 236 } 237 intersect(const B2DRange & rRange)238 void intersect(const B2DRange& rRange) 239 { 240 maRangeX.intersect(rRange.maRangeX); 241 maRangeY.intersect(rRange.maRangeY); 242 } 243 grow(double fValue)244 void grow(double fValue) 245 { 246 maRangeX.grow(fValue); 247 maRangeY.grow(fValue); 248 } 249 250 void transform(const B2DHomMatrix& rMatrix); 251 252 private: 253 typedef ::basegfx::BasicRange< ValueType, TraitsType > MyBasicRange; 254 255 MyBasicRange maRangeX; 256 MyBasicRange maRangeY; 257 }; 258 259 /** Round double to nearest integer for 2D range 260 261 @return the nearest integer for this range 262 */ 263 B2IRange fround(const B2DRange& rRange); 264 265 /** Compute the set difference of the two given ranges 266 267 This method calculates the symmetric difference (aka XOR) 268 between the two given ranges, and returning the resulting 269 ranges. Thus, the result will contain all areas where one, but 270 not both ranges lie. 271 272 @param o_rResult 273 Result vector. The up to four difference ranges are returned 274 within this vector 275 276 @param rFirst 277 The first range 278 279 @param rSecond 280 The second range 281 282 @return the input vector 283 */ 284 ::std::vector< B2DRange >& computeSetDifference( ::std::vector< B2DRange >& o_rResult, 285 const B2DRange& rFirst, 286 const B2DRange& rSecond ); 287 288 } // end of namespace basegfx 289 290 291 #endif /* _BGFX_RANGE_B2DRANGE_HXX */ 292