1ce9c7ef7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ce9c7ef7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ce9c7ef7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5ce9c7ef7SAndrew Rist * distributed with this work for additional information 6ce9c7ef7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ce9c7ef7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8ce9c7ef7SAndrew Rist * "License"); you may not use this file except in compliance 9ce9c7ef7SAndrew Rist * with the License. You may obtain a copy of the License at 10ce9c7ef7SAndrew Rist * 11ce9c7ef7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ce9c7ef7SAndrew Rist * 13ce9c7ef7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14ce9c7ef7SAndrew Rist * software distributed under the License is distributed on an 15ce9c7ef7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ce9c7ef7SAndrew Rist * KIND, either express or implied. See the License for the 17ce9c7ef7SAndrew Rist * specific language governing permissions and limitations 18ce9c7ef7SAndrew Rist * under the License. 19ce9c7ef7SAndrew Rist * 20ce9c7ef7SAndrew Rist *************************************************************/ 21ce9c7ef7SAndrew Rist 22ce9c7ef7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _BGFX_RANGE_B3DRANGE_HXX 25cdf0e10cSrcweir #define _BGFX_RANGE_B3DRANGE_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx> 28cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx> 29cdf0e10cSrcweir #include <basegfx/tuple/b3dtuple.hxx> 30cdf0e10cSrcweir #include <basegfx/range/basicrange.hxx> 31*b63233d8Sdamjan #include <basegfx/basegfxdllapi.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace basegfx 34cdf0e10cSrcweir { 35cdf0e10cSrcweir // predeclarations 36cdf0e10cSrcweir class B3IRange; 37cdf0e10cSrcweir class B3DHomMatrix; 38cdf0e10cSrcweir 39*b63233d8Sdamjan class BASEGFX_DLLPUBLIC B3DRange 40cdf0e10cSrcweir { 41cdf0e10cSrcweir typedef ::basegfx::BasicRange< double, DoubleTraits > MyBasicRange; 42cdf0e10cSrcweir 43cdf0e10cSrcweir MyBasicRange maRangeX; 44cdf0e10cSrcweir MyBasicRange maRangeY; 45cdf0e10cSrcweir MyBasicRange maRangeZ; 46cdf0e10cSrcweir 47cdf0e10cSrcweir public: B3DRange()48cdf0e10cSrcweir B3DRange() 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir B3DRange(const B3DTuple & rTuple)52cdf0e10cSrcweir explicit B3DRange(const B3DTuple& rTuple) 53cdf0e10cSrcweir : maRangeX(rTuple.getX()), 54cdf0e10cSrcweir maRangeY(rTuple.getY()), 55cdf0e10cSrcweir maRangeZ(rTuple.getZ()) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir } 58cdf0e10cSrcweir B3DRange(double x1,double y1,double z1,double x2,double y2,double z2)59cdf0e10cSrcweir B3DRange(double x1, 60cdf0e10cSrcweir double y1, 61cdf0e10cSrcweir double z1, 62cdf0e10cSrcweir double x2, 63cdf0e10cSrcweir double y2, 64cdf0e10cSrcweir double z2) 65cdf0e10cSrcweir : maRangeX(x1), 66cdf0e10cSrcweir maRangeY(y1), 67cdf0e10cSrcweir maRangeZ(z1) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir maRangeX.expand(x2); 70cdf0e10cSrcweir maRangeY.expand(y2); 71cdf0e10cSrcweir maRangeZ.expand(z2); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir B3DRange(const B3DTuple & rTuple1,const B3DTuple & rTuple2)74cdf0e10cSrcweir B3DRange(const B3DTuple& rTuple1, 75cdf0e10cSrcweir const B3DTuple& rTuple2) 76cdf0e10cSrcweir : maRangeX(rTuple1.getX()), 77cdf0e10cSrcweir maRangeY(rTuple1.getY()), 78cdf0e10cSrcweir maRangeZ(rTuple1.getZ()) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir expand(rTuple2); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir B3DRange(const B3DRange & rRange)83cdf0e10cSrcweir B3DRange(const B3DRange& rRange) 84cdf0e10cSrcweir : maRangeX(rRange.maRangeX), 85cdf0e10cSrcweir maRangeY(rRange.maRangeY), 86cdf0e10cSrcweir maRangeZ(rRange.maRangeZ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir explicit B3DRange(const B3IRange& rRange); 91cdf0e10cSrcweir isEmpty() const92cdf0e10cSrcweir bool isEmpty() const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir return ( 95cdf0e10cSrcweir maRangeX.isEmpty() 96cdf0e10cSrcweir || maRangeY.isEmpty() 97cdf0e10cSrcweir || maRangeZ.isEmpty() 98cdf0e10cSrcweir ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir reset()101cdf0e10cSrcweir void reset() 102cdf0e10cSrcweir { 103cdf0e10cSrcweir maRangeX.reset(); 104cdf0e10cSrcweir maRangeY.reset(); 105cdf0e10cSrcweir maRangeZ.reset(); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir operator ==(const B3DRange & rRange) const108cdf0e10cSrcweir bool operator==( const B3DRange& rRange ) const 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return (maRangeX == rRange.maRangeX 111cdf0e10cSrcweir && maRangeY == rRange.maRangeY 112cdf0e10cSrcweir && maRangeZ == rRange.maRangeZ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir operator !=(const B3DRange & rRange) const115cdf0e10cSrcweir bool operator!=( const B3DRange& rRange ) const 116cdf0e10cSrcweir { 117cdf0e10cSrcweir return (maRangeX != rRange.maRangeX 118cdf0e10cSrcweir || maRangeY != rRange.maRangeY 119cdf0e10cSrcweir || maRangeZ != rRange.maRangeZ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir operator =(const B3DRange & rRange)122cdf0e10cSrcweir B3DRange& operator=(const B3DRange& rRange) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir maRangeX = rRange.maRangeX; 125cdf0e10cSrcweir maRangeY = rRange.maRangeY; 126cdf0e10cSrcweir maRangeZ = rRange.maRangeZ; 127cdf0e10cSrcweir return *this; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir equal(const B3DRange & rRange) const130cdf0e10cSrcweir bool equal(const B3DRange& rRange) const 131cdf0e10cSrcweir { 132cdf0e10cSrcweir return (maRangeX.equal(rRange.maRangeX) 133cdf0e10cSrcweir && maRangeY.equal(rRange.maRangeY) 134cdf0e10cSrcweir && maRangeZ.equal(rRange.maRangeZ)); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir getMinX() const137cdf0e10cSrcweir double getMinX() const 138cdf0e10cSrcweir { 139cdf0e10cSrcweir return maRangeX.getMinimum(); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir getMinY() const142cdf0e10cSrcweir double getMinY() const 143cdf0e10cSrcweir { 144cdf0e10cSrcweir return maRangeY.getMinimum(); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir getMinZ() const147cdf0e10cSrcweir double getMinZ() const 148cdf0e10cSrcweir { 149cdf0e10cSrcweir return maRangeZ.getMinimum(); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir getMaxX() const152cdf0e10cSrcweir double getMaxX() const 153cdf0e10cSrcweir { 154cdf0e10cSrcweir return maRangeX.getMaximum(); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir getMaxY() const157cdf0e10cSrcweir double getMaxY() const 158cdf0e10cSrcweir { 159cdf0e10cSrcweir return maRangeY.getMaximum(); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir getMaxZ() const162cdf0e10cSrcweir double getMaxZ() const 163cdf0e10cSrcweir { 164cdf0e10cSrcweir return maRangeZ.getMaximum(); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir getWidth() const167cdf0e10cSrcweir double getWidth() const 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return maRangeX.getRange(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir getHeight() const172cdf0e10cSrcweir double getHeight() const 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return maRangeY.getRange(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir getDepth() const177cdf0e10cSrcweir double getDepth() const 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return maRangeZ.getRange(); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir getMinimum() const182cdf0e10cSrcweir B3DPoint getMinimum() const 183cdf0e10cSrcweir { 184cdf0e10cSrcweir return B3DPoint( 185cdf0e10cSrcweir maRangeX.getMinimum(), 186cdf0e10cSrcweir maRangeY.getMinimum(), 187cdf0e10cSrcweir maRangeZ.getMinimum() 188cdf0e10cSrcweir ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir getMaximum() const191cdf0e10cSrcweir B3DPoint getMaximum() const 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return B3DPoint( 194cdf0e10cSrcweir maRangeX.getMaximum(), 195cdf0e10cSrcweir maRangeY.getMaximum(), 196cdf0e10cSrcweir maRangeZ.getMaximum() 197cdf0e10cSrcweir ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir getRange() const200cdf0e10cSrcweir B3DVector getRange() const 201cdf0e10cSrcweir { 202cdf0e10cSrcweir return B3DVector( 203cdf0e10cSrcweir maRangeX.getRange(), 204cdf0e10cSrcweir maRangeY.getRange(), 205cdf0e10cSrcweir maRangeZ.getRange() 206cdf0e10cSrcweir ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir getCenter() const209cdf0e10cSrcweir B3DPoint getCenter() const 210cdf0e10cSrcweir { 211cdf0e10cSrcweir return B3DPoint( 212cdf0e10cSrcweir maRangeX.getCenter(), 213cdf0e10cSrcweir maRangeY.getCenter(), 214cdf0e10cSrcweir maRangeZ.getCenter() 215cdf0e10cSrcweir ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir getCenterX() const218cdf0e10cSrcweir double getCenterX() const 219cdf0e10cSrcweir { 220cdf0e10cSrcweir return maRangeX.getCenter(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir getCenterY() const223cdf0e10cSrcweir double getCenterY() const 224cdf0e10cSrcweir { 225cdf0e10cSrcweir return maRangeY.getCenter(); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir getCenterZ() const228cdf0e10cSrcweir double getCenterZ() const 229cdf0e10cSrcweir { 230cdf0e10cSrcweir return maRangeZ.getCenter(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir isInside(const B3DTuple & rTuple) const233cdf0e10cSrcweir bool isInside(const B3DTuple& rTuple) const 234cdf0e10cSrcweir { 235cdf0e10cSrcweir return ( 236cdf0e10cSrcweir maRangeX.isInside(rTuple.getX()) 237cdf0e10cSrcweir && maRangeY.isInside(rTuple.getY()) 238cdf0e10cSrcweir && maRangeZ.isInside(rTuple.getZ()) 239cdf0e10cSrcweir ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir isInside(const B3DRange & rRange) const242cdf0e10cSrcweir bool isInside(const B3DRange& rRange) const 243cdf0e10cSrcweir { 244cdf0e10cSrcweir return ( 245cdf0e10cSrcweir maRangeX.isInside(rRange.maRangeX) 246cdf0e10cSrcweir && maRangeY.isInside(rRange.maRangeY) 247cdf0e10cSrcweir && maRangeZ.isInside(rRange.maRangeZ) 248cdf0e10cSrcweir ); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir overlaps(const B3DRange & rRange) const251cdf0e10cSrcweir bool overlaps(const B3DRange& rRange) const 252cdf0e10cSrcweir { 253cdf0e10cSrcweir return ( 254cdf0e10cSrcweir maRangeX.overlaps(rRange.maRangeX) 255cdf0e10cSrcweir && maRangeY.overlaps(rRange.maRangeY) 256cdf0e10cSrcweir && maRangeZ.overlaps(rRange.maRangeZ) 257cdf0e10cSrcweir ); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir expand(const B3DTuple & rTuple)260cdf0e10cSrcweir void expand(const B3DTuple& rTuple) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir maRangeX.expand(rTuple.getX()); 263cdf0e10cSrcweir maRangeY.expand(rTuple.getY()); 264cdf0e10cSrcweir maRangeZ.expand(rTuple.getZ()); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir expand(const B3DRange & rRange)267cdf0e10cSrcweir void expand(const B3DRange& rRange) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir maRangeX.expand(rRange.maRangeX); 270cdf0e10cSrcweir maRangeY.expand(rRange.maRangeY); 271cdf0e10cSrcweir maRangeZ.expand(rRange.maRangeZ); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir intersect(const B3DRange & rRange)274cdf0e10cSrcweir void intersect(const B3DRange& rRange) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir maRangeX.intersect(rRange.maRangeX); 277cdf0e10cSrcweir maRangeY.intersect(rRange.maRangeY); 278cdf0e10cSrcweir maRangeZ.intersect(rRange.maRangeZ); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir grow(double fValue)281cdf0e10cSrcweir void grow(double fValue) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir maRangeX.grow(fValue); 284cdf0e10cSrcweir maRangeY.grow(fValue); 285cdf0e10cSrcweir maRangeZ.grow(fValue); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir void transform(const B3DHomMatrix& rMatrix); 289cdf0e10cSrcweir }; 290cdf0e10cSrcweir 291cdf0e10cSrcweir /** Round double to nearest integer for 3D range 292cdf0e10cSrcweir 293cdf0e10cSrcweir @return the nearest integer for this range 294cdf0e10cSrcweir */ 295*b63233d8Sdamjan BASEGFX_DLLPUBLIC B3IRange fround(const B3DRange& rRange); 296cdf0e10cSrcweir } // end of namespace basegfx 297cdf0e10cSrcweir 298cdf0e10cSrcweir 299cdf0e10cSrcweir #endif /* _BGFX_RANGE_B3DRANGE_HXX */ 300