diff options
Diffstat (limited to 'basegfx/source/polygon')
-rw-r--r-- | basegfx/source/polygon/b2dpolygon.cxx | 495 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 1410 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygon.cxx | 349 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygoncutter.cxx | 1542 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygontools.cxx | 221 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolygon.cxx | 373 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolygontools.cxx | 453 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolypolygon.cxx | 331 | ||||
-rw-r--r-- | basegfx/source/polygon/b3dpolypolygontools.cxx | 43 |
9 files changed, 2678 insertions, 2539 deletions
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index 7a9b477081f5..0dcbeaa7a3a2 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygon.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:10 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -86,17 +86,17 @@ class CoordinateData2D { - ::basegfx::point::B2DPoint maPoint; + ::basegfx::B2DPoint maPoint; public: CoordinateData2D() {} - CoordinateData2D(const ::basegfx::point::B2DPoint& rData) : maPoint(rData) {} + CoordinateData2D(const ::basegfx::B2DPoint& rData) : maPoint(rData) {} ~CoordinateData2D() {} - const ::basegfx::point::B2DPoint& getCoordinate() const { return maPoint; } - void setCoordinate(const ::basegfx::point::B2DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } + const ::basegfx::B2DPoint& getCoordinate() const { return maPoint; } + void setCoordinate(const ::basegfx::B2DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } sal_Bool operator==(const CoordinateData2D& rData ) const { return (maPoint == rData.getCoordinate()); } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) { maPoint *= rMatrix; } + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { maPoint *= rMatrix; } }; ////////////////////////////////////////////////////////////////////////////// @@ -137,12 +137,12 @@ public: return (maVector == rCandidate.maVector); } - const ::basegfx::point::B2DPoint& getCoordinate(sal_uInt32 nIndex) const + const ::basegfx::B2DPoint& getCoordinate(sal_uInt32 nIndex) const { return maVector[nIndex].getCoordinate(); } - void setCoordinate(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) + void setCoordinate(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) { maVector[nIndex].setCoordinate(rValue); } @@ -233,7 +233,7 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { CoordinateData2DVector::iterator aStart(maVector.begin()); CoordinateData2DVector::iterator aEnd(maVector.end()); @@ -249,18 +249,18 @@ public: class ControlVectorPair2D { - ::basegfx::vector::B2DVector maVectorA; - ::basegfx::vector::B2DVector maVectorB; + ::basegfx::B2DVector maVectorA; + ::basegfx::B2DVector maVectorB; public: ControlVectorPair2D() {} ~ControlVectorPair2D() {} - const ::basegfx::vector::B2DVector& getVectorA() const { return maVectorA; } - void setVectorA(const ::basegfx::vector::B2DVector& rValue) { if(rValue != maVectorA) maVectorA = rValue; } + const ::basegfx::B2DVector& getVectorA() const { return maVectorA; } + void setVectorA(const ::basegfx::B2DVector& rValue) { if(rValue != maVectorA) maVectorA = rValue; } - const ::basegfx::vector::B2DVector& getVectorB() const { return maVectorB; } - void setVectorB(const ::basegfx::vector::B2DVector& rValue) { if(rValue != maVectorB) maVectorB = rValue; } + const ::basegfx::B2DVector& getVectorB() const { return maVectorB; } + void setVectorB(const ::basegfx::B2DVector& rValue) { if(rValue != maVectorB) maVectorB = rValue; } sal_Bool operator==(const ControlVectorPair2D& rData ) const { return (maVectorA == rData.getVectorA() && maVectorB == rData.getVectorB()); } @@ -329,12 +329,12 @@ public: return (0L != mnUsedVectors); } - const ::basegfx::vector::B2DVector& getVectorA(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getVectorA(sal_uInt32 nIndex) const { return maVector[nIndex].getVectorA(); } - void setVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorA().equalZero()); sal_Bool bIsUsed(!rValue.equalZero()); @@ -347,7 +347,7 @@ public: } else { - maVector[nIndex].setVectorA(::basegfx::vector::B2DVector::getEmptyVector()); + maVector[nIndex].setVectorA(::basegfx::B2DVector::getEmptyVector()); mnUsedVectors--; } } @@ -361,12 +361,12 @@ public: } } - const ::basegfx::vector::B2DVector& getVectorB(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getVectorB(sal_uInt32 nIndex) const { return maVector[nIndex].getVectorB(); } - void setVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorB().equalZero()); sal_Bool bIsUsed(!rValue.equalZero()); @@ -379,7 +379,7 @@ public: } else { - maVector[nIndex].setVectorB(::basegfx::vector::B2DVector::getEmptyVector()); + maVector[nIndex].setVectorB(::basegfx::B2DVector::getEmptyVector()); mnUsedVectors--; } } @@ -601,17 +601,17 @@ public: return sal_False; } - const ::basegfx::point::B2DPoint& getPoint(sal_uInt32 nIndex) const + const ::basegfx::B2DPoint& getPoint(sal_uInt32 nIndex) const { return maPoints.getCoordinate(nIndex); } - void setPoint(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) + void setPoint(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) { maPoints.setCoordinate(nIndex, rValue); } - void insert(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) { if(nCount) { @@ -626,7 +626,7 @@ public: } } - const ::basegfx::vector::B2DVector& getControlVectorA(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getControlVectorA(sal_uInt32 nIndex) const { if(mpControlVector) { @@ -634,11 +634,11 @@ public: } else { - return ::basegfx::vector::B2DVector::getEmptyVector(); + return ::basegfx::B2DVector::getEmptyVector(); } } - void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { if(!mpControlVector) { @@ -665,7 +665,7 @@ public: return (mpControlVector && mpControlVector->isUsed()); } - const ::basegfx::vector::B2DVector& getControlVectorB(sal_uInt32 nIndex) const + const ::basegfx::B2DVector& getControlVectorB(sal_uInt32 nIndex) const { if(mpControlVector) { @@ -673,11 +673,11 @@ public: } else { - return ::basegfx::vector::B2DVector::getEmptyVector(); + return ::basegfx::B2DVector::getEmptyVector(); } } - void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) + void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) { if(!mpControlVector) { @@ -775,10 +775,10 @@ public: const sal_uInt32 nVectorSource(nCoorSource ? nCoorSource - 1L : nCount - 1L); // get source data - const ::basegfx::point::B2DPoint& rSourceCoor = pCoordinateCopy->getCoordinate(nCoorSource); - const ::basegfx::point::B2DPoint& rVectorSourceCoor = pCoordinateCopy->getCoordinate(nVectorSource); - const ::basegfx::vector::B2DVector& rVectorSourceA = pVectorCopy->getVectorA(nVectorSource); - const ::basegfx::vector::B2DVector& rVectorSourceB = pVectorCopy->getVectorB(nVectorSource); + const ::basegfx::B2DPoint& rSourceCoor = pCoordinateCopy->getCoordinate(nCoorSource); + const ::basegfx::B2DPoint& rVectorSourceCoor = pCoordinateCopy->getCoordinate(nVectorSource); + const ::basegfx::B2DVector& rVectorSourceA = pVectorCopy->getVectorA(nVectorSource); + const ::basegfx::B2DVector& rVectorSourceB = pVectorCopy->getVectorB(nVectorSource); // copy point data maPoints.setCoordinate(a, rSourceCoor); @@ -787,12 +787,12 @@ public: if(rVectorSourceA.equalZero()) { // unused, use zero vector - mpControlVector->setVectorB(a, ::basegfx::vector::B2DVector::getEmptyVector()); + mpControlVector->setVectorB(a, ::basegfx::B2DVector::getEmptyVector()); } else { // calculate new vector relative to new point - ::basegfx::vector::B2DVector aNewVectorB((rVectorSourceA + rVectorSourceCoor) - rSourceCoor); + ::basegfx::B2DVector aNewVectorB((rVectorSourceA + rVectorSourceCoor) - rSourceCoor); mpControlVector->setVectorB(a, aNewVectorB); } @@ -800,12 +800,12 @@ public: if(rVectorSourceB.equalZero()) { // unused, use zero vector - mpControlVector->setVectorA(a, ::basegfx::vector::B2DVector::getEmptyVector()); + mpControlVector->setVectorA(a, ::basegfx::B2DVector::getEmptyVector()); } else { // calculate new vector relative to new point - ::basegfx::vector::B2DVector aNewVectorA((rVectorSourceB + rVectorSourceCoor) - rSourceCoor); + ::basegfx::B2DVector aNewVectorA((rVectorSourceB + rVectorSourceCoor) - rSourceCoor); mpControlVector->setVectorA(a, aNewVectorA); } } @@ -939,28 +939,28 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { if(mpControlVector) { for(sal_uInt32 a(0L); a < maPoints.count(); a++) { - ::basegfx::point::B2DPoint aCandidate = maPoints.getCoordinate(a); + ::basegfx::B2DPoint aCandidate = maPoints.getCoordinate(a); if(mpControlVector->isUsed()) { - const ::basegfx::vector::B2DVector& rVectorA(mpControlVector->getVectorA(a)); - const ::basegfx::vector::B2DVector& rVectorB(mpControlVector->getVectorB(a)); + const ::basegfx::B2DVector& rVectorA(mpControlVector->getVectorA(a)); + const ::basegfx::B2DVector& rVectorB(mpControlVector->getVectorB(a)); if(!rVectorA.equalZero()) { - ::basegfx::vector::B2DVector aVectorA(rMatrix * rVectorA); + ::basegfx::B2DVector aVectorA(rMatrix * rVectorA); mpControlVector->setVectorA(a, aVectorA); } if(!rVectorB.equalZero()) { - ::basegfx::vector::B2DVector aVectorB(rMatrix * rVectorB); + ::basegfx::B2DVector aVectorB(rMatrix * rVectorB); mpControlVector->setVectorB(a, aVectorB); } } @@ -986,294 +986,291 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB2DPolygon maStaticDefaultPolygon; + // init static default Polygon + static ImplB2DPolygon maStaticDefaultPolygon; - void B2DPolygon::implForceUniqueCopy() + void B2DPolygon::implForceUniqueCopy() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - mpPolygon = new ImplB2DPolygon(*mpPolygon); - } + mpPolygon->decRefCount(); + mpPolygon = new ImplB2DPolygon(*mpPolygon); } + } - B2DPolygon::B2DPolygon() - : mpPolygon(&maStaticDefaultPolygon) - { - mpPolygon->incRefCount(); - } + B2DPolygon::B2DPolygon() + : mpPolygon(&maStaticDefaultPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon) + : mpPolygon(rPolygon.mpPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) + : mpPolygon(new ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + { + OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); + } - B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon) - : mpPolygon(rPolygon.mpPolygon) + B2DPolygon::~B2DPolygon() + { + if(mpPolygon->getRefCount()) { - mpPolygon->incRefCount(); + mpPolygon->decRefCount(); } - - B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) - : mpPolygon(new ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + else { - OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); + delete mpPolygon; } + } - B2DPolygon::~B2DPolygon() + B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon) + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + mpPolygon->decRefCount(); } - - B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon) + else { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } - - mpPolygon = rPolygon.mpPolygon; - mpPolygon->incRefCount(); - - return *this; + delete mpPolygon; } - sal_Bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_True; - } + mpPolygon = rPolygon.mpPolygon; + mpPolygon->incRefCount(); - return mpPolygon->isEqual(*(rPolygon.mpPolygon)); - } + return *this; + } - sal_Bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const + sal_Bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_False; - } - - return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + return sal_True; } - sal_uInt32 B2DPolygon::count() const + return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } + + sal_Bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) { - return mpPolygon->count(); + return sal_False; } - ::basegfx::point::B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return mpPolygon->getPoint(nIndex); - } + sal_uInt32 B2DPolygon::count() const + { + return mpPolygon->count(); + } - void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getPoint(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setPoint(nIndex, rValue); - } - } + return mpPolygon->getPoint(nIndex); + } - void B2DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(nIndex, rPoint, nCount); - } + if(mpPolygon->getPoint(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setPoint(nIndex, rValue); } + } + + void B2DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - void B2DPolygon::append(const ::basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(mpPolygon->count(), rPoint, nCount); - } + implForceUniqueCopy(); + mpPolygon->insert(nIndex, rPoint, nCount); } + } - ::basegfx::vector::B2DVector B2DPolygon::getControlVectorA(sal_uInt32 nIndex) const + void B2DPolygon::append(const ::basegfx::B2DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - return mpPolygon->getControlVectorA(nIndex); + implForceUniqueCopy(); + mpPolygon->insert(mpPolygon->count(), rPoint, nCount); } + } - void B2DPolygon::setControlVectorA(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector B2DPolygon::getControlVectorA(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getControlVectorA(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setControlVectorA(nIndex, rValue); - } - } + return mpPolygon->getControlVectorA(nIndex); + } - ::basegfx::vector::B2DVector B2DPolygon::getControlVectorB(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + void B2DPolygon::setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - return mpPolygon->getControlVectorB(nIndex); + if(mpPolygon->getControlVectorA(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setControlVectorA(nIndex, rValue); } + } - void B2DPolygon::setControlVectorB(sal_uInt32 nIndex, const ::basegfx::vector::B2DVector& rValue) - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector B2DPolygon::getControlVectorB(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - if(mpPolygon->getControlVectorB(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setControlVectorB(nIndex, rValue); - } - } + return mpPolygon->getControlVectorB(nIndex); + } - sal_Bool B2DPolygon::areControlPointsUsed() const + void B2DPolygon::setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->getControlVectorB(nIndex) != rValue) { - return mpPolygon->areControlPointsUsed(); + implForceUniqueCopy(); + mpPolygon->setControlVectorB(nIndex, rValue); } + } - void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + sal_Bool B2DPolygon::areControlPointsUsed() const + { + return mpPolygon->areControlPointsUsed(); + } - if(rPoly.count()) - { - implForceUniqueCopy(); + void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - if(!nCount) - { - nCount = rPoly.count(); - } + if(rPoly.count()) + { + implForceUniqueCopy(); - if(0L == nIndex2 && nCount == rPoly.count()) - { - mpPolygon->insert(nIndex, *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B2DPolygon Insert outside range (!)"); - ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); - mpPolygon->insert(nIndex, aTempPoly); - } + if(!nCount) + { + nCount = rPoly.count(); } - } - void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) - { - if(rPoly.count()) + if(0L == nIndex2 && nCount == rPoly.count()) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex && nCount == rPoly.count()) - { - mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); - ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(mpPolygon->count(), aTempPoly); - } + mpPolygon->insert(nIndex, *rPoly.mpPolygon); + } + else + { + OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); + mpPolygon->insert(nIndex, aTempPoly); } } + } - void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(rPoly.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)"); + implForceUniqueCopy(); - if(nCount) + if(!nCount) { - implForceUniqueCopy(); - mpPolygon->remove(nIndex, nCount); + nCount = rPoly.count(); } - } - void B2DPolygon::clear() - { - if(mpPolygon->getRefCount()) + if(0L == nIndex && nCount == rPoly.count()) { - mpPolygon->decRefCount(); + mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); } else { - delete mpPolygon; + OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); + mpPolygon->insert(mpPolygon->count(), aTempPoly); } - - mpPolygon = &maStaticDefaultPolygon; - mpPolygon->incRefCount(); } + } - sal_Bool B2DPolygon::isClosed() const + void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)"); + + if(nCount) { - return mpPolygon->isClosed(); + implForceUniqueCopy(); + mpPolygon->remove(nIndex, nCount); } + } - void B2DPolygon::setClosed(sal_Bool bNew) + void B2DPolygon::clear() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->isClosed() != bNew) - { - implForceUniqueCopy(); - mpPolygon->setClosed(bNew); - } + mpPolygon->decRefCount(); + } + else + { + delete mpPolygon; } - void B2DPolygon::flip() + mpPolygon = &maStaticDefaultPolygon; + mpPolygon->incRefCount(); + } + + sal_Bool B2DPolygon::isClosed() const + { + return mpPolygon->isClosed(); + } + + void B2DPolygon::setClosed(sal_Bool bNew) + { + if(mpPolygon->isClosed() != bNew) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->flip(); - } + implForceUniqueCopy(); + mpPolygon->setClosed(bNew); } + } - sal_Bool B2DPolygon::hasDoublePoints() const + void B2DPolygon::flip() + { + if(mpPolygon->count() > 1) { - return mpPolygon->hasDoublePoints(); + implForceUniqueCopy(); + mpPolygon->flip(); } + } - void B2DPolygon::removeDoublePoints() + sal_Bool B2DPolygon::hasDoublePoints() const + { + return mpPolygon->hasDoublePoints(); + } + + void B2DPolygon::removeDoublePoints() + { + if(mpPolygon->count() > 1) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->removeDoublePointsAtBeginEnd(); - mpPolygon->removeDoublePointsWholeTrack(); - } + implForceUniqueCopy(); + mpPolygon->removeDoublePointsAtBeginEnd(); + mpPolygon->removeDoublePointsWholeTrack(); } + } - void B2DPolygon::transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void B2DPolygon::transform(const ::basegfx::B2DHomMatrix& rMatrix) + { + if(mpPolygon->count()) { - if(mpPolygon->count()) - { - implForceUniqueCopy(); - mpPolygon->transform(rMatrix); - } + implForceUniqueCopy(); + mpPolygon->transform(rMatrix); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index c2a6faf8909a..6f5ef6e89fba 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygontools.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:11 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,10 @@ #include <basegfx/polygon/b2dpolygon.hxx> #endif +#ifndef _BGFX_POLYGON_B2DPOLYPOLYGON_HXX +#include <basegfx/polygon/b2dpolypolygon.hxx> +#endif + #ifndef _BGFX_NUMERIC_FTOOLS_HXX #include <basegfx/numeric/ftools.hxx> #endif @@ -91,925 +95,993 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B2DPolygon tools + void checkClosed(B2DPolygon& rCandidate) { - // B2DPolygon tools - void checkClosed(polygon::B2DPolygon& rCandidate) + while(rCandidate.count() > 1L + && rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L))) { - while(rCandidate.count() > 1L - && rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L))) - { - rCandidate.setClosed(sal_True); - rCandidate.remove(rCandidate.count() - 1L); - } + rCandidate.setClosed(sal_True); + rCandidate.remove(rCandidate.count() - 1L); } + } + + // Get index of outmost point (e.g. biggest X and biggest Y) + sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nRetval(0L); - // Get index of outmost point (e.g. biggest X and biggest Y) - sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::polygon::B2DPolygon& rCandidate) + if(rCandidate.count()) { - sal_uInt32 nRetval(0L); + ::basegfx::B2DPoint aOutmostPoint(rCandidate.getB2DPoint(0L)); - if(rCandidate.count()) + for(sal_uInt32 a(1L); a < rCandidate.count(); a++) { - ::basegfx::point::B2DPoint aOutmostPoint(rCandidate.getB2DPoint(0L)); + ::basegfx::B2DPoint rPoint(rCandidate.getB2DPoint(a)); - for(sal_uInt32 a(1L); a < rCandidate.count(); a++) + if(::basegfx::fTools::more(rPoint.getX(), aOutmostPoint.getX())) { - ::basegfx::point::B2DPoint rPoint(rCandidate.getB2DPoint(a)); - - if(::basegfx::numeric::fTools::more(rPoint.getX(), aOutmostPoint.getX())) + nRetval = a; + aOutmostPoint = rPoint; + } + else + { + if(::basegfx::fTools::more(rPoint.getY(), aOutmostPoint.getY())) { nRetval = a; aOutmostPoint = rPoint; } - else - { - if(::basegfx::numeric::fTools::more(rPoint.getY(), aOutmostPoint.getY())) - { - nRetval = a; - aOutmostPoint = rPoint; - } - } } } - - return nRetval; } - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) - { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nRetval; + } - if(nIndex) - { - return nIndex - 1L; - } - else if(rCandidate.count()) - { - return rCandidate.count() - 1L; - } - else - { - return nIndex; - } - } + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + if(nIndex) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - - if(nIndex + 1L < rCandidate.count()) - { - return nIndex + 1L; - } - else - { - return 0L; - } + return nIndex - 1L; } - - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + else if(rCandidate.count()) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - - if(rCandidate.count() > 1) - { - nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); + return rCandidate.count() - 1L; + } + else + { + return nIndex; + } + } - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) - { - nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); - } - } + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - return nNewIndex; + if(nIndex + 1L < rCandidate.count()) + { + return nIndex + 1L; } + else + { + return 0L; + } + } + + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate) + if(rCandidate.count() > 1) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - if(rCandidate.count() > 1) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) { - nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) - { - nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); - } + nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); } - - return nNewIndex; } - ::basegfx::vector::B2DVectorOrientation getOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate) + return nNewIndex; + } + + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(rCandidate.count() > 1) { - ::basegfx::vector::B2DVectorOrientation eRetval(::basegfx::vector::ORIENTATION_NEUTRAL); + nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - if(rCandidate.count() > 2) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB2DPoint(nNewIndex))) { - sal_uInt32 nIndex = getIndexOfOutmostPoint(rCandidate); - eRetval = getPointOrientation(rCandidate, nIndex); + nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); } - - return eRetval; } - ::basegfx::vector::B2DVectorContinuity getContinuityInPoint(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) + return nNewIndex; + } + + ::basegfx::B2DVectorOrientation getOrientation(const ::basegfx::B2DPolygon& rCandidate) + { + ::basegfx::B2DVectorOrientation eRetval(::basegfx::ORIENTATION_NEUTRAL); + + if(rCandidate.count() > 2) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - ::basegfx::vector::B2DVectorContinuity eRetval(::basegfx::vector::CONTINUITY_NONE); + sal_uInt32 nIndex = getIndexOfOutmostPoint(rCandidate); + eRetval = getPointOrientation(rCandidate, nIndex); + } - if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed()) - { - sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); - const ::basegfx::vector::B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex)); - const ::basegfx::vector::B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd)); + return eRetval; + } - eRetval = ::basegfx::vector::getContinuity(aBackVector, aForwardVector); - } + ::basegfx::B2DVectorContinuity getContinuityInPoint(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + ::basegfx::B2DVectorContinuity eRetval(::basegfx::CONTINUITY_NONE); + + if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed()) + { + sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); + const ::basegfx::B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex)); + const ::basegfx::B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd)); - return eRetval; + eRetval = ::basegfx::getContinuity(aBackVector, aForwardVector); } - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistanceBound) + return eRetval; + } + + ::basegfx::B2DPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolygon& rCandidate, double fDistanceBound) + { + ::basegfx::B2DPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aRetval(rCandidate); + const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + aRetval.clear(); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); - aRetval.clear(); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!aVectorA.equalZero() || !aVectorB.equalZero()) { - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - - if(!aVectorA.equalZero() || !aVectorB.equalZero()) - { - // vectors are used, get points - const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); - ::basegfx::point::B2DPoint aPointA(rCandidate.getB2DPoint(a)); - ::basegfx::point::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - - // build CubicBezier segment - ::basegfx::curve::B2DCubicBezier aBezier( - aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - - // generate DistanceBound - double fBound; + // vectors are used, get points + const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); + ::basegfx::B2DPoint aPointA(rCandidate.getB2DPoint(a)); + ::basegfx::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - if(0.0 == fDistanceBound) - { - // If not set, calculate rough length of bezier segment by taking - // half of the sum of the edge and the control polygon - ::basegfx::vector::B2DVector aSimpleDistance(aPointB - aPointA); - ::basegfx::vector::B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA)); - const double fRoughLength( - (aSimpleDistance.getLength() - + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0); - - // take 1/100th of the rouch curve length - fBound = fRoughLength * 0.01; - } - else - { - // use given bound value - fBound = fDistanceBound; - } + // build CubicBezier segment + ::basegfx::B2DCubicBezier aBezier( + aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - // make sure bound value is not too small. The base units are 1/100th mm, thus - // just make sure it's not smaller then 1/100th of that - if(fBound < 0.01) - { - fBound = 0.01; - } + // generate DistanceBound + double fBound; - // call adaptive subdivide - ::basegfx::curve::adaptiveSubdivideByDistance(aRetval, aBezier, fBound); + if(0.0 == fDistanceBound) + { + // If not set, calculate rough length of bezier segment by taking + // half of the sum of the edge and the control polygon + ::basegfx::B2DVector aSimpleDistance(aPointB - aPointA); + ::basegfx::B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA)); + const double fRoughLength( + (aSimpleDistance.getLength() + + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0); + + // take 1/100th of the rouch curve length + fBound = fRoughLength * 0.01; } else { - // no vectors used, add point - aRetval.append(rCandidate.getB2DPoint(a)); + // use given bound value + fBound = fDistanceBound; + } + + // make sure bound value is not too small. The base units are 1/100th mm, thus + // just make sure it's not smaller then 1/100th of that + if(fBound < 0.01) + { + fBound = 0.01; } - } - // check closed flag, aRetval was cleared and thus it may be invalid. - if(aRetval.isClosed() != rCandidate.isClosed()) + // call adaptive subdivide + ::basegfx::adaptiveSubdivideByDistance(aRetval, aBezier, fBound); + } + else { - aRetval.setClosed(rCandidate.isClosed()); + // no vectors used, add point + aRetval.append(rCandidate.getB2DPoint(a)); } } - return aRetval; + // check closed flag, aRetval was cleared and thus it may be invalid. + if(aRetval.isClosed() != rCandidate.isClosed()) + { + aRetval.setClosed(rCandidate.isClosed()); + } } - ::basegfx::polygon::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolygon& rCandidate, double fAngleBound) + return aRetval; + } + + ::basegfx::B2DPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolygon& rCandidate, double fAngleBound) + { + ::basegfx::B2DPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aRetval(rCandidate); + const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + aRetval.clear(); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); - aRetval.clear(); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!aVectorA.equalZero() || !aVectorB.equalZero()) { - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - - if(!aVectorA.equalZero() || !aVectorB.equalZero()) - { - // vectors are used, get points - const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); - ::basegfx::point::B2DPoint aPointA(rCandidate.getB2DPoint(a)); - ::basegfx::point::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); + // vectors are used, get points + const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate)); + ::basegfx::B2DPoint aPointA(rCandidate.getB2DPoint(a)); + ::basegfx::B2DPoint aPointB(rCandidate.getB2DPoint(nNext)); - // build CubicBezier segment - ::basegfx::curve::B2DCubicBezier aBezier( - aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); + // build CubicBezier segment + ::basegfx::B2DCubicBezier aBezier( + aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB); - // generate AngleBound - double fBound(fAngleBound); + // generate AngleBound + double fBound(fAngleBound); - // make sure angle bound is not too small - if(::basegfx::numeric::fTools::less(fAngleBound, 0.1)) - { - fAngleBound = 0.1; - } - - // call adaptive subdivide - ::basegfx::curve::adaptiveSubdivideByAngle(aRetval, aBezier, fBound); - } - else + // make sure angle bound is not too small + if(::basegfx::fTools::less(fAngleBound, 0.1)) { - // no vectors used, add point - aRetval.append(rCandidate.getB2DPoint(a)); + fAngleBound = 0.1; } - } - // check closed flag, aRetval was cleared and thus it may be invalid. - if(aRetval.isClosed() != rCandidate.isClosed()) + // call adaptive subdivide + ::basegfx::adaptiveSubdivideByAngle(aRetval, aBezier, fBound); + } + else { - aRetval.setClosed(rCandidate.isClosed()); + // no vectors used, add point + aRetval.append(rCandidate.getB2DPoint(a)); } } - return aRetval; + // check closed flag, aRetval was cleared and thus it may be invalid. + if(aRetval.isClosed() != rCandidate.isClosed()) + { + aRetval.setClosed(rCandidate.isClosed()); + } } - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder) + return aRetval; + } + + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPoint& rPoint, sal_Bool bWithBorder) + { + sal_Bool bRetval(sal_False); + const sal_uInt32 nPointCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPointCount; a++) { - sal_Bool bRetval(sal_False); - const sal_uInt32 nPointCount(rCandidate.count()); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(bWithBorder && aCurrentPoint.equal(rPoint)) { - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + return sal_True; + } - if(bWithBorder && aCurrentPoint.equal(rPoint)) - { - return sal_True; - } + // cross-over in Y? + const ::basegfx::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); + const sal_Bool bCompYA(::basegfx::fTools::more(aPreviousPoint.getY(), rPoint.getY())); + const sal_Bool bCompYB(::basegfx::fTools::more(aCurrentPoint.getY(), rPoint.getY())); - // cross-over in Y? - const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); - const sal_Bool bCompYA(::basegfx::numeric::fTools::more(aPreviousPoint.getY(), rPoint.getY())); - const sal_Bool bCompYB(::basegfx::numeric::fTools::more(aCurrentPoint.getY(), rPoint.getY())); + if(bCompYA != bCompYB) + { + const sal_Bool bCompXA(::basegfx::fTools::more(aPreviousPoint.getX(), rPoint.getX())); + const sal_Bool bCompXB(::basegfx::fTools::more(aCurrentPoint.getX(), rPoint.getX())); - if(bCompYA != bCompYB) + if(bCompXA == bCompXB) { - const sal_Bool bCompXA(::basegfx::numeric::fTools::more(aPreviousPoint.getX(), rPoint.getX())); - const sal_Bool bCompXB(::basegfx::numeric::fTools::more(aCurrentPoint.getX(), rPoint.getX())); + if(bCompXA) + { + bRetval = !bRetval; + } + } + else + { + const double fCompare = + aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * + (aPreviousPoint.getX() - aCurrentPoint.getX()) / + (aPreviousPoint.getY() - aCurrentPoint.getY()); - if(bCompXA == bCompXB) + if(bWithBorder && ::basegfx::fTools::more(fCompare, rPoint.getX())) { - if(bCompXA) - { - bRetval = !bRetval; - } + bRetval = !bRetval; } - else + else if(::basegfx::fTools::moreOrEqual(fCompare, rPoint.getX())) { - const double fCompare = - aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * - (aPreviousPoint.getX() - aCurrentPoint.getX()) / - (aPreviousPoint.getY() - aCurrentPoint.getY()); - - if(bWithBorder && ::basegfx::numeric::fTools::more(fCompare, rPoint.getX())) - { - bRetval = !bRetval; - } - else if(::basegfx::numeric::fTools::moreOrEqual(fCompare, rPoint.getX())) - { - bRetval = !bRetval; - } + bRetval = !bRetval; } } } - - return bRetval; } - sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_Bool bWithBorder) + return bRetval; + } + + sal_Bool isInside(const ::basegfx::B2DPolygon& rCandidate, const ::basegfx::B2DPolygon& rPolygon, sal_Bool bWithBorder) + { + const sal_uInt32 nPointCount(rPolygon.count()); + + for(sal_uInt32 a(0L); a < nPointCount; a++) { - const sal_uInt32 nPointCount(rPolygon.count()); + const ::basegfx::B2DPoint aTestPoint(rPolygon.getB2DPoint(a)); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(!isInside(rCandidate, aTestPoint, bWithBorder)) { - const ::basegfx::point::B2DPoint aTestPoint(rPolygon.getB2DPoint(a)); - - if(!isInside(rCandidate, aTestPoint, bWithBorder)) - { - return sal_False; - } + return sal_False; } - - return sal_True; } - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolygon& rCandidate) - { - ::basegfx::range::B2DRange aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + return sal_True; + } + + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolygon& rCandidate) + { + ::basegfx::B2DRange aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - if(rCandidate.areControlPointsUsed()) + if(rCandidate.areControlPointsUsed()) + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); - const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a)); - const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a)); - aRetval.expand(aTestPoint); + const ::basegfx::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DVector aVectorA(rCandidate.getControlVectorA(a)); + const ::basegfx::B2DVector aVectorB(rCandidate.getControlVectorB(a)); + aRetval.expand(aTestPoint); - if(!aVectorA.equalZero()) - { - aRetval.expand(aTestPoint + aVectorA); - } + if(!aVectorA.equalZero()) + { + aRetval.expand(aTestPoint + aVectorA); + } - if(!aVectorB.equalZero()) - { - const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - aRetval.expand(aNextPoint + aVectorB); - } + if(!aVectorB.equalZero()) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + aRetval.expand(aNextPoint + aVectorB); } } - else + } + else + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); - aRetval.expand(aTestPoint); - } + const ::basegfx::B2DPoint aTestPoint(rCandidate.getB2DPoint(a)); + aRetval.expand(aTestPoint); } - - return aRetval; } - double getArea(const ::basegfx::polygon::B2DPolygon& rCandidate) - { - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + return aRetval; + } - if(nPointCount > 2) + double getArea(const ::basegfx::B2DPolygon& rCandidate) + { + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + + if(nPointCount > 2) + { + for(sal_uInt32 a(0L); a < nPointCount; a++) { - for(sal_uInt32 a(0L); a < nPointCount; a++) - { - const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - fRetval += aPreviousPoint.getX() * aCurrentPoint.getY(); - fRetval -= aPreviousPoint.getY() * aCurrentPoint.getX(); - } + fRetval += aPreviousPoint.getX() * aCurrentPoint.getY(); + fRetval -= aPreviousPoint.getY() * aCurrentPoint.getX(); + } - fRetval /= 2.0; + fRetval /= 2.0; - const double fZero(0.0); + const double fZero(0.0); - if(::basegfx::numeric::fTools::less(fRetval, fZero)) - { - fRetval = -fRetval; - } + if(::basegfx::fTools::less(fRetval, fZero)) + { + fRetval = -fRetval; } - - return fRetval; } - double getEdgeLength(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) - { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + return fRetval; + } + + double getEdgeLength(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); - if(nIndex < nPointCount) + if(nIndex < nPointCount) + { + if(rCandidate.isClosed() || nIndex + 1 != nPointCount) { - if(rCandidate.isClosed() || nIndex + 1 != nPointCount) - { - const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(nIndex)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - const ::basegfx::vector::B2DVector aVector(aNextPoint - aCurrentPoint); - fRetval = aVector.getLength(); - } + const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(nIndex)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aNextPoint - aCurrentPoint); + fRetval = aVector.getLength(); } + } + + return fRetval; + } - return fRetval; + double getLength(const ::basegfx::B2DPolygon& rCandidate) + { + // This method may also be implemented using a loop over getEdgeLength, but + // since this would cause a lot of sqare roots to be solved it is much better + // to sum up the quadrats first and then use a singe suare root (if necessary) + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); + const ::basegfx::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aNextPoint - aCurrentPoint); + fRetval += aVector.scalar(aVector); } - double getLength(const ::basegfx::polygon::B2DPolygon& rCandidate) + if(!::basegfx::fTools::equalZero(fRetval)) { - // This method may also be implemented using a loop over getEdgeLength, but - // since this would cause a lot of sqare roots to be solved it is much better - // to sum up the quadrats first and then use a singe suare root (if necessary) - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); - const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + const double fOne(1.0); - for(sal_uInt32 a(0L); a < nLoopCount; a++) + if(!::basegfx::fTools::equal(fOne, fRetval)) { - const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); - const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - const ::basegfx::vector::B2DVector aVector(aNextPoint - aCurrentPoint); - fRetval += aVector.scalar(aVector); + fRetval = sqrt(fRetval); } + } - if(!::basegfx::numeric::fTools::equalZero(fRetval)) - { - const double fOne(1.0); + return fRetval; + } - if(!::basegfx::numeric::fTools::equal(fOne, fRetval)) - { - fRetval = sqrt(fRetval); - } - } - - return fRetval; - } + ::basegfx::B2DPoint getPositionAbsolute(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength) + { + ::basegfx::B2DPoint aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - ::basegfx::point::B2DPoint getPositionAbsolute(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength) + if(nPointCount > 1L) { - ::basegfx::point::B2DPoint aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + sal_uInt32 nIndex(0L); + sal_Bool bIndexDone(sal_False); + const double fZero(0.0); + double fEdgeLength(fZero); - if(nPointCount > 1L) + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) { - sal_uInt32 nIndex(0L); - sal_Bool bIndexDone(sal_False); - const double fZero(0.0); - double fEdgeLength(fZero); + fLength = getLength(rCandidate); + } - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) + // handle fDistance < 0.0 + if(::basegfx::fTools::less(fDistance, fZero)) + { + if(rCandidate.isClosed()) { - fLength = getLength(rCandidate); + // if fDistance < 0.0 increment with multiple of fLength + sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); + fDistance += double(nCount + 1L) * fLength; } + else + { + // crop to polygon start + fDistance = fZero; + bIndexDone = sal_True; + } + } - // handle fDistance < 0.0 - if(::basegfx::numeric::fTools::less(fDistance, fZero)) + // handle fDistance >= fLength + if(::basegfx::fTools::moreOrEqual(fDistance, fLength)) + { + if(rCandidate.isClosed()) { - if(rCandidate.isClosed()) - { - // if fDistance < 0.0 increment with multiple of fLength - sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); - fDistance += double(nCount + 1L) * fLength; - } - else - { - // crop to polygon start - fDistance = fZero; - bIndexDone = sal_True; - } + // if fDistance >= fLength decrement with multiple of fLength + sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); + fDistance -= (double)(nCount) * fLength; + } + else + { + // crop to polygon end + fDistance = fZero; + nIndex = nPointCount - 1L; + bIndexDone = sal_True; } + } - // handle fDistance >= fLength - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fLength)) + // look for correct index. fDistance is now [0.0 .. fLength[ + if(!bIndexDone) + { + do { - if(rCandidate.isClosed()) + // get length of next edge + fEdgeLength = getEdgeLength(rCandidate, nIndex); + + if(::basegfx::fTools::moreOrEqual(fDistance, fEdgeLength)) { - // if fDistance >= fLength decrement with multiple of fLength - sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); - fDistance -= (double)(nCount) * fLength; + // go to next edge + fDistance -= fEdgeLength; + nIndex++; } else { - // crop to polygon end - fDistance = fZero; - nIndex = nPointCount - 1L; + // it's on this edge, stop bIndexDone = sal_True; } - } - - // look for correct index. fDistance is now [0.0 .. fLength[ - if(!bIndexDone) - { - do - { - // get length of next edge - fEdgeLength = getEdgeLength(rCandidate, nIndex); + } while (!bIndexDone); + } - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fEdgeLength)) - { - // go to next edge - fDistance -= fEdgeLength; - nIndex++; - } - else - { - // it's on this edge, stop - bIndexDone = sal_True; - } - } while (!bIndexDone); - } + // get the point using nIndex + aRetval = rCandidate.getB2DPoint(nIndex); - // get the point using nIndex - aRetval = rCandidate.getB2DPoint(nIndex); + // if fDistance != 0.0, move that length on the edge. The edge + // length is in fEdgeLength. + if(!::basegfx::fTools::equalZero(fDistance)) + { + sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); + const ::basegfx::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); + double fRelative(fZero); - // if fDistance != 0.0, move that length on the edge. The edge - // length is in fEdgeLength. - if(!::basegfx::numeric::fTools::equalZero(fDistance)) + if(!::basegfx::fTools::equalZero(fEdgeLength)) { - sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); - const ::basegfx::point::B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - double fRelative(fZero); - - if(!::basegfx::numeric::fTools::equalZero(fEdgeLength)) - { - fRelative = fDistance / fEdgeLength; - } - - // add calculated average value to the return value - aRetval += ::basegfx::tuple::average(aRetval, aNextPoint, fRelative); + fRelative = fDistance / fEdgeLength; } - } - return aRetval; + // add calculated average value to the return value + aRetval = ::basegfx::interpolate(aRetval, aNextPoint, fRelative); + } } - ::basegfx::point::B2DPoint getPositionRelative(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistance, double fLength) - { - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) - { - fLength = getLength(rCandidate); - } + return aRetval; + } - // multiply fDistance with real length to get absolute position and - // use getPositionAbsolute - return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + ::basegfx::B2DPoint getPositionRelative(const ::basegfx::B2DPolygon& rCandidate, double fDistance, double fLength) + { + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) + { + fLength = getLength(rCandidate); } - ::basegfx::vector::B2DVectorOrientation getPointOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex) + // multiply fDistance with real length to get absolute position and + // use getPositionAbsolute + return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + } + + ::basegfx::B2DVectorOrientation getPointOrientation(const ::basegfx::B2DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + ::basegfx::B2DVectorOrientation eRetval(::basegfx::ORIENTATION_NEUTRAL); + + if(rCandidate.count() > 2) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - ::basegfx::vector::B2DVectorOrientation eRetval(::basegfx::vector::ORIENTATION_NEUTRAL); + sal_uInt32 nIndPrev = getIndexOfDifferentPredecessor(nIndex, rCandidate); - if(rCandidate.count() > 2) + if(nIndPrev != nIndex) { - sal_uInt32 nIndPrev = getIndexOfDifferentPredecessor(nIndex, rCandidate); + sal_uInt32 nIndNext = getIndexOfDifferentSuccessor(nIndex, rCandidate); - if(nIndPrev != nIndex) + if(nIndNext != nIndex && nIndNext != nIndPrev) { - sal_uInt32 nIndNext = getIndexOfDifferentSuccessor(nIndex, rCandidate); - - if(nIndNext != nIndex && nIndNext != nIndPrev) - { - ::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); - ::basegfx::vector::B2DVector aVecPrev(rCandidate.getB2DPoint(nIndPrev) - aPoint); - ::basegfx::vector::B2DVector aVecNext(rCandidate.getB2DPoint(nIndNext) - aPoint); - eRetval = ::basegfx::vector::getOrientation(aVecPrev, aVecNext); - } + ::basegfx::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex)); + ::basegfx::B2DVector aVecPrev(rCandidate.getB2DPoint(nIndPrev) - aPoint); + ::basegfx::B2DVector aVecNext(rCandidate.getB2DPoint(nIndNext) - aPoint); + eRetval = ::basegfx::getOrientation(aVecPrev, aVecNext); } } - - return eRetval; } - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate, - sal_uInt32 nIndex1, sal_uInt32 nIndex2, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - const sal_uInt32 nPointCount(rCandidate.count()); + return eRetval; + } - if(nIndex1 < nPointCount && nIndex2 < nPointCount && nIndex1 != nIndex2) - { - sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate)); - sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate)); + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate, + sal_uInt32 nIndex1, sal_uInt32 nIndex2, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + const sal_uInt32 nPointCount(rCandidate.count()); - const ::basegfx::point::B2DPoint aStart1(rCandidate.getB2DPoint(nIndex1)); - const ::basegfx::point::B2DPoint aEnd1(rCandidate.getB2DPoint(nEnd1)); - const ::basegfx::vector::B2DVector aVector1(aEnd1 - aStart1); + if(nIndex1 < nPointCount && nIndex2 < nPointCount && nIndex1 != nIndex2) + { + sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate)); + sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate)); - const ::basegfx::point::B2DPoint aStart2(rCandidate.getB2DPoint(nIndex2)); - const ::basegfx::point::B2DPoint aEnd2(rCandidate.getB2DPoint(nEnd2)); - const ::basegfx::vector::B2DVector aVector2(aEnd2 - aStart2); + const ::basegfx::B2DPoint aStart1(rCandidate.getB2DPoint(nIndex1)); + const ::basegfx::B2DPoint aEnd1(rCandidate.getB2DPoint(nEnd1)); + const ::basegfx::B2DVector aVector1(aEnd1 - aStart1); - aRetval = findCut( - aStart1, aVector1, aStart2, aVector2, - aCutFlags, pCut1, pCut2); - } + const ::basegfx::B2DPoint aStart2(rCandidate.getB2DPoint(nIndex2)); + const ::basegfx::B2DPoint aEnd2(rCandidate.getB2DPoint(nEnd2)); + const ::basegfx::B2DVector aVector2(aEnd2 - aStart2); - return aRetval; + aRetval = findCut( + aStart1, aVector1, aStart2, aVector2, + aCutFlags, pCut1, pCut2); } - CutFlagValue findCut( - const ::basegfx::polygon::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, - const ::basegfx::polygon::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - const sal_uInt32 nPointCount1(rCandidate1.count()); - const sal_uInt32 nPointCount2(rCandidate2.count()); + return aRetval; + } - if(nIndex1 < nPointCount1 && nIndex2 < nPointCount2) - { - sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate1)); - sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate2)); + CutFlagValue findCut( + const ::basegfx::B2DPolygon& rCandidate1, sal_uInt32 nIndex1, + const ::basegfx::B2DPolygon& rCandidate2, sal_uInt32 nIndex2, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + const sal_uInt32 nPointCount1(rCandidate1.count()); + const sal_uInt32 nPointCount2(rCandidate2.count()); - const ::basegfx::point::B2DPoint aStart1(rCandidate1.getB2DPoint(nIndex1)); - const ::basegfx::point::B2DPoint aEnd1(rCandidate1.getB2DPoint(nEnd1)); - const ::basegfx::vector::B2DVector aVector1(aEnd1 - aStart1); + if(nIndex1 < nPointCount1 && nIndex2 < nPointCount2) + { + sal_uInt32 nEnd1(getIndexOfSuccessor(nIndex1, rCandidate1)); + sal_uInt32 nEnd2(getIndexOfSuccessor(nIndex2, rCandidate2)); - const ::basegfx::point::B2DPoint aStart2(rCandidate2.getB2DPoint(nIndex2)); - const ::basegfx::point::B2DPoint aEnd2(rCandidate2.getB2DPoint(nEnd2)); - const ::basegfx::vector::B2DVector aVector2(aEnd2 - aStart2); + const ::basegfx::B2DPoint aStart1(rCandidate1.getB2DPoint(nIndex1)); + const ::basegfx::B2DPoint aEnd1(rCandidate1.getB2DPoint(nEnd1)); + const ::basegfx::B2DVector aVector1(aEnd1 - aStart1); - aRetval = findCut( - aStart1, aVector1, aStart2, aVector2, - aCutFlags, pCut1, pCut2); - } + const ::basegfx::B2DPoint aStart2(rCandidate2.getB2DPoint(nIndex2)); + const ::basegfx::B2DPoint aEnd2(rCandidate2.getB2DPoint(nEnd2)); + const ::basegfx::B2DVector aVector2(aEnd2 - aStart2); - return aRetval; + aRetval = findCut( + aStart1, aVector1, aStart2, aVector2, + aCutFlags, pCut1, pCut2); } - CutFlagValue findCut( - const ::basegfx::point::B2DPoint& rEdge1Start, const ::basegfx::vector::B2DVector& rEdge1Delta, - const ::basegfx::point::B2DPoint& rEdge2Start, const ::basegfx::vector::B2DVector& rEdge2Delta, - CutFlagValue aCutFlags, - double* pCut1, double* pCut2) - { - CutFlagValue aRetval(CUTFLAG_NONE); - double fCut1(0.0); - double fCut2(0.0); - sal_Bool bFinished(!((sal_Bool)(aCutFlags & CUTFLAG_ALL))); + return aRetval; + } - // test for same points? - if(!bFinished - && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END1)) - && (aCutFlags & (CUTFLAG_START2|CUTFLAG_END2))) + CutFlagValue findCut( + const ::basegfx::B2DPoint& rEdge1Start, const ::basegfx::B2DVector& rEdge1Delta, + const ::basegfx::B2DPoint& rEdge2Start, const ::basegfx::B2DVector& rEdge2Delta, + CutFlagValue aCutFlags, + double* pCut1, double* pCut2) + { + CutFlagValue aRetval(CUTFLAG_NONE); + double fCut1(0.0); + double fCut2(0.0); + sal_Bool bFinished(!((sal_Bool)(aCutFlags & CUTFLAG_ALL))); + + // test for same points? + if(!bFinished + && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END1)) + && (aCutFlags & (CUTFLAG_START2|CUTFLAG_END2))) + { + // same startpoint? + if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_START2)) == (CUTFLAG_START1|CUTFLAG_START2)) { - // same startpoint? - if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_START2)) == (CUTFLAG_START1|CUTFLAG_START2)) + if(rEdge1Start.equal(rEdge2Start)) { - if(rEdge1Start.equal(rEdge2Start)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START1|CUTFLAG_START2); - } + bFinished = sal_True; + aRetval = (CUTFLAG_START1|CUTFLAG_START2); } + } - // same endpoint? - if(!bFinished && (aCutFlags & (CUTFLAG_END1|CUTFLAG_END2)) == (CUTFLAG_END1|CUTFLAG_END2)) - { - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + // same endpoint? + if(!bFinished && (aCutFlags & (CUTFLAG_END1|CUTFLAG_END2)) == (CUTFLAG_END1|CUTFLAG_END2)) + { + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(aEnd1.equal(aEnd2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_END1|CUTFLAG_END2); - fCut1 = fCut2 = 1.0; - } + if(aEnd1.equal(aEnd2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_END1|CUTFLAG_END2); + fCut1 = fCut2 = 1.0; } + } - // startpoint1 == endpoint2? - if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END2)) == (CUTFLAG_START1|CUTFLAG_END2)) - { - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + // startpoint1 == endpoint2? + if(!bFinished && (aCutFlags & (CUTFLAG_START1|CUTFLAG_END2)) == (CUTFLAG_START1|CUTFLAG_END2)) + { + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(rEdge1Start.equal(aEnd2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START1|CUTFLAG_END2); - fCut1 = 0.0; - fCut2 = 1.0; - } + if(rEdge1Start.equal(aEnd2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_START1|CUTFLAG_END2); + fCut1 = 0.0; + fCut2 = 1.0; } + } - // startpoint2 == endpoint1? - if(!bFinished&& (aCutFlags & (CUTFLAG_START2|CUTFLAG_END1)) == (CUTFLAG_START2|CUTFLAG_END1)) - { - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + // startpoint2 == endpoint1? + if(!bFinished&& (aCutFlags & (CUTFLAG_START2|CUTFLAG_END1)) == (CUTFLAG_START2|CUTFLAG_END1)) + { + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - if(rEdge2Start.equal(aEnd1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_START2|CUTFLAG_END1); - fCut1 = 1.0; - fCut2 = 0.0; - } + if(rEdge2Start.equal(aEnd1)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_START2|CUTFLAG_END1); + fCut1 = 1.0; + fCut2 = 0.0; } } + } - if(!bFinished && (aCutFlags & CUTFLAG_LINE)) + if(!bFinished && (aCutFlags & CUTFLAG_LINE)) + { + if(!bFinished && (aCutFlags & CUTFLAG_START1)) { - if(!bFinished && (aCutFlags & CUTFLAG_START1)) + // start1 on line 2 ? + if(isPointOnEdge(rEdge1Start, rEdge2Start, rEdge2Delta, &fCut2)) { - // start1 on line 2 ? - if(isPointOnEdge(rEdge1Start, rEdge2Start, rEdge2Delta, &fCut2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_START1); - } + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_START1); } + } - if(!bFinished && (aCutFlags & CUTFLAG_START2)) + if(!bFinished && (aCutFlags & CUTFLAG_START2)) + { + // start2 on line 1 ? + if(isPointOnEdge(rEdge2Start, rEdge1Start, rEdge1Delta, &fCut1)) { - // start2 on line 1 ? - if(isPointOnEdge(rEdge2Start, rEdge1Start, rEdge1Delta, &fCut1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_START2); - } + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_START2); } + } - if(!bFinished && (aCutFlags & CUTFLAG_END1)) - { - // end1 on line 2 ? - const ::basegfx::point::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); + if(!bFinished && (aCutFlags & CUTFLAG_END1)) + { + // end1 on line 2 ? + const ::basegfx::B2DPoint aEnd1(rEdge1Start + rEdge1Delta); - if(isPointOnEdge(aEnd1, rEdge2Start, rEdge2Delta, &fCut2)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_END1); - } + if(isPointOnEdge(aEnd1, rEdge2Start, rEdge2Delta, &fCut2)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_END1); } + } - if(!bFinished && (aCutFlags & CUTFLAG_END2)) - { - // end2 on line 1 ? - const ::basegfx::point::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); + if(!bFinished && (aCutFlags & CUTFLAG_END2)) + { + // end2 on line 1 ? + const ::basegfx::B2DPoint aEnd2(rEdge2Start + rEdge2Delta); - if(isPointOnEdge(aEnd2, rEdge1Start, rEdge1Delta, &fCut1)) - { - bFinished = sal_True; - aRetval = (CUTFLAG_LINE|CUTFLAG_END2); - } + if(isPointOnEdge(aEnd2, rEdge1Start, rEdge1Delta, &fCut1)) + { + bFinished = sal_True; + aRetval = (CUTFLAG_LINE|CUTFLAG_END2); } + } + + if(!bFinished) + { + // cut in line1, line2 ? + fCut1 = (rEdge1Delta.getX() * rEdge2Delta.getY()) - (rEdge1Delta.getY() * rEdge2Delta.getX()); - if(!bFinished) + if(!::basegfx::fTools::equalZero(fCut1)) { - // cut in line1, line2 ? - fCut1 = (rEdge1Delta.getX() * rEdge2Delta.getY()) - (rEdge1Delta.getY() * rEdge2Delta.getX()); + fCut1 = (rEdge2Delta.getY() * (rEdge2Start.getX() - rEdge1Start.getX()) + + rEdge2Delta.getX() * (rEdge1Start.getY() - rEdge2Start.getY())) / fCut1; - if(!::basegfx::numeric::fTools::equalZero(fCut1)) - { - fCut1 = (rEdge2Delta.getY() * (rEdge2Start.getX() - rEdge1Start.getX()) - + rEdge2Delta.getX() * (rEdge1Start.getY() - rEdge2Start.getY())) / fCut1; + const double fZero(0.0); + const double fOne(1.0); - const double fZero(0.0); - const double fOne(1.0); + // inside parameter range edge1 AND fCut2 is calcable + if(::basegfx::fTools::more(fCut1, fZero) && ::basegfx::fTools::less(fCut1, fOne) + && (!::basegfx::fTools::equalZero(rEdge2Delta.getX()) || !::basegfx::fTools::equalZero(rEdge2Delta.getY()))) + { + // take the mopre precise calculation of the two possible + if(fabs(rEdge2Delta.getX()) > fabs(rEdge2Delta.getY())) + { + fCut2 = (rEdge1Start.getX() + fCut1 + * rEdge1Delta.getX() - rEdge2Start.getX()) / rEdge2Delta.getX(); + } + else + { + fCut2 = (rEdge1Start.getY() + fCut1 + * rEdge1Delta.getY() - rEdge2Start.getY()) / rEdge2Delta.getY(); + } - // inside parameter range edge1 AND fCut2 is calcable - if(::basegfx::numeric::fTools::more(fCut1, fZero) && ::basegfx::numeric::fTools::less(fCut1, fOne) - && (!::basegfx::numeric::fTools::equalZero(rEdge2Delta.getX()) || !::basegfx::numeric::fTools::equalZero(rEdge2Delta.getY()))) + // inside parameter range edge2, too + if(::basegfx::fTools::more(fCut2, fZero) && ::basegfx::fTools::less(fCut2, fOne)) { - // take the mopre precise calculation of the two possible - if(fabs(rEdge2Delta.getX()) > fabs(rEdge2Delta.getY())) - { - fCut2 = (rEdge1Start.getX() + fCut1 - * rEdge1Delta.getX() - rEdge2Start.getX()) / rEdge2Delta.getX(); - } - else - { - fCut2 = (rEdge1Start.getY() + fCut1 - * rEdge1Delta.getY() - rEdge2Start.getY()) / rEdge2Delta.getY(); - } - - // inside parameter range edge2, too - if(::basegfx::numeric::fTools::more(fCut2, fZero) && ::basegfx::numeric::fTools::less(fCut2, fOne)) - { - bFinished = sal_True; - aRetval = CUTFLAG_LINE; - } + bFinished = sal_True; + aRetval = CUTFLAG_LINE; } } } } + } - // copy values if wanted - if(pCut1) - { - *pCut1 = fCut1; - } - - if(pCut2) - { - *pCut2 = fCut2; - } - - return aRetval; + // copy values if wanted + if(pCut1) + { + *pCut1 = fCut1; } - sal_Bool isPointOnEdge( - const ::basegfx::point::B2DPoint& rPoint, - const ::basegfx::point::B2DPoint& rEdgeStart, - const ::basegfx::vector::B2DVector& rEdgeDelta, - double* pCut) + if(pCut2) { - sal_Bool bDeltaXIsZero(::basegfx::numeric::fTools::equalZero(rEdgeDelta.getX())); - sal_Bool bDeltaYIsZero(::basegfx::numeric::fTools::equalZero(rEdgeDelta.getY())); - const double fZero(0.0); - const double fOne(1.0); + *pCut2 = fCut2; + } - if(bDeltaXIsZero && bDeltaYIsZero) - { - // no line, just a point - return sal_False; - } - else if(bDeltaXIsZero) + return aRetval; + } + + sal_Bool isPointOnEdge( + const ::basegfx::B2DPoint& rPoint, + const ::basegfx::B2DPoint& rEdgeStart, + const ::basegfx::B2DVector& rEdgeDelta, + double* pCut) + { + sal_Bool bDeltaXIsZero(::basegfx::fTools::equalZero(rEdgeDelta.getX())); + sal_Bool bDeltaYIsZero(::basegfx::fTools::equalZero(rEdgeDelta.getY())); + const double fZero(0.0); + const double fOne(1.0); + + if(bDeltaXIsZero && bDeltaYIsZero) + { + // no line, just a point + return sal_False; + } + else if(bDeltaXIsZero) + { + // vertical line + if(::basegfx::fTools::equal(rPoint.getX(), rEdgeStart.getX())) { - // vertical line - if(::basegfx::numeric::fTools::equal(rPoint.getX(), rEdgeStart.getX())) - { - double fValue = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + double fValue = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); - if(::basegfx::numeric::fTools::more(fValue, fZero) && ::basegfx::numeric::fTools::less(fValue, fOne)) + if(::basegfx::fTools::more(fValue, fZero) && ::basegfx::fTools::less(fValue, fOne)) + { + if(pCut) { - if(pCut) - { - *pCut = fValue; - } - - return sal_True; + *pCut = fValue; } + + return sal_True; } } - else if(bDeltaYIsZero) + } + else if(bDeltaYIsZero) + { + // horizontal line + if(::basegfx::fTools::equal(rPoint.getY(), rEdgeStart.getY())) { - // horizontal line - if(::basegfx::numeric::fTools::equal(rPoint.getY(), rEdgeStart.getY())) - { - double fValue = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); + double fValue = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); - if(::basegfx::numeric::fTools::more(fValue, fZero) - && ::basegfx::numeric::fTools::less(fValue, fOne)) + if(::basegfx::fTools::more(fValue, fZero) + && ::basegfx::fTools::less(fValue, fOne)) + { + if(pCut) { - if(pCut) - { - *pCut = fValue; - } - - return sal_True; + *pCut = fValue; } + + return sal_True; } } - else + } + else + { + // any angle line + double fTOne = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); + double fTTwo = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + + if(::basegfx::fTools::equal(fTOne, fTTwo)) { - // any angle line - double fTOne = (rPoint.getX() - rEdgeStart.getX()) / rEdgeDelta.getX(); - double fTTwo = (rPoint.getY() - rEdgeStart.getY()) / rEdgeDelta.getY(); + // same parameter representation, point is on line. Take + // middle value for better results + double fValue = (fTOne + fTTwo) / 2.0; - if(::basegfx::numeric::fTools::equal(fTOne, fTTwo)) + if(::basegfx::fTools::more(fValue, fZero) && ::basegfx::fTools::less(fValue, fOne)) { - // same parameter representation, point is on line. Take - // middle value for better results - double fValue = (fTOne + fTTwo) / 2.0; + // point is inside line bounds, too + if(pCut) + { + *pCut = fValue; + } + + return sal_True; + } + } + } - if(::basegfx::numeric::fTools::more(fValue, fZero) && ::basegfx::numeric::fTools::less(fValue, fOne)) + return sal_False; + } + + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B2DPolyPolygon aRetval; + + if(rCandidate.count() && fFullDashDotLen > 0.0) + { + const sal_uInt32 nCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + sal_uInt32 nDashDotIndex(0L); + double fDashDotLength(raDashDotArray[nDashDotIndex]); + + for(sal_uInt32 a(0L); a < nCount; a++) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B2DPoint aStart(rCandidate.getB2DPoint(a)); + const ::basegfx::B2DPoint aEnd(rCandidate.getB2DPoint(nNextIndex)); + const ::basegfx::B2DVector aVector(aEnd - aStart); + double fLength(aVector.getLength()); + double fPosOnVector(0.0); + + while(fLength >= fDashDotLength) + { + // handle [fPosOnVector .. fPosOnVector+fDashDotLength] + if(nDashDotIndex % 2) { - // point is inside line bounds, too - if(pCut) + ::basegfx::B2DPolygon aResult; + + // add start point + if(fPosOnVector == 0.0) + { + aResult.append(aStart); + } + else { - *pCut = fValue; + aResult.append(aStart + (aVector * fPosOnVector)); } - return sal_True; + // add end point + aResult.append(aStart + (aVector * (fPosOnVector + fDashDotLength))); + + // add line to PolyPolygon + aRetval.append(aResult); } + + // consume from fDashDotLength + fPosOnVector += fDashDotLength; + fLength -= fDashDotLength; + nDashDotIndex = (nDashDotIndex + 1L) % raDashDotArray.size(); + fDashDotLength = raDashDotArray[nDashDotIndex]; } - } - return sal_False; + // handle [fPosOnVector .. fPosOnVector+fLength (bzw. end)] + if((fLength > 0.0) && (nDashDotIndex % 2)) + { + ::basegfx::B2DPolygon aResult; + + // add start and end point + const ::basegfx::B2DPoint aPosA(aStart + (aVector * fPosOnVector)); + aResult.append(aPosA); + + // add line to PolyPolygon + aRetval.append(aResult); + } + + // consume from fDashDotLength + fDashDotLength -= fLength; + } } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx index 301d5a68edd8..f6fcbd9c0e55 100644 --- a/basegfx/source/polygon/b2dpolypolygon.cxx +++ b/basegfx/source/polygon/b2dpolypolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygon.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:11 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,7 +81,7 @@ class ImplB2DPolyPolygon { - typedef ::std::vector< ::basegfx::polygon::B2DPolygon > PolygonVector; + typedef ::std::vector< ::basegfx::B2DPolygon > PolygonVector; PolygonVector maPolygons; sal_uInt32 mnRefCount; @@ -127,17 +127,17 @@ public: return sal_True; } - const ::basegfx::polygon::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const + const ::basegfx::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const { return maPolygons[nIndex]; } - void setB2DPolygon(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rPolygon) + void setB2DPolygon(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rPolygon) { maPolygons[nIndex] = rPolygon; } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) { @@ -148,7 +148,7 @@ public: } } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolyPolygon& rPolyPolygon) + void insert(sal_uInt32 nIndex, const ::basegfx::B2DPolyPolygon& rPolyPolygon) { const sal_uInt32 nCount = rPolyPolygon.count(); @@ -209,7 +209,7 @@ public: } } - void transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + void transform(const ::basegfx::B2DHomMatrix& rMatrix) { for(sal_uInt32 a(0L); a < maPolygons.size(); a++) { @@ -222,247 +222,244 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB2DPolyPolygon maStaticDefaultPolyPolygon; + // init static default Polygon + static ImplB2DPolyPolygon maStaticDefaultPolyPolygon; - void B2DPolyPolygon::implForceUniqueCopy() + void B2DPolyPolygon::implForceUniqueCopy() + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - mpPolyPolygon = new ImplB2DPolyPolygon(*mpPolyPolygon); - } + mpPolyPolygon->decRefCount(); + mpPolyPolygon = new ImplB2DPolyPolygon(*mpPolyPolygon); } + } - B2DPolyPolygon::B2DPolyPolygon() - : mpPolyPolygon(&maStaticDefaultPolyPolygon) - { - mpPolyPolygon->incRefCount(); - } + B2DPolyPolygon::B2DPolyPolygon() + : mpPolyPolygon(&maStaticDefaultPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } - B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) - : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) + : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B2DPolyPolygon::~B2DPolyPolygon() + { + if(mpPolyPolygon->getRefCount()) { - mpPolyPolygon->incRefCount(); + mpPolyPolygon->decRefCount(); } - - B2DPolyPolygon::~B2DPolyPolygon() + else { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + delete mpPolyPolygon; } + } - B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon) + B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon) + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } - - mpPolyPolygon = rPolyPolygon.mpPolyPolygon; - mpPolyPolygon->incRefCount(); - - return *this; + mpPolyPolygon->decRefCount(); } - - sal_Bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const + else { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_True; - } - - return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + delete mpPolyPolygon; } - sal_Bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const - { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_False; - } + mpPolyPolygon = rPolyPolygon.mpPolyPolygon; + mpPolyPolygon->incRefCount(); - return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); - } + return *this; + } - sal_uInt32 B2DPolyPolygon::count() const + sal_Bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - return mpPolyPolygon->count(); + return sal_True; } - B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - return mpPolyPolygon->getB2DPolygon(nIndex); + sal_Bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) + { + return sal_False; } - void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - if(mpPolyPolygon->getB2DPolygon(nIndex) != rPolygon) - { - implForceUniqueCopy(); - mpPolyPolygon->setB2DPolygon(nIndex, rPolygon); - } - } + sal_uInt32 B2DPolyPolygon::count() const + { + return mpPolyPolygon->count(); + } - sal_Bool B2DPolyPolygon::areControlPointsUsed() const - { - for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++) - { - const ::basegfx::polygon::B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a); + B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); - if(rPolygon.areControlPointsUsed()) - { - return sal_True; - } - } + return mpPolyPolygon->getB2DPolygon(nIndex); + } - return sal_False; + void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + + if(mpPolyPolygon->getB2DPolygon(nIndex) != rPolygon) + { + implForceUniqueCopy(); + mpPolyPolygon->setB2DPolygon(nIndex, rPolygon); } + } - void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) + sal_Bool B2DPolyPolygon::areControlPointsUsed() const + { + for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + const ::basegfx::B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a); - if(nCount) + if(rPolygon.areControlPointsUsed()) { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolygon, nCount); + return sal_True; } } - void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) + return sal_False; + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolygon, nCount); } + } - void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) + void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); - - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); } + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); - void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) + if(rPolyPolygon.count()) { - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolyPolygon); } + } - void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) + { + if(rPolyPolygon.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)"); - - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->remove(nIndex, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); } + } - void B2DPolyPolygon::clear() - { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)"); - mpPolyPolygon = &maStaticDefaultPolyPolygon; - mpPolyPolygon->incRefCount(); + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->remove(nIndex, nCount); } + } - sal_Bool B2DPolyPolygon::isClosed() const + void B2DPolyPolygon::clear() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else { - sal_Bool bRetval(sal_True); + delete mpPolyPolygon; + } - // PolyPOlygon is closed when all contained Polygons are closed or - // no Polygon exists. - for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) - { - if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed()) - { - bRetval = sal_False; - } - } + mpPolyPolygon = &maStaticDefaultPolyPolygon; + mpPolyPolygon->incRefCount(); + } - return bRetval; - } + sal_Bool B2DPolyPolygon::isClosed() const + { + sal_Bool bRetval(sal_True); - void B2DPolyPolygon::setClosed(sal_Bool bNew) + // PolyPOlygon is closed when all contained Polygons are closed or + // no Polygon exists. + for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) { - if(bNew != isClosed()) + if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed()) { - implForceUniqueCopy(); - mpPolyPolygon->setClosed(bNew); + bRetval = sal_False; } } - void B2DPolyPolygon::flip() + return bRetval; + } + + void B2DPolyPolygon::setClosed(sal_Bool bNew) + { + if(bNew != isClosed()) { implForceUniqueCopy(); - mpPolyPolygon->flip(); + mpPolyPolygon->setClosed(bNew); } + } - sal_Bool B2DPolyPolygon::hasDoublePoints() const - { - sal_Bool bRetval(sal_False); - - for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) - { - if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints()) - { - bRetval = sal_True; - } - } + void B2DPolyPolygon::flip() + { + implForceUniqueCopy(); + mpPolyPolygon->flip(); + } - return bRetval; - } + sal_Bool B2DPolyPolygon::hasDoublePoints() const + { + sal_Bool bRetval(sal_False); - void B2DPolyPolygon::removeDoublePoints() + for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) { - if(hasDoublePoints()) + if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints()) { - implForceUniqueCopy(); - mpPolyPolygon->removeDoublePoints(); + bRetval = sal_True; } } - void B2DPolyPolygon::transform(const ::basegfx::matrix::B2DHomMatrix& rMatrix) + return bRetval; + } + + void B2DPolyPolygon::removeDoublePoints() + { + if(hasDoublePoints()) { implForceUniqueCopy(); - mpPolyPolygon->transform(rMatrix); + mpPolyPolygon->removeDoublePoints(); } - } // end of namespace polygon + } + + void B2DPolyPolygon::transform(const ::basegfx::B2DHomMatrix& rMatrix) + { + implForceUniqueCopy(); + mpPolyPolygon->transform(rMatrix); + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx index a86bfce3d937..17d1c476acbf 100644 --- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx +++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygoncutter.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:12 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -88,231 +88,228 @@ namespace basegfx { - namespace polygon + B2DPolygonNode::B2DPolygonNode(const ::basegfx::B2DPoint& rPosition, B2DPolygonNode* pPrevious) + : maPosition(rPosition) { - B2DPolygonNode::B2DPolygonNode(const ::basegfx::point::B2DPoint& rPosition, B2DPolygonNode* pPrevious) - : maPosition(rPosition) - { - mpListPrevious = this; - mpListNext = this; + mpListPrevious = this; + mpListNext = this; - if(pPrevious) - { - mpNext = pPrevious->getNext(); - mpPrevious = pPrevious; - mpNext->mpPrevious = this; - mpPrevious->mpNext = this; - } - else - { - mpPrevious = mpNext = this; - } + if(pPrevious) + { + mpNext = pPrevious->getNext(); + mpPrevious = pPrevious; + mpNext->mpPrevious = this; + mpPrevious->mpNext = this; } - - B2DPolygonNode::~B2DPolygonNode() + else { - if(mpNext != this) - { - mpPrevious->mpNext = mpNext; - mpNext->mpPrevious = mpPrevious; - } + mpPrevious = mpNext = this; } + } - void B2DPolygonNode::calcMinMaxX(double& fMaxAX, double& fMinAX) const + B2DPolygonNode::~B2DPolygonNode() + { + if(mpNext != this) { - if(maPosition.getX() > mpNext->maPosition.getX()) - { - fMaxAX = maPosition.getX(); - fMinAX = mpNext->maPosition.getX(); - } - else - { - fMaxAX = mpNext->maPosition.getX(); - fMinAX = maPosition.getX(); - } + mpPrevious->mpNext = mpNext; + mpNext->mpPrevious = mpPrevious; } + } - void B2DPolygonNode::calcMinMaxY(double& fMaxAY, double& fMinAY) const + void B2DPolygonNode::calcMinMaxX(double& fMaxAX, double& fMinAX) const + { + if(maPosition.getX() > mpNext->maPosition.getX()) { - if(maPosition.getY() > mpNext->maPosition.getY()) - { - fMaxAY = maPosition.getY(); - fMinAY = mpNext->maPosition.getY(); - } - else - { - fMaxAY = mpNext->maPosition.getY(); - fMinAY = maPosition.getY(); - } + fMaxAX = maPosition.getX(); + fMinAX = mpNext->maPosition.getX(); + } + else + { + fMaxAX = mpNext->maPosition.getX(); + fMinAX = maPosition.getX(); } + } - void B2DPolygonNode::swapNextPointers(B2DPolygonNode* pCand) + void B2DPolygonNode::calcMinMaxY(double& fMaxAY, double& fMinAY) const + { + if(maPosition.getY() > mpNext->maPosition.getY()) { - B2DPolygonNode* pTemporary = mpNext; - mpNext = pCand->mpNext; - pCand->mpNext = pTemporary; - mpNext->mpPrevious = this; - pCand->mpNext->mpPrevious = pCand; + fMaxAY = maPosition.getY(); + fMinAY = mpNext->maPosition.getY(); + } + else + { + fMaxAY = mpNext->maPosition.getY(); + fMinAY = maPosition.getY(); } + } - void B2DPolygonNode::addToList(B2DPolygonNode*& rpList) + void B2DPolygonNode::swapNextPointers(B2DPolygonNode* pCand) + { + B2DPolygonNode* pTemporary = mpNext; + mpNext = pCand->mpNext; + pCand->mpNext = pTemporary; + mpNext->mpPrevious = this; + pCand->mpNext->mpPrevious = pCand; + } + + void B2DPolygonNode::addToList(B2DPolygonNode*& rpList) + { + if(rpList) { - if(rpList) - { - mpListNext = rpList->mpListNext; - rpList->mpListNext = this; - mpListPrevious = rpList; - mpListNext->mpListPrevious = this; - } - else - { - rpList = this; - } + mpListNext = rpList->mpListNext; + rpList->mpListNext = this; + mpListPrevious = rpList; + mpListNext->mpListPrevious = this; + } + else + { + rpList = this; } + } - void B2DPolygonNode::remFromList(B2DPolygonNode*& rpList) + void B2DPolygonNode::remFromList(B2DPolygonNode*& rpList) + { + if(mpListNext != this) { - if(mpListNext != this) + if(rpList == this) { - if(rpList == this) - { - rpList = mpListPrevious; - } - - mpListPrevious->mpListNext = mpListNext; - mpListNext->mpListPrevious = mpListPrevious; - mpListNext = mpListPrevious = this; + rpList = mpListPrevious; } - else + + mpListPrevious->mpListNext = mpListNext; + mpListNext->mpListPrevious = mpListPrevious; + mpListNext = mpListPrevious = this; + } + else + { + if(rpList == this) { - if(rpList == this) - { - rpList = 0L; - } + rpList = 0L; } } + } - sal_Bool B2DPolygonNode::getOrientation() const - { - const B2DPolygonNode* pOutmost = this; - const B2DPolygonNode* pCurrent = this->getNext(); + sal_Bool B2DPolygonNode::getOrientation() const + { + const B2DPolygonNode* pOutmost = this; + const B2DPolygonNode* pCurrent = this->getNext(); - while(pCurrent != this) + while(pCurrent != this) + { + if(::basegfx::fTools::more(pOutmost->getPosition().getX(), pCurrent->getPosition().getX())) { - if(::basegfx::numeric::fTools::more(pOutmost->getPosition().getX(), pCurrent->getPosition().getX())) + if(pCurrent->getPosition().getX() < pOutmost->getPosition().getX()) + { + pOutmost = pCurrent; + } + else { - if(pCurrent->getPosition().getX() < pOutmost->getPosition().getX()) + if(pCurrent->getPosition().getY() < pOutmost->getPosition().getY()) { pOutmost = pCurrent; } - else - { - if(pCurrent->getPosition().getY() < pOutmost->getPosition().getY()) - { - pOutmost = pCurrent; - } - } } - - // next node - pCurrent = pCurrent->getNext(); } - ::basegfx::vector::B2DVector aVec1(pOutmost->getPrevious()->getPosition() - pOutmost->getPosition()); - ::basegfx::vector::B2DVector aVec2(pOutmost->getNext()->getPosition() - pOutmost->getPosition()); - return sal_Bool(::basegfx::numeric::fTools::more(aVec1.getX() * aVec2.getY(), aVec1.getY() * aVec2.getX())); + // next node + pCurrent = pCurrent->getNext(); } - void B2DPolygonNode::swapOrientation() - { - B2DPolygonNode* pCurrent = this; + ::basegfx::B2DVector aVec1(pOutmost->getPrevious()->getPosition() - pOutmost->getPosition()); + ::basegfx::B2DVector aVec2(pOutmost->getNext()->getPosition() - pOutmost->getPosition()); + return sal_Bool(::basegfx::fTools::more(aVec1.getX() * aVec2.getY(), aVec1.getY() * aVec2.getX())); + } - do { - pCurrent->swapPreviousNext(); - pCurrent = pCurrent->getPrevious(); - } while(pCurrent != this); - } + void B2DPolygonNode::swapOrientation() + { + B2DPolygonNode* pCurrent = this; - ::basegfx::range::B2DRange B2DPolygonNode::getRange() const - { - ::basegfx::range::B2DRange aRetval; - const B2DPolygonNode* pCurrent = this; + do { + pCurrent->swapPreviousNext(); + pCurrent = pCurrent->getPrevious(); + } while(pCurrent != this); + } - do { - aRetval.expand(pCurrent->getPosition()); - pCurrent = pCurrent->getPrevious(); - } while(pCurrent != this); + ::basegfx::B2DRange B2DPolygonNode::getRange() const + { + ::basegfx::B2DRange aRetval; + const B2DPolygonNode* pCurrent = this; - return aRetval; - } + do { + aRetval.expand(pCurrent->getPosition()); + pCurrent = pCurrent->getPrevious(); + } while(pCurrent != this); - sal_Bool B2DPolygonNode::isInside(const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder) const + return aRetval; + } + + sal_Bool B2DPolygonNode::isInside(const ::basegfx::B2DPoint& rPoint, sal_Bool bWithBorder) const + { + sal_Bool bInside(sal_False); + const B2DPolygonNode* pCurrent = this; + + do { - sal_Bool bInside(sal_False); - const B2DPolygonNode* pCurrent = this; + if(bWithBorder && pCurrent->getPosition().equal(rPoint)) + { + return sal_True; + } + + B2DPolygonNode* pNext = pCurrent->getNext(); + const sal_Bool bCompYA(::basegfx::fTools::more(pCurrent->getPosition().getY(), rPoint.getY())); + const sal_Bool bCompYB(::basegfx::fTools::more(pNext->getPosition().getY(), rPoint.getY())); - do + if(bCompYA != bCompYB) { - if(bWithBorder && pCurrent->getPosition().equal(rPoint)) + const sal_Bool bCompXA(::basegfx::fTools::more(pCurrent->getPosition().getX(), rPoint.getX())); + const sal_Bool bCompXB(::basegfx::fTools::more(pNext->getPosition().getX(), rPoint.getX())); + + if(bCompXA == bCompXB) { - return sal_True; + if(bCompXA) + { + bInside = !bInside; + } } - - B2DPolygonNode* pNext = pCurrent->getNext(); - const sal_Bool bCompYA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getY(), rPoint.getY())); - const sal_Bool bCompYB(::basegfx::numeric::fTools::more(pNext->getPosition().getY(), rPoint.getY())); - - if(bCompYA != bCompYB) + else { - const sal_Bool bCompXA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getX(), rPoint.getX())); - const sal_Bool bCompXB(::basegfx::numeric::fTools::more(pNext->getPosition().getX(), rPoint.getX())); + double fCmp = + pNext->getPosition().getX() - (pNext->getPosition().getY() - rPoint.getY()) * + (pCurrent->getPosition().getX() - pNext->getPosition().getX()) / + (pCurrent->getPosition().getY() - pNext->getPosition().getY()); - if(bCompXA == bCompXB) + if(bWithBorder && ::basegfx::fTools::more(fCmp, rPoint.getX())) { - if(bCompXA) - { - bInside = !bInside; - } + bInside = !bInside; } - else + else if(::basegfx::fTools::moreOrEqual(fCmp, rPoint.getX())) { - double fCmp = - pNext->getPosition().getX() - (pNext->getPosition().getY() - rPoint.getY()) * - (pCurrent->getPosition().getX() - pNext->getPosition().getX()) / - (pCurrent->getPosition().getY() - pNext->getPosition().getY()); - - if(bWithBorder && ::basegfx::numeric::fTools::more(fCmp, rPoint.getX())) - { - bInside = !bInside; - } - else if(::basegfx::numeric::fTools::moreOrEqual(fCmp, rPoint.getX())) - { - bInside = !bInside; - } + bInside = !bInside; } } + } - // next edge - pCurrent = pNext; + // next edge + pCurrent = pNext; - } while(pCurrent != this); + } while(pCurrent != this); - return bInside; - } + return bInside; + } - sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder) const - { - B2DPolygonNode* pTest = pPoly; - sal_Bool bAllAInside(sal_True); + sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder) const + { + B2DPolygonNode* pTest = pPoly; + sal_Bool bAllAInside(sal_True); - do { - bAllAInside = isInside(pTest->getPosition(), bWithBorder); - pTest = pTest->getNext(); - } while(bAllAInside && pTest != pPoly); + do { + bAllAInside = isInside(pTest->getPosition(), bWithBorder); + pTest = pTest->getNext(); + } while(bAllAInside && pTest != pPoly); - return bAllAInside; - } - } // end of namespace polygon + return bAllAInside; + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -320,26 +317,23 @@ namespace basegfx namespace basegfx { - namespace polygon + void B2DSimpleCut::solve() { - void B2DSimpleCut::solve() - { - mpLeft->swapNextPointers(mpRight); + mpLeft->swapNextPointers(mpRight); - if(mbCorrectOrientation) + if(mbCorrectOrientation) + { + if(mpLeft->getOrientation() != mbOrientation) { - if(mpLeft->getOrientation() != mbOrientation) - { - mpLeft->swapOrientation(); - } + mpLeft->swapOrientation(); + } - if(mpRight->getOrientation() != mbOrientation) - { - mpRight->swapOrientation(); - } + if(mpRight->getOrientation() != mbOrientation) + { + mpRight->swapOrientation(); } } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -347,27 +341,24 @@ namespace basegfx namespace basegfx { - namespace polygon + void B2DClipExtraPolygonInfo::init(B2DPolygonNode* pNew) { - void B2DClipExtraPolygonInfo::init(B2DPolygonNode* pNew) + maRange = pNew->getRange(); + mbOrientation = pNew->getOrientation(); + mnDepth = (mbOrientation) ? 0L : -1L; + } + + void B2DClipExtraPolygonInfo::changeDepth(sal_Bool bOrientation) + { + if(bOrientation) { - maRange = pNew->getRange(); - mbOrientation = pNew->getOrientation(); - mnDepth = (mbOrientation) ? 0L : -1L; + mnDepth++; } - - void B2DClipExtraPolygonInfo::changeDepth(sal_Bool bOrientation) + else { - if(bOrientation) - { - mnDepth++; - } - else - { - mnDepth--; - } + mnDepth--; } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// @@ -375,772 +366,769 @@ namespace basegfx namespace basegfx { - namespace polygon + B2DPolyPolygonCutter::~B2DPolyPolygonCutter() { - B2DPolyPolygonCutter::~B2DPolyPolygonCutter() + for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) { - for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) - { - delete maPolygonList[a]; - } - - maPolygonList.clear(); + delete maPolygonList[a]; } - void B2DPolyPolygonCutter::removeIncludedPolygons(sal_Bool bUseOr) + maPolygonList.clear(); + } + + void B2DPolyPolygonCutter::removeIncludedPolygons(sal_Bool bUseOr) + { + const sal_uInt32 aCount(maPolygonList.size()); + B2DClipExtraPolygonInfo* pInfos = new B2DClipExtraPolygonInfo[aCount]; + sal_uInt32 a, b; + + // fill infos + for(a = 0L; a < aCount; a++) { - const sal_uInt32 aCount(maPolygonList.size()); - B2DClipExtraPolygonInfo* pInfos = new B2DClipExtraPolygonInfo[aCount]; - sal_uInt32 a, b; + pInfos[a].init(maPolygonList[a]); + } - // fill infos - for(a = 0L; a < aCount; a++) - { - pInfos[a].init(maPolygonList[a]); - } + // get all includes + for(a = 0L; a < aCount; a++) + { + B2DClipExtraPolygonInfo& rInfoA = pInfos[a]; - // get all includes - for(a = 0L; a < aCount; a++) + for(b = 0L; b < aCount; b++) { - B2DClipExtraPolygonInfo& rInfoA = pInfos[a]; + B2DClipExtraPolygonInfo& rInfoB = pInfos[b]; - for(b = 0L; b < aCount; b++) + if(a != b && doRangesInclude(rInfoA.getRange(), rInfoB.getRange())) { - B2DClipExtraPolygonInfo& rInfoB = pInfos[b]; - - if(a != b && doRangesInclude(rInfoA.getRange(), rInfoB.getRange())) + // volume B in A, test pA, pB for inclusion, with border + if(maPolygonList[a]->isPolygonInside(maPolygonList[b], sal_True)) { - // volume B in A, test pA, pB for inclusion, with border - if(maPolygonList[a]->isPolygonInside(maPolygonList[b], sal_True)) - { - // pB is inside pA - rInfoB.changeDepth(rInfoA.getOrientation()); - } + // pB is inside pA + rInfoB.changeDepth(rInfoA.getOrientation()); } } } + } - // delete removable - for(a = 0L, b = 0L; a < aCount; a++) - { - B2DClipExtraPolygonInfo& rInfo = pInfos[a]; + // delete removable + for(a = 0L, b = 0L; a < aCount; a++) + { + B2DClipExtraPolygonInfo& rInfo = pInfos[a]; - if((bUseOr && rInfo.getDepth() != 0L) || (!bUseOr && rInfo.getDepth() < 1L)) - { - B2DPolygonNodeVector::iterator aPosition(maPolygonList.begin() + b); - B2DPolygonNode* pCandidate = *aPosition; - maPolygonList.erase(aPosition); - deletePolygon(pCandidate); - } - else - { - b++; - } + if((bUseOr && rInfo.getDepth() != 0L) || (!bUseOr && rInfo.getDepth() < 1L)) + { + B2DPolygonNodeVector::iterator aPosition(maPolygonList.begin() + b); + B2DPolygonNode* pCandidate = *aPosition; + maPolygonList.erase(aPosition); + deletePolygon(pCandidate); + } + else + { + b++; } - - // delete infos - delete[] pInfos; } - void B2DPolyPolygonCutter::solveAllCuts(B2DSimpleCutVector& rCuts) - { - B2DPolygonNode* pNewList = 0L; - - // add all nodes of polys to list - polysToList(pNewList); + // delete infos + delete[] pInfos; + } - // solve cuts - B2DSimpleCutVector::iterator aCandidate(rCuts.begin()); + void B2DPolyPolygonCutter::solveAllCuts(B2DSimpleCutVector& rCuts) + { + B2DPolygonNode* pNewList = 0L; - for(; aCandidate < rCuts.end(); aCandidate++) - { - B2DSimpleCut* pCut = *aCandidate; - pCut->solve(); - delete pCut; - } + // add all nodes of polys to list + polysToList(pNewList); - rCuts.clear(); + // solve cuts + B2DSimpleCutVector::iterator aCandidate(rCuts.begin()); - // extract polys - listToPolys(pNewList); + for(; aCandidate < rCuts.end(); aCandidate++) + { + B2DSimpleCut* pCut = *aCandidate; + pCut->solve(); + delete pCut; } - void B2DPolyPolygonCutter::polysToList(B2DPolygonNode*& rpList) - { - B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); + rCuts.clear(); - for(; aCandidate != maPolygonList.end(); aCandidate++) - { - addAllNodes(*aCandidate, rpList); - } + // extract polys + listToPolys(pNewList); + } - maPolygonList.clear(); - } + void B2DPolyPolygonCutter::polysToList(B2DPolygonNode*& rpList) + { + B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); - void B2DPolyPolygonCutter::listToPolys(B2DPolygonNode*& rpList) + for(; aCandidate != maPolygonList.end(); aCandidate++) { - while(rpList) - { - // get one - B2DPolygonNode* pNew = extractNextPolygon(rpList); - - if(pNew) - { - maPolygonList.push_back(pNew); - } - } + addAllNodes(*aCandidate, rpList); } - B2DPolygonNode* B2DPolyPolygonCutter::createNewPolygon(const B2DPolygon& rPolygon) + maPolygonList.clear(); + } + + void B2DPolyPolygonCutter::listToPolys(B2DPolygonNode*& rpList) + { + while(rpList) { - B2DPolygonNode* pRetval = NULL; + // get one + B2DPolygonNode* pNew = extractNextPolygon(rpList); - for(sal_uInt32 a(0L); a < rPolygon.count(); a++) + if(pNew) { - ::basegfx::point::B2DPoint aPoint(rPolygon.getB2DPoint(a)); - pRetval = new B2DPolygonNode(aPoint, pRetval); + maPolygonList.push_back(pNew); } - - return pRetval; } + } + + B2DPolygonNode* B2DPolyPolygonCutter::createNewPolygon(const B2DPolygon& rPolygon) + { + B2DPolygonNode* pRetval = NULL; - void B2DPolyPolygonCutter::deletePolygon(B2DPolygonNode* pCand) + for(sal_uInt32 a(0L); a < rPolygon.count(); a++) { - B2DPolygonNode* pPoly = pCand; + ::basegfx::B2DPoint aPoint(rPolygon.getB2DPoint(a)); + pRetval = new B2DPolygonNode(aPoint, pRetval); + } - while(pPoly) - { - B2DPolygonNode* pNext = pPoly->getNext(); + return pRetval; + } - if(pNext == pPoly) - { - pNext = 0L; - } + void B2DPolyPolygonCutter::deletePolygon(B2DPolygonNode* pCand) + { + B2DPolygonNode* pPoly = pCand; + + while(pPoly) + { + B2DPolygonNode* pNext = pPoly->getNext(); - delete pPoly; - pPoly = pNext; + if(pNext == pPoly) + { + pNext = 0L; } + + delete pPoly; + pPoly = pNext; } + } - void B2DPolyPolygonCutter::addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList) - { - B2DPolygonNode* pAct = pPolygon; + void B2DPolyPolygonCutter::addAllNodes(B2DPolygonNode* pPolygon, B2DPolygonNode*& rpList) + { + B2DPolygonNode* pAct = pPolygon; - do { - pAct->addToList(rpList); - pAct = pAct->getNext(); - } while(pAct != pPolygon); - } + do { + pAct->addToList(rpList); + pAct = pAct->getNext(); + } while(pAct != pPolygon); + } - void B2DPolyPolygonCutter::addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation) + void B2DPolyPolygonCutter::addPolyPolygon(const B2DPolyPolygon& rPolyPolygon, sal_Bool bForceOrientation) + { + for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++) { - for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++) - { - B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a); - aCandidate.removeDoublePoints(); + B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a); + aCandidate.removeDoublePoints(); - if(!aCandidate.isClosed() || aCandidate.count() < 3) - { - maNotClosedPolygons.append(aCandidate); - } - else + if(!aCandidate.isClosed() || aCandidate.count() < 3) + { + maNotClosedPolygons.append(aCandidate); + } + else + { + if(bForceOrientation) { - if(bForceOrientation) - { - ::basegfx::vector::B2DVectorOrientation aOrientation = - ::basegfx::polygon::tools::getOrientation(aCandidate); + ::basegfx::B2DVectorOrientation aOrientation = + ::basegfx::tools::getOrientation(aCandidate); - if(::basegfx::vector::ORIENTATION_POSITIVE != aOrientation) - { - aCandidate.flip(); - } + if(::basegfx::ORIENTATION_POSITIVE != aOrientation) + { + aCandidate.flip(); } - - B2DPolygonNode* pNew = createNewPolygon(aCandidate); - maPolygonList.push_back(pNew); } + + B2DPolygonNode* pNew = createNewPolygon(aCandidate); + maPolygonList.push_back(pNew); } } + } + + void B2DPolyPolygonCutter::getPolyPolygon(B2DPolyPolygon& rPolyPolygon) + { + B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); - void B2DPolyPolygonCutter::getPolyPolygon(B2DPolyPolygon& rPolyPolygon) + for(; aCandidate < maPolygonList.end(); aCandidate++) { - B2DPolygonNodeVector::iterator aCandidate(maPolygonList.begin()); + B2DPolygonNode* pCand = *aCandidate; + B2DPolygonNode* pAct = pCand; + sal_uInt32 nCount(0L); + + do { + nCount++; + pAct = pAct->getNext(); + } while(pAct != pCand); - for(; aCandidate < maPolygonList.end(); aCandidate++) + if(nCount > 2L) { - B2DPolygonNode* pCand = *aCandidate; - B2DPolygonNode* pAct = pCand; - sal_uInt32 nCount(0L); + B2DPolygon aNewPolygon; do { - nCount++; + aNewPolygon.append(pAct->getPosition()); pAct = pAct->getNext(); } while(pAct != pCand); - if(nCount > 2L) - { - B2DPolygon aNewPolygon; + aNewPolygon.setClosed(sal_True); + rPolyPolygon.append(aNewPolygon); + } - do { - aNewPolygon.append(pAct->getPosition()); - pAct = pAct->getNext(); - } while(pAct != pCand); + deletePolygon(pCand); + } - aNewPolygon.setClosed(sal_True); - rPolyPolygon.append(aNewPolygon); - } + maPolygonList.clear(); - deletePolygon(pCand); - } + while(maNotClosedPolygons.count()) + { + rPolyPolygon.append(maNotClosedPolygons.getB2DPolygon(0L)); + maNotClosedPolygons.remove(0L); + } + } - maPolygonList.clear(); + B2DSimpleCut* B2DPolyPolygonCutter::getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB) + { + for(sal_uInt32 a(0L); a < rTmpCuts.size(); a++) + { + B2DSimpleCut* pCand = rTmpCuts[a]; - while(maNotClosedPolygons.count()) + if(pCand->isSameCut(pA, pB)) { - rPolyPolygon.append(maNotClosedPolygons.getB2DPolygon(0L)); - maNotClosedPolygons.remove(0L); + return pCand; } } - B2DSimpleCut* B2DPolyPolygonCutter::getExistingCut(B2DSimpleCutVector& rTmpCuts, B2DPolygonNode* pA, B2DPolygonNode* pB) - { - for(sal_uInt32 a(0L); a < rTmpCuts.size(); a++) - { - B2DSimpleCut* pCand = rTmpCuts[a]; + return 0L; + } - if(pCand->isSameCut(pA, pB)) - { - return pCand; - } - } + B2DPolygonNode* B2DPolyPolygonCutter::extractNextPolygon(B2DPolygonNode*& rpList) + { + B2DPolygonNode* pStart = rpList; + + // remove all nodes of this poly from list + B2DPolygonNode* pAct = pStart; + sal_uInt32 nNumNodes(0L); + + do { + pAct->remFromList(rpList); + pAct = pAct->getNext(); + nNumNodes++; + } while(pAct != pStart); + if(nNumNodes < 3L) + { + deletePolygon(pStart); return 0L; } - - B2DPolygonNode* B2DPolyPolygonCutter::extractNextPolygon(B2DPolygonNode*& rpList) + else { - B2DPolygonNode* pStart = rpList; - - // remove all nodes of this poly from list - B2DPolygonNode* pAct = pStart; - sal_uInt32 nNumNodes(0L); - - do { - pAct->remFromList(rpList); - pAct = pAct->getNext(); - nNumNodes++; - } while(pAct != pStart); - - if(nNumNodes < 3L) - { - deletePolygon(pStart); - return 0L; - } - else - { - return pStart; - } + return pStart; } + } - void B2DPolyPolygonCutter::removeSelfIntersections() + void B2DPolyPolygonCutter::removeSelfIntersections() + { + B2DSimpleCutVector aCuts; + B2DSimpleCutVector aNewCuts; + B2DPolygonNode* pCand; + B2DPolygonNode* pA; + B2DPolygonNode* pB; + double fMaxAX, fMinAX, fMaxAY, fMinAY; + double fMaxBX, fMinBX, fMaxBY, fMinBY; + double fCut; + + // first job: Find all cuts and add points there + for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) { - B2DSimpleCutVector aCuts; - B2DSimpleCutVector aNewCuts; - B2DPolygonNode* pCand; - B2DPolygonNode* pA; - B2DPolygonNode* pB; - double fMaxAX, fMinAX, fMaxAY, fMinAY; - double fMaxBX, fMinBX, fMaxBY, fMinBY; - double fCut; - - // first job: Find all cuts and add points there - for(sal_uInt32 a(0L); a < maPolygonList.size(); a++) - { - pCand = maPolygonList[a]; - pA = pCand; + pCand = maPolygonList[a]; + pA = pCand; + + // one run to find same start positions (so there is no need to + // search for existing cuts in main loop) + do { + pB = pA->getNext(); - // one run to find same start positions (so there is no need to - // search for existing cuts in main loop) do { - pB = pA->getNext(); + if(isSamePos(pA->getPosition(), pB->getPosition())) + { + aNewCuts.push_back(new B2DSimpleCut(pA, pB, sal_True, pCand->getOrientation())); + } - do { - if(isSamePos(pA->getPosition(), pB->getPosition())) - { - aNewCuts.push_back(new B2DSimpleCut(pA, pB, sal_True, pCand->getOrientation())); - } + // next B + pB = pB->getNext(); + } while(pB != pCand); - // next B - pB = pB->getNext(); - } while(pB != pCand); + // next A + pA = pA->getNext(); + } while(pA->getNext() != pCand); - // next A - pA = pA->getNext(); - } while(pA->getNext() != pCand); + // second run to find real cuts + pA = pCand; - // second run to find real cuts - pA = pCand; + do { + // get bounds for this edge in poly + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + pB = pA->getNext(); do { - // get bounds for this edge in poly - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - pB = pA->getNext(); + pB->calcMinMaxX(fMaxBX, fMinBX); - do { - pB->calcMinMaxX(fMaxBX, fMinBX); + if(::basegfx::fTools::more(fMaxBX, fMinAX) + && ::basegfx::fTools::more(fMaxAX, fMinBX)) + { + pB->calcMinMaxY(fMaxBY, fMinBY); - if(::basegfx::numeric::fTools::more(fMaxBX, fMinAX) - && ::basegfx::numeric::fTools::more(fMaxAX, fMinBX)) + if(::basegfx::fTools::more(fMaxBY, fMinAY) + && ::basegfx::fTools::more(fMaxAY, fMinBY)) { - pB->calcMinMaxY(fMaxBY, fMinBY); - - if(::basegfx::numeric::fTools::more(fMaxBY, fMinAY) - && ::basegfx::numeric::fTools::more(fMaxAY, fMinBY)) + if(!isSamePos(pA->getPosition(), pB->getPosition())) { - if(!isSamePos(pA->getPosition(), pB->getPosition())) - { - const ::basegfx::vector::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); - const ::basegfx::vector::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); + const ::basegfx::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); + const ::basegfx::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); - if(::basegfx::polygon::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + if(::basegfx::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + { + // crossover, two new points + ::basegfx::B2DPoint aNewPos(::basegfx::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); + B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); + B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi, sal_True, pCand->getOrientation())); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + } + else + { + if(::basegfx::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) { - // crossover, two new points - ::basegfx::point::B2DPoint aNewPos(::basegfx::tuple::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); - B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); - B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi, sal_True, pCand->getOrientation())); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); + // startpoint A at edge B, one new point + B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); + aNewCuts.push_back(new B2DSimpleCut(pA, pCutHi, sal_True, pCand->getOrientation())); } - else + else if(::basegfx::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) { - if(::basegfx::polygon::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) - { - // startpoint A at edge B, one new point - B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); - aNewCuts.push_back(new B2DSimpleCut(pA, pCutHi, sal_True, pCand->getOrientation())); - } - else if(::basegfx::polygon::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) - { - // startpoint B at edge A, one new point - B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pB, sal_True, pCand->getOrientation())); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - } + // startpoint B at edge A, one new point + B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pB, sal_True, pCand->getOrientation())); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); } } } } + } - // next B - pB = pB->getNext(); - } while(pB != pCand); + // next B + pB = pB->getNext(); + } while(pB != pCand); - // next A - pA = pA->getNext(); - } while(pA->getNext() != pCand); + // next A + pA = pA->getNext(); + } while(pA->getNext() != pCand); - // copy new cuts to cuts - aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); - aNewCuts.clear(); - } + // copy new cuts to cuts + aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); + aNewCuts.clear(); + } - // second job: if there were cuts, split polys - if(aCuts.size()) - { - solveAllCuts(aCuts); - } + // second job: if there were cuts, split polys + if(aCuts.size()) + { + solveAllCuts(aCuts); } + } - sal_Bool B2DPolyPolygonCutter::isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB) + sal_Bool B2DPolyPolygonCutter::isCrossover(B2DPolygonNode* pA, B2DPolygonNode* pB) + { + // build entering vectors + ::basegfx::B2DVector aVecA(pA->getPrevious()->getPosition() - pA->getPosition()); + ::basegfx::B2DVector aVecB(pB->getPrevious()->getPosition() - pA->getPosition()); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()); + double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()); + + // build leaving vectors + aVecA = pA->getNext()->getPosition() - pA->getPosition(); + aVecB = pB->getNext()->getPosition() - pA->getPosition(); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()); + double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()); + + // compare + if(fDegreeA1 > fDegreeA2) { - // build entering vectors - ::basegfx::vector::B2DVector aVecA(pA->getPrevious()->getPosition() - pA->getPosition()); - ::basegfx::vector::B2DVector aVecB(pB->getPrevious()->getPosition() - pA->getPosition()); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()); - double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()); - - // build leaving vectors - aVecA = pA->getNext()->getPosition() - pA->getPosition(); - aVecB = pB->getNext()->getPosition() - pA->getPosition(); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()); - double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()); - - // compare - if(fDegreeA1 > fDegreeA2) - { - double fTemp = fDegreeA2; - fDegreeA2 = fDegreeA1; - fDegreeA1 = fTemp; - } + double fTemp = fDegreeA2; + fDegreeA2 = fDegreeA1; + fDegreeA1 = fTemp; + } - sal_Bool bB1Inside(::basegfx::numeric::fTools::more(fDegreeB1, fDegreeA1) - && ::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB1)); - sal_Bool bB2Inside(::basegfx::numeric::fTools::more(fDegreeB2, fDegreeA1) - && ::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB2)); + sal_Bool bB1Inside(::basegfx::fTools::more(fDegreeB1, fDegreeA1) + && ::basegfx::fTools::more(fDegreeA2, fDegreeB1)); + sal_Bool bB2Inside(::basegfx::fTools::more(fDegreeB2, fDegreeA1) + && ::basegfx::fTools::more(fDegreeA2, fDegreeB2)); - if(bB1Inside && bB2Inside) - { - return sal_False; - } + if(bB1Inside && bB2Inside) + { + return sal_False; + } + + sal_Bool bB1Outside(::basegfx::fTools::more(fDegreeA1, fDegreeB1) + || ::basegfx::fTools::more(fDegreeB1, fDegreeA2)); + sal_Bool bB2Outside(::basegfx::fTools::more(fDegreeA1, fDegreeB2) + || ::basegfx::fTools::more(fDegreeB2, fDegreeA2)); - sal_Bool bB1Outside(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB1) - || ::basegfx::numeric::fTools::more(fDegreeB1, fDegreeA2)); - sal_Bool bB2Outside(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB2) - || ::basegfx::numeric::fTools::more(fDegreeB2, fDegreeA2)); + return !(bB1Outside && bB2Outside); + } - return !(bB1Outside && bB2Outside); + sal_Bool B2DPolyPolygonCutter::isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave) + { + // build entering vectors + ::basegfx::B2DVector aVecJ(pEnter->getLeft()->getNext()->getPosition() - pEnter->getLeft()->getPosition()); + ::basegfx::B2DVector aVecA(pEnter->getLeft()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); + ::basegfx::B2DVector aVecB(pEnter->getRight()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); + aVecJ.normalize(); + aVecA.normalize(); + aVecB.normalize(); + double fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); + double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; + double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; + + // move to range [0..2PI[ + while(fDegreeA2 < 0.0) + { + fDegreeA2 += (2.0 * F_PI); } - sal_Bool B2DPolyPolygonCutter::isCrossover(B2DSimpleCut* pEnter, B2DSimpleCut* pLeave) + while(fDegreeA2 >= (2.0 * F_PI)) { - // build entering vectors - ::basegfx::vector::B2DVector aVecJ(pEnter->getLeft()->getNext()->getPosition() - pEnter->getLeft()->getPosition()); - ::basegfx::vector::B2DVector aVecA(pEnter->getLeft()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); - ::basegfx::vector::B2DVector aVecB(pEnter->getRight()->getPrevious()->getPosition() - pEnter->getLeft()->getPosition()); - aVecJ.normalize(); - aVecA.normalize(); - aVecB.normalize(); - double fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); - double fDegreeA2 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; - double fDegreeB2 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; - - // move to range [0..2PI[ - while(fDegreeA2 < 0.0) - { - fDegreeA2 += (2.0 * F_PI); - } + fDegreeA2 -= (2.0 * F_PI); + } - while(fDegreeA2 >= (2.0 * F_PI)) - { - fDegreeA2 -= (2.0 * F_PI); - } + // move to range [0..2PI[ + while(fDegreeB2 < 0.0) + { + fDegreeB2 += (2.0 * F_PI); + } - // move to range [0..2PI[ - while(fDegreeB2 < 0.0) - { - fDegreeB2 += (2.0 * F_PI); - } + while(fDegreeB2 >= (2.0 * F_PI)) + { + fDegreeB2 -= (2.0 * F_PI); + } - while(fDegreeB2 >= (2.0 * F_PI)) - { - fDegreeB2 -= (2.0 * F_PI); - } + sal_Bool bA2BiggerB2(::basegfx::fTools::more(fDegreeA2, fDegreeB2)); + + // build leaving vectors + aVecJ = pLeave->getLeft()->getPrevious()->getPosition() - pLeave->getLeft()->getPosition(); + aVecA = pLeave->getLeft()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); + aVecB = pLeave->getRight()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); + aVecJ.normalize(); + aVecA.normalize(); + aVecB.normalize(); + fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); + double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; + double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; + + // move to range [0..2PI[ + while(fDegreeA1 < 0.0) + { + fDegreeA1 += (2.0 * F_PI); + } - sal_Bool bA2BiggerB2(::basegfx::numeric::fTools::more(fDegreeA2, fDegreeB2)); - - // build leaving vectors - aVecJ = pLeave->getLeft()->getPrevious()->getPosition() - pLeave->getLeft()->getPosition(); - aVecA = pLeave->getLeft()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); - aVecB = pLeave->getRight()->getNext()->getPosition() - pLeave->getLeft()->getPosition(); - aVecJ.normalize(); - aVecA.normalize(); - aVecB.normalize(); - fDegreeJo = atan2(aVecJ.getY(), aVecJ.getX()); - double fDegreeA1 = atan2(aVecA.getY(), aVecA.getX()) - fDegreeJo; - double fDegreeB1 = atan2(aVecB.getY(), aVecB.getX()) - fDegreeJo; - - // move to range [0..2PI[ - while(fDegreeA1 < 0.0) - { - fDegreeA1 += (2.0 * F_PI); - } + while(fDegreeA1 >= (2.0 * F_PI)) + { + fDegreeA1 -= (2.0 * F_PI); + } - while(fDegreeA1 >= (2.0 * F_PI)) - { - fDegreeA1 -= (2.0 * F_PI); - } + // move to range [0..2PI[ + while(fDegreeB1 < 0) + { + fDegreeB1 += (2.0 * F_PI); + } - // move to range [0..2PI[ - while(fDegreeB1 < 0) - { - fDegreeB1 += (2.0 * F_PI); - } + while(fDegreeB1 >= (2.0 * F_PI)) + { + fDegreeB1 -= (2.0 * F_PI); + } - while(fDegreeB1 >= (2.0 * F_PI)) - { - fDegreeB1 -= (2.0 * F_PI); - } + sal_Bool bA1BiggerB1(::basegfx::fTools::more(fDegreeA1, fDegreeB1)); - sal_Bool bA1BiggerB1(::basegfx::numeric::fTools::more(fDegreeA1, fDegreeB1)); + // compare + return (bA1BiggerB1 == bA2BiggerB2); + } - // compare - return (bA1BiggerB1 == bA2BiggerB2); + void B2DPolyPolygonCutter::removeDoubleIntersections() + { + double fMaxAX, fMinAX, fMaxAY, fMinAY; + double fMaxBX, fMinBX, fMaxBY, fMinBY; + double fCut; + B2DSimpleCutVector aCuts; + B2DSimpleCutVector aTmpCuts; + B2DSimpleCutVector aNewCuts; + B2DPolygonNode* pCandA; + B2DPolygonNode* pCandB; + B2DPolygonNode* pA; + B2DPolygonNode* pB; + sal_uInt32 a; + + // create volume list for all polys for faster compares + ::basegfx::B2DRange* pVolumes = new ::basegfx::B2DRange[maPolygonList.size()]; + + for(a = 0L; a < maPolygonList.size(); a++) + { + pVolumes[a] = maPolygonList[a]->getRange(); } - void B2DPolyPolygonCutter::removeDoubleIntersections() + // register cuts (and add points for them) between pCandA and pCandB + for(a = 0L; a + 1L < maPolygonList.size(); a++) { - double fMaxAX, fMinAX, fMaxAY, fMinAY; - double fMaxBX, fMinBX, fMaxBY, fMinBY; - double fCut; - B2DSimpleCutVector aCuts; - B2DSimpleCutVector aTmpCuts; - B2DSimpleCutVector aNewCuts; - B2DPolygonNode* pCandA; - B2DPolygonNode* pCandB; - B2DPolygonNode* pA; - B2DPolygonNode* pB; - sal_uInt32 a; - - // create volume list for all polys for faster compares - ::basegfx::range::B2DRange* pVolumes = new ::basegfx::range::B2DRange[maPolygonList.size()]; - - for(a = 0L; a < maPolygonList.size(); a++) - { - pVolumes[a] = maPolygonList[a]->getRange(); - } + pCandA = maPolygonList[a]; - // register cuts (and add points for them) between pCandA and pCandB - for(a = 0L; a + 1L < maPolygonList.size(); a++) + for(sal_uInt32 b = a + 1L; b < maPolygonList.size(); b++) { - pCandA = maPolygonList[a]; - - for(sal_uInt32 b = a + 1L; b < maPolygonList.size(); b++) + if(doRangesIntersect(pVolumes[a], pVolumes[b])) { - if(doRangesIntersect(pVolumes[a], pVolumes[b])) - { - pCandB = maPolygonList[b]; - pA = pCandA; + pCandB = maPolygonList[b]; + pA = pCandA; + + // one run to find same start positions (so there is no need to + // search for existing cuts in main loop) + do { + pB = pCandB; - // one run to find same start positions (so there is no need to - // search for existing cuts in main loop) do { - pB = pCandB; + if(isSamePos(pA->getPosition(), pB->getPosition())) + { + aTmpCuts.push_back(new B2DSimpleCut(pA, pB)); + } - do { - if(isSamePos(pA->getPosition(), pB->getPosition())) - { - aTmpCuts.push_back(new B2DSimpleCut(pA, pB)); - } + // next B + pB = pB->getNext(); + } while(pB != pCandB); - // next B - pB = pB->getNext(); - } while(pB != pCandB); + // next A + pA = pA->getNext(); + } while(pA != pCandA); - // next A - pA = pA->getNext(); - } while(pA != pCandA); + // second run to find real cuts + pA = pCandA; - // second run to find real cuts - pA = pCandA; + do { + // get bounds for this edge in poly + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + pB = pCandB; do { - // get bounds for this edge in poly - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - pB = pCandB; + pB->calcMinMaxX(fMaxBX, fMinBX); - do { - pB->calcMinMaxX(fMaxBX, fMinBX); + if(::basegfx::fTools::more(fMaxBX, fMinAX) + && ::basegfx::fTools::more(fMaxAX, fMinBX)) + { + pB->calcMinMaxY(fMaxBY, fMinBY); - if(::basegfx::numeric::fTools::more(fMaxBX, fMinAX) - && ::basegfx::numeric::fTools::more(fMaxAX, fMinBX)) + if(::basegfx::fTools::more(fMaxBY, fMinAY) + && ::basegfx::fTools::more(fMaxAY, fMinBY)) { - pB->calcMinMaxY(fMaxBY, fMinBY); - - if(::basegfx::numeric::fTools::more(fMaxBY, fMinAY) - && ::basegfx::numeric::fTools::more(fMaxAY, fMinBY)) + if(!isSamePos(pA->getPosition(), pB->getPosition())) { - if(!isSamePos(pA->getPosition(), pB->getPosition())) - { - const ::basegfx::vector::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); - const ::basegfx::vector::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); + const ::basegfx::B2DVector aVectorA(pA->getNext()->getPosition() - pA->getPosition()); + const ::basegfx::B2DVector aVectorB(pB->getNext()->getPosition() - pB->getPosition()); - if(::basegfx::polygon::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + if(::basegfx::tools::findCut(pA->getPosition(), aVectorA, pB->getPosition(), aVectorB, CUTFLAG_LINE, &fCut)) + { + // crossover, two new points, use as cutpoint + ::basegfx::B2DPoint aNewPos(::basegfx::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); + B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); + B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); + aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi)); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); + } + else + { + if(::basegfx::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) { - // crossover, two new points, use as cutpoint - ::basegfx::point::B2DPoint aNewPos(::basegfx::tuple::interpolate(pA->getPosition(), pA->getNext()->getPosition(), fCut)); - B2DPolygonNode* pCutLo = new B2DPolygonNode(aNewPos, pA); - B2DPolygonNode* pCutHi = new B2DPolygonNode(aNewPos, pB); - aNewCuts.push_back(new B2DSimpleCut(pCutLo, pCutHi)); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); + // startpoint A at edge B, one new point + // leaves or enters common section + B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); + aTmpCuts.push_back(new B2DSimpleCut(pA, pCutHi)); } - else + else if(::basegfx::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) { - if(::basegfx::polygon::tools::isPointOnEdge(pA->getPosition(), pB->getPosition(), aVectorB, &fCut)) - { - // startpoint A at edge B, one new point - // leaves or enters common section - B2DPolygonNode* pCutHi = new B2DPolygonNode(pA->getPosition(), pB); - aTmpCuts.push_back(new B2DSimpleCut(pA, pCutHi)); - } - else if(::basegfx::polygon::tools::isPointOnEdge(pB->getPosition(), pA->getPosition(), aVectorA, &fCut)) - { - // startpoint B at edge A, one new point - // leaves or enters common section - B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); - aTmpCuts.push_back(new B2DSimpleCut(pCutLo, pB)); - pA->calcMinMaxX(fMaxAX, fMinAX); - pA->calcMinMaxY(fMaxAY, fMinAY); - } + // startpoint B at edge A, one new point + // leaves or enters common section + B2DPolygonNode* pCutLo = new B2DPolygonNode(pB->getPosition(), pA); + aTmpCuts.push_back(new B2DSimpleCut(pCutLo, pB)); + pA->calcMinMaxX(fMaxAX, fMinAX); + pA->calcMinMaxY(fMaxAY, fMinAY); } } } } + } - // next B - pB = pB->getNext(); - } while(pB != pCandB); - - // next A - pA = pA->getNext(); - } while(pA != pCandA); + // next B + pB = pB->getNext(); + } while(pB != pCandB); - // test all temporary cuts for simple criteria - for(sal_uInt32 c(0L); c < aTmpCuts.size();) - { - B2DSimpleCut* pCand = aTmpCuts[c]; - sal_Bool bPrevSamePos(isPrevSamePos(pCand->getLeft(), pCand->getRight())); - sal_Bool bNextSamePos(isNextSamePos(pCand->getLeft(), pCand->getRight())); - sal_Bool bDelete(sal_False); - sal_Bool bIncC(sal_True); + // next A + pA = pA->getNext(); + } while(pA != pCandA); - if(bPrevSamePos && bNextSamePos) - { - // single point inside continued same direction section - bDelete = sal_True; - } - else if(!bPrevSamePos && !bNextSamePos) - { - // this is no same direction section, test for real cut - if(isCrossover(pCand->getLeft(), pCand->getRight())) - { - // real cut, move to real cutlist - aNewCuts.push_back(pCand); - aTmpCuts.erase(aTmpCuts.begin() + c); - bIncC = sal_False; - } - else - { - // no cut, just a touch in one point - bDelete = sal_True; - } - } + // test all temporary cuts for simple criteria + for(sal_uInt32 c(0L); c < aTmpCuts.size();) + { + B2DSimpleCut* pCand = aTmpCuts[c]; + sal_Bool bPrevSamePos(isPrevSamePos(pCand->getLeft(), pCand->getRight())); + sal_Bool bNextSamePos(isNextSamePos(pCand->getLeft(), pCand->getRight())); + sal_Bool bDelete(sal_False); + sal_Bool bIncC(sal_True); - // delete if wanted - if(bDelete) + if(bPrevSamePos && bNextSamePos) + { + // single point inside continued same direction section + bDelete = sal_True; + } + else if(!bPrevSamePos && !bNextSamePos) + { + // this is no same direction section, test for real cut + if(isCrossover(pCand->getLeft(), pCand->getRight())) { - delete pCand; + // real cut, move to real cutlist + aNewCuts.push_back(pCand); aTmpCuts.erase(aTmpCuts.begin() + c); bIncC = sal_False; } + else + { + // no cut, just a touch in one point + bDelete = sal_True; + } + } - // next candidate - if(bIncC) - c++; + // delete if wanted + if(bDelete) + { + delete pCand; + aTmpCuts.erase(aTmpCuts.begin() + c); + bIncC = sal_False; } - // are there entering/leaving same direction sections? - while(aTmpCuts.size()) + // next candidate + if(bIncC) + c++; + } + + // are there entering/leaving same direction sections? + while(aTmpCuts.size()) + { + // this cuts enter/leave a common same-direction section between + // polygons pCandA, pCandB. If it is a real crossover, a cutpoint + // for it is needed, else it can be ignored. + B2DSimpleCut* pCutA = aTmpCuts[0L]; + aTmpCuts.erase(aTmpCuts.begin()); + B2DPolygonNode* pActA = pCutA->getLeft(); + B2DPolygonNode* pActB = pCutA->getRight(); + sal_Bool bPrevSamePos(isPrevSamePos(pActA, pActB)); + sal_Bool bNextSamePos(isNextSamePos(pActA, pActB)); + + if(aTmpCuts.size()) { - // this cuts enter/leave a common same-direction section between - // polygons pCandA, pCandB. If it is a real crossover, a cutpoint - // for it is needed, else it can be ignored. - B2DSimpleCut* pCutA = aTmpCuts[0L]; - aTmpCuts.erase(aTmpCuts.begin()); - B2DPolygonNode* pActA = pCutA->getLeft(); - B2DPolygonNode* pActB = pCutA->getRight(); - sal_Bool bPrevSamePos(isPrevSamePos(pActA, pActB)); - sal_Bool bNextSamePos(isNextSamePos(pActA, pActB)); - - if(aTmpCuts.size()) + B2DSimpleCut* pCutB = 0L; + + if(isNextSamePos(pCutA->getLeft(), pCutA->getRight())) { - B2DSimpleCut* pCutB = 0L; + // this is a start node + B2DPolygonNode* pActA = pCutA->getLeft()->getNext(); + B2DPolygonNode* pActB = pCutA->getRight()->getNext(); - if(isNextSamePos(pCutA->getLeft(), pCutA->getRight())) + while(!pCutB && pActA != pCutA->getLeft()) { - // this is a start node - B2DPolygonNode* pActA = pCutA->getLeft()->getNext(); - B2DPolygonNode* pActB = pCutA->getRight()->getNext(); - - while(!pCutB && pActA != pCutA->getLeft()) + if(!isNextSamePos(pActA, pActB)) { - if(!isNextSamePos(pActA, pActB)) - { - pCutB = getExistingCut(aTmpCuts, pActA, pActB); - } - - pActA = pActA->getNext(); - pActB = pActB->getNext(); + pCutB = getExistingCut(aTmpCuts, pActA, pActB); } - if(pCutB) + pActA = pActA->getNext(); + pActB = pActB->getNext(); + } + + if(pCutB) + { + const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); + aTmpCuts.erase(aFindResult); + + if(isCrossover(pCutA, pCutB)) + { + aNewCuts.push_back(pCutB); + } + else { - const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); - aTmpCuts.erase(aFindResult); + delete pCutB; + } + } + } + else + { + // this is a end node + B2DPolygonNode* pActA = pCutA->getLeft()->getPrevious(); + B2DPolygonNode* pActB = pCutA->getRight()->getPrevious(); - if(isCrossover(pCutA, pCutB)) - { - aNewCuts.push_back(pCutB); - } - else - { - delete pCutB; - } + while(!pCutB && pActA != pCutA->getLeft()) + { + if(!isPrevSamePos(pActA, pActB)) + { + pCutB = getExistingCut(aTmpCuts, pActA, pActB); } + + pActA = pActA->getPrevious(); + pActB = pActB->getPrevious(); } - else + + if(pCutB) { - // this is a end node - B2DPolygonNode* pActA = pCutA->getLeft()->getPrevious(); - B2DPolygonNode* pActB = pCutA->getRight()->getPrevious(); + const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); + aTmpCuts.erase(aFindResult); - while(!pCutB && pActA != pCutA->getLeft()) + if(isCrossover(pCutB, pCutA)) { - if(!isPrevSamePos(pActA, pActB)) - { - pCutB = getExistingCut(aTmpCuts, pActA, pActB); - } - - pActA = pActA->getPrevious(); - pActB = pActB->getPrevious(); + aNewCuts.push_back(pCutB); } - - if(pCutB) + else { - const B2DSimpleCutVector::iterator aFindResult = ::std::find(aTmpCuts.begin(), aTmpCuts.end(), pCutB); - aTmpCuts.erase(aFindResult); - - if(isCrossover(pCutB, pCutA)) - { - aNewCuts.push_back(pCutB); - } - else - { - delete pCutB; - } + delete pCutB; } } } - - // delete cut in EVERY case - delete pCutA; } - // copy new cuts to all cuts - aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); - aNewCuts.clear(); + // delete cut in EVERY case + delete pCutA; } + + // copy new cuts to all cuts + aCuts.insert(aCuts.begin(), aNewCuts.begin(), aNewCuts.end()); + aNewCuts.clear(); } } + } - // delete volume list again - delete[] pVolumes; + // delete volume list again + delete[] pVolumes; - // are there cuts to solve? Solve them all in one run - if(aCuts.size()) - { - solveAllCuts(aCuts); - } + // are there cuts to solve? Solve them all in one run + if(aCuts.size()) + { + solveAllCuts(aCuts); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b2dpolypolygontools.cxx b/basegfx/source/polygon/b2dpolypolygontools.cxx index 3ddb6f11a0a3..60f61b347135 100644 --- a/basegfx/source/polygon/b2dpolypolygontools.cxx +++ b/basegfx/source/polygon/b2dpolypolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolypolygontools.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:40:12 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,153 +87,164 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B2DPolyPolygon tools + + void correctOrientations(::basegfx::B2DPolyPolygon& rCandidate) { - // B2DPolyPolygon tools + const sal_uInt32 nPolygonCount(rCandidate.count()); + sal_uInt32 nIndexOfOutmostPolygon(0L); + sal_Bool bIndexOfOutmostPolygonSet(sal_False); - void correctOrientations(::basegfx::polygon::B2DPolyPolygon& rCandidate) + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(rCandidate.count()); - sal_uInt32 nIndexOfOutmostPolygon(0L); - sal_Bool bIndexOfOutmostPolygonSet(sal_False); + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - for(sal_uInt32 a(0L); a < nPolygonCount; a++) + if(aCandidate.count() > 2L) { - ::basegfx::polygon::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - - if(aCandidate.count() > 2L) + ::basegfx::B2DVectorOrientation aOrientation = + ::basegfx::tools::getOrientation(aCandidate); + sal_Bool bDoFlip(::basegfx::ORIENTATION_POSITIVE != aOrientation); + + // init values for depth and compare point for + // inside test. Since the ordering makes only sense when assuming + // that there are no intersections, the inside test is done with + // any point of the candidate, so teke the first one. + sal_uInt32 nDepth(0L); + const ::basegfx::B2DPoint aTestPoint(aCandidate.getB2DPoint(0L)); + + // loop over other polygons and calculate depth + for(sal_uInt32 b(0L); b < nPolygonCount; b++) { - ::basegfx::vector::B2DVectorOrientation aOrientation = - ::basegfx::polygon::tools::getOrientation(aCandidate); - sal_Bool bDoFlip(::basegfx::vector::ORIENTATION_POSITIVE != aOrientation); - - // init values for depth and compare point for - // inside test. Since the ordering makes only sense when assuming - // that there are no intersections, the inside test is done with - // any point of the candidate, so teke the first one. - sal_uInt32 nDepth(0L); - const ::basegfx::point::B2DPoint aTestPoint(aCandidate.getB2DPoint(0L)); - - // loop over other polygons and calculate depth - for(sal_uInt32 b(0L); b < nPolygonCount; b++) + if(b != a) { - if(b != a) - { - ::basegfx::polygon::B2DPolygon aComparePolygon = rCandidate.getB2DPolygon(b); + ::basegfx::B2DPolygon aComparePolygon = rCandidate.getB2DPolygon(b); - if(::basegfx::polygon::tools::isInside(aComparePolygon, aTestPoint)) - { - nDepth++; - } + if(::basegfx::tools::isInside(aComparePolygon, aTestPoint)) + { + nDepth++; } } + } - // if nDepth is odd it is a hole - sal_Bool bIsHole(1L == (nDepth & 0x00000001)); + // if nDepth is odd it is a hole + sal_Bool bIsHole(1L == (nDepth & 0x00000001)); - // does polygon need to be flipped? - if((bDoFlip && !bIsHole) || (!bDoFlip && bIsHole)) - { - aCandidate.flip(); - - // write back changed polygon - rCandidate.setB2DPolygon(a, aCandidate); - } + // does polygon need to be flipped? + if((bDoFlip && !bIsHole) || (!bDoFlip && bIsHole)) + { + aCandidate.flip(); - // remember the index if it's the outmost polygon - if(!bIndexOfOutmostPolygonSet && 0L == nDepth) - { - bIndexOfOutmostPolygonSet = sal_True; - nIndexOfOutmostPolygon = a; - } + // write back changed polygon + rCandidate.setB2DPolygon(a, aCandidate); } - } - // if the outmost polygon is not the first, move it in front - if(bIndexOfOutmostPolygonSet && nIndexOfOutmostPolygon > 0L) - { - ::basegfx::polygon::B2DPolygon aOutmostPolygon = rCandidate.getB2DPolygon(nIndexOfOutmostPolygon); - rCandidate.remove(nIndexOfOutmostPolygon); - rCandidate.insert(0L, aOutmostPolygon); + // remember the index if it's the outmost polygon + if(!bIndexOfOutmostPolygonSet && 0L == nDepth) + { + bIndexOfOutmostPolygonSet = sal_True; + nIndexOfOutmostPolygon = a; + } } } - void removeIntersections(::basegfx::polygon::B2DPolyPolygon& rCandidate, - sal_Bool bForceOrientation, sal_Bool bInvertRemove) + // if the outmost polygon is not the first, move it in front + if(bIndexOfOutmostPolygonSet && nIndexOfOutmostPolygon > 0L) { - ::basegfx::polygon::B2DPolyPolygonCutter aCutter; - - aCutter.addPolyPolygon(rCandidate, bForceOrientation); - aCutter.removeSelfIntersections(); - aCutter.removeDoubleIntersections(); - aCutter.removeIncludedPolygons(!bInvertRemove); - rCandidate.clear(); - aCutter.getPolyPolygon(rCandidate); + ::basegfx::B2DPolygon aOutmostPolygon = rCandidate.getB2DPolygon(nIndexOfOutmostPolygon); + rCandidate.remove(nIndexOfOutmostPolygon); + rCandidate.insert(0L, aOutmostPolygon); } + } + + void removeIntersections(::basegfx::B2DPolyPolygon& rCandidate, + sal_Bool bForceOrientation, sal_Bool bInvertRemove) + { + ::basegfx::B2DPolyPolygonCutter aCutter; + + aCutter.addPolyPolygon(rCandidate, bForceOrientation); + aCutter.removeSelfIntersections(); + aCutter.removeDoubleIntersections(); + aCutter.removeIncludedPolygons(!bInvertRemove); + rCandidate.clear(); + aCutter.getPolyPolygon(rCandidate); + } - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fDistanceBound) + ::basegfx::B2DPolyPolygon adaptiveSubdivideByDistance(const ::basegfx::B2DPolyPolygon& rCandidate, double fDistanceBound) + { + ::basegfx::B2DPolyPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolyPolygon aRetval(rCandidate); + const sal_uInt32 nPolygonCount(aRetval.count()); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(aRetval.count()); + ::basegfx::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) + if(aCandidate.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - - if(aCandidate.areControlPointsUsed()) - { - aCandidate = ::basegfx::polygon::tools::adaptiveSubdivideByDistance(aCandidate, fDistanceBound); - aRetval.setB2DPolygon(a, aCandidate); - } + aCandidate = ::basegfx::tools::adaptiveSubdivideByDistance(aCandidate, fDistanceBound); + aRetval.setB2DPolygon(a, aCandidate); } } - - return aRetval; } - ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fAngleBound) + return aRetval; + } + + ::basegfx::B2DPolyPolygon adaptiveSubdivideByAngle(const ::basegfx::B2DPolyPolygon& rCandidate, double fAngleBound) + { + ::basegfx::B2DPolyPolygon aRetval(rCandidate); + + if(aRetval.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolyPolygon aRetval(rCandidate); + const sal_uInt32 nPolygonCount(aRetval.count()); - if(aRetval.areControlPointsUsed()) + for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) { - const sal_uInt32 nPolygonCount(aRetval.count()); + ::basegfx::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++) + if(aCandidate.areControlPointsUsed()) { - ::basegfx::polygon::B2DPolygon aCandidate = aRetval.getB2DPolygon(a); - - if(aCandidate.areControlPointsUsed()) - { - aCandidate = ::basegfx::polygon::tools::adaptiveSubdivideByAngle(aCandidate, fAngleBound); - aRetval.setB2DPolygon(a, aCandidate); - } + aCandidate = ::basegfx::tools::adaptiveSubdivideByAngle(aCandidate, fAngleBound); + aRetval.setB2DPolygon(a, aCandidate); } } - - return aRetval; } - ::basegfx::range::B2DRange getRange(const ::basegfx::polygon::B2DPolyPolygon& rCandidate) + return aRetval; + } + + ::basegfx::B2DRange getRange(const ::basegfx::B2DPolyPolygon& rCandidate) + { + ::basegfx::B2DRange aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - ::basegfx::range::B2DRange aRetval; - const sal_uInt32 nPolygonCount(rCandidate.count()); + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); + aRetval.expand(::basegfx::tools::getRange(aCandidate)); + } - for(sal_uInt32 a(0L); a < nPolygonCount; a++) - { - ::basegfx::polygon::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); - aRetval.expand(::basegfx::polygon::tools::getRange(aCandidate)); - } + return aRetval; + } + + ::basegfx::B2DPolyPolygon applyLineDashing(const ::basegfx::B2DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B2DPolyPolygon aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); - return aRetval; + for(sal_uInt32 a(0L); a < nPolygonCount; a++) + { + ::basegfx::B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); + aRetval.append(applyLineDashing(aCandidate, raDashDotArray, fFullDashDotLen)); } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolygon.cxx b/basegfx/source/polygon/b3dpolygon.cxx index df2672d6bbf4..0d488c04bf2c 100644 --- a/basegfx/source/polygon/b3dpolygon.cxx +++ b/basegfx/source/polygon/b3dpolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygon.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:36 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,17 +82,17 @@ class CoordinateData3D { - ::basegfx::point::B3DPoint maPoint; + ::basegfx::B3DPoint maPoint; public: CoordinateData3D() {} - CoordinateData3D(const ::basegfx::point::B3DPoint& rData) : maPoint(rData) {} + CoordinateData3D(const ::basegfx::B3DPoint& rData) : maPoint(rData) {} ~CoordinateData3D() {} - const ::basegfx::point::B3DPoint& getCoordinate() const { return maPoint; } - void setCoordinate(const ::basegfx::point::B3DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } + const ::basegfx::B3DPoint& getCoordinate() const { return maPoint; } + void setCoordinate(const ::basegfx::B3DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } sal_Bool operator==(const CoordinateData3D& rData ) const { return (maPoint == rData.getCoordinate()); } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) { maPoint *= rMatrix; } + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { maPoint *= rMatrix; } }; ////////////////////////////////////////////////////////////////////////////// @@ -133,12 +133,12 @@ public: return (maVector == rCandidate.maVector); } - const ::basegfx::point::B3DPoint& getCoordinate(sal_uInt32 nIndex) const + const ::basegfx::B3DPoint& getCoordinate(sal_uInt32 nIndex) const { return maVector[nIndex].getCoordinate(); } - void setCoordinate(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + void setCoordinate(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) { maVector[nIndex].setCoordinate(rValue); } @@ -229,7 +229,7 @@ public: } } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { CoordinateData3DVector::iterator aStart(maVector.begin()); CoordinateData3DVector::iterator aEnd(maVector.end()); @@ -333,17 +333,17 @@ public: return sal_False; } - const ::basegfx::point::B3DPoint& getPoint(sal_uInt32 nIndex) const + const ::basegfx::B3DPoint& getPoint(sal_uInt32 nIndex) const { return maPoints.getCoordinate(nIndex); } - void setPoint(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + void setPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) { maPoints.setCoordinate(nIndex, rValue); } - void insert(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) { if(nCount) { @@ -417,7 +417,7 @@ public: maPoints.removeDoublePointsWholeTrack(); } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { maPoints.transform(rMatrix); } @@ -427,253 +427,250 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB3DPolygon maStaticDefaultPolygon; + // init static default Polygon + static ImplB3DPolygon maStaticDefaultPolygon; - void B3DPolygon::implForceUniqueCopy() + void B3DPolygon::implForceUniqueCopy() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - mpPolygon = new ImplB3DPolygon(*mpPolygon); - } + mpPolygon->decRefCount(); + mpPolygon = new ImplB3DPolygon(*mpPolygon); } + } + + B3DPolygon::B3DPolygon() + : mpPolygon(&maStaticDefaultPolygon) + { + mpPolygon->incRefCount(); + } - B3DPolygon::B3DPolygon() - : mpPolygon(&maStaticDefaultPolygon) + B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon) + : mpPolygon(rPolygon.mpPolygon) + { + mpPolygon->incRefCount(); + } + + B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) + : mpPolygon(new ImplB3DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + { + OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B3DPolygon constructor outside range (!)"); + } + + B3DPolygon::~B3DPolygon() + { + if(mpPolygon->getRefCount()) { - mpPolygon->incRefCount(); + mpPolygon->decRefCount(); } - - B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon) - : mpPolygon(rPolygon.mpPolygon) + else { - mpPolygon->incRefCount(); + delete mpPolygon; } + } - B3DPolygon::B3DPolygon(const B3DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) - : mpPolygon(new ImplB3DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + B3DPolygon& B3DPolygon::operator=(const B3DPolygon& rPolygon) + { + if(mpPolygon->getRefCount()) { - OSL_ENSURE(nIndex + nCount > rPolygon.mpPolygon->count(), "B3DPolygon constructor outside range (!)"); + mpPolygon->decRefCount(); } - - B3DPolygon::~B3DPolygon() + else { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + delete mpPolygon; } - B3DPolygon& B3DPolygon::operator=(const B3DPolygon& rPolygon) - { - if(mpPolygon->getRefCount()) - { - mpPolygon->decRefCount(); - } - else - { - delete mpPolygon; - } + mpPolygon = rPolygon.mpPolygon; + mpPolygon->incRefCount(); - mpPolygon = rPolygon.mpPolygon; - mpPolygon->incRefCount(); + return *this; + } - return *this; + sal_Bool B3DPolygon::operator==(const B3DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return sal_True; } - sal_Bool B3DPolygon::operator==(const B3DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_True; - } + return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + sal_Bool B3DPolygon::operator!=(const B3DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return sal_False; } - sal_Bool B3DPolygon::operator!=(const B3DPolygon& rPolygon) const - { - if(mpPolygon == rPolygon.mpPolygon) - { - return sal_False; - } + return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } - return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); - } + sal_uInt32 B3DPolygon::count() const + { + return mpPolygon->count(); + } - sal_uInt32 B3DPolygon::count() const - { - return mpPolygon->count(); - } + ::basegfx::B3DPoint B3DPolygon::getB3DPoint(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - ::basegfx::point::B3DPoint B3DPolygon::getB3DPoint(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); + return mpPolygon->getPoint(nIndex); + } - return mpPolygon->getPoint(nIndex); - } + void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - void B3DPolygon::setB3DPoint(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rValue) + if(mpPolygon->getPoint(nIndex) != rValue) { - OSL_ENSURE(nIndex < mpPolygon->count(), "B3DPolygon access outside range (!)"); - - if(mpPolygon->getPoint(nIndex) != rValue) - { - implForceUniqueCopy(); - mpPolygon->setPoint(nIndex, rValue); - } + implForceUniqueCopy(); + mpPolygon->setPoint(nIndex, rValue); } + } - void B3DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + void B3DPolygon::insert(sal_uInt32 nIndex, const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(nIndex, rPoint, nCount); - } + if(nCount) + { + implForceUniqueCopy(); + mpPolygon->insert(nIndex, rPoint, nCount); } + } - void B3DPolygon::append(const ::basegfx::point::B3DPoint& rPoint, sal_uInt32 nCount) + void B3DPolygon::append(const ::basegfx::B3DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolygon->insert(mpPolygon->count(), rPoint, nCount); - } + implForceUniqueCopy(); + mpPolygon->insert(mpPolygon->count(), rPoint, nCount); } + } + + void B3DPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - void B3DPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + if(rPoly.count()) { - OSL_ENSURE(nIndex <= mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + implForceUniqueCopy(); - if(rPoly.count()) + if(!nCount) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex2 && nCount == rPoly.count()) - { - mpPolygon->insert(nIndex, *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B3DPolygon Insert outside range (!)"); - ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); - mpPolygon->insert(nIndex, aTempPoly); - } + nCount = rPoly.count(); } - } - void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) - { - if(rPoly.count()) + if(0L == nIndex2 && nCount == rPoly.count()) { - implForceUniqueCopy(); - - if(!nCount) - { - nCount = rPoly.count(); - } - - if(0L == nIndex && nCount == rPoly.count()) - { - mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); - } - else - { - OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)"); - ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(mpPolygon->count(), aTempPoly); - } + mpPolygon->insert(nIndex, *rPoly.mpPolygon); + } + else + { + OSL_ENSURE(nIndex2 + nCount > rPoly.mpPolygon->count(), "B3DPolygon Insert outside range (!)"); + ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); + mpPolygon->insert(nIndex, aTempPoly); } } + } - void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B3DPolygon::append(const B3DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(rPoly.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B3DPolygon Remove outside range (!)"); + implForceUniqueCopy(); - if(nCount) + if(!nCount) { - implForceUniqueCopy(); - mpPolygon->remove(nIndex, nCount); + nCount = rPoly.count(); } - } - void B3DPolygon::clear() - { - if(mpPolygon->getRefCount()) + if(0L == nIndex && nCount == rPoly.count()) { - mpPolygon->decRefCount(); + mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); } else { - delete mpPolygon; + OSL_ENSURE(nIndex + nCount > rPoly.mpPolygon->count(), "B3DPolygon Append outside range (!)"); + ImplB3DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); + mpPolygon->insert(mpPolygon->count(), aTempPoly); } - - mpPolygon = &maStaticDefaultPolygon; - mpPolygon->incRefCount(); } + } - sal_Bool B3DPolygon::isClosed() const + void B3DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B3DPolygon Remove outside range (!)"); + + if(nCount) { - return mpPolygon->isClosed(); + implForceUniqueCopy(); + mpPolygon->remove(nIndex, nCount); } + } - void B3DPolygon::setClosed(sal_Bool bNew) + void B3DPolygon::clear() + { + if(mpPolygon->getRefCount()) { - if(mpPolygon->isClosed() != bNew) - { - implForceUniqueCopy(); - mpPolygon->setClosed(bNew); - } + mpPolygon->decRefCount(); } + else + { + delete mpPolygon; + } + + mpPolygon = &maStaticDefaultPolygon; + mpPolygon->incRefCount(); + } + + sal_Bool B3DPolygon::isClosed() const + { + return mpPolygon->isClosed(); + } - void B3DPolygon::flip() + void B3DPolygon::setClosed(sal_Bool bNew) + { + if(mpPolygon->isClosed() != bNew) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->flip(); - } + implForceUniqueCopy(); + mpPolygon->setClosed(bNew); } + } - sal_Bool B3DPolygon::hasDoublePoints() const + void B3DPolygon::flip() + { + if(mpPolygon->count() > 1) { - return mpPolygon->hasDoublePoints(); + implForceUniqueCopy(); + mpPolygon->flip(); } + } - void B3DPolygon::removeDoublePoints() + sal_Bool B3DPolygon::hasDoublePoints() const + { + return mpPolygon->hasDoublePoints(); + } + + void B3DPolygon::removeDoublePoints() + { + if(mpPolygon->count() > 1) { - if(mpPolygon->count() > 1) - { - implForceUniqueCopy(); - mpPolygon->removeDoublePointsAtBeginEnd(); - mpPolygon->removeDoublePointsWholeTrack(); - } + implForceUniqueCopy(); + mpPolygon->removeDoublePointsAtBeginEnd(); + mpPolygon->removeDoublePointsWholeTrack(); } + } - void B3DPolygon::transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void B3DPolygon::transform(const ::basegfx::B3DHomMatrix& rMatrix) + { + if(mpPolygon->count()) { - if(mpPolygon->count()) - { - implForceUniqueCopy(); - mpPolygon->transform(rMatrix); - } + implForceUniqueCopy(); + mpPolygon->transform(rMatrix); } - } // end of namespace polygon + } } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolygontools.cxx b/basegfx/source/polygon/b3dpolygontools.cxx index 473aa6baef45..9784ae5930a9 100644 --- a/basegfx/source/polygon/b3dpolygontools.cxx +++ b/basegfx/source/polygon/b3dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolygontools.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:39 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,275 +83,344 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B3DPolygon tools + void checkClosed(B3DPolygon& rCandidate) { - // B3DPolygon tools - void checkClosed(polygon::B3DPolygon& rCandidate) + while(rCandidate.count() > 1L + && rCandidate.getB3DPoint(0L).equal(rCandidate.getB3DPoint(rCandidate.count() - 1L))) { - while(rCandidate.count() > 1L - && rCandidate.getB3DPoint(0L).equal(rCandidate.getB3DPoint(rCandidate.count() - 1L))) - { - rCandidate.setClosed(sal_True); - rCandidate.remove(rCandidate.count() - 1L); - } + rCandidate.setClosed(sal_True); + rCandidate.remove(rCandidate.count() - 1L); } + } + + // Get successor and predecessor indices. Returning the same index means there + // is none. Same for successor. + sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - // Get successor and predecessor indices. Returning the same index means there - // is none. Same for successor. - sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + if(nIndex) + { + return nIndex - 1L; + } + else if(rCandidate.count()) + { + return rCandidate.count() - 1L; + } + else { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nIndex; + } + } - if(nIndex) - { - return nIndex - 1L; - } - else if(rCandidate.count()) - { - return rCandidate.count() - 1L; - } - else - { - return nIndex; - } + sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(nIndex + 1L < rCandidate.count()) + { + return nIndex + 1L; } + else + { + return 0L; + } + } + + sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + if(rCandidate.count() > 1) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); + ::basegfx::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - if(nIndex + 1L < rCandidate.count()) - { - return nIndex + 1L; - } - else + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) { - return 0L; + nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); } } - sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) + return nNewIndex; + } + + sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rCandidate) + { + sal_uInt32 nNewIndex(nIndex); + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + + if(rCandidate.count() > 1) { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); + ::basegfx::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - if(rCandidate.count() > 1) + while(nNewIndex != nIndex + && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) { - nNewIndex = getIndexOfPredecessor(nIndex, rCandidate); - ::basegfx::point::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) - { - nNewIndex = getIndexOfPredecessor(nNewIndex, rCandidate); - } + nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); } - - return nNewIndex; } - sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rCandidate) - { - sal_uInt32 nNewIndex(nIndex); - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + return nNewIndex; + } - if(rCandidate.count() > 1) - { - nNewIndex = getIndexOfSuccessor(nIndex, rCandidate); - ::basegfx::point::B3DPoint aPoint(rCandidate.getB3DPoint(nIndex)); - - while(nNewIndex != nIndex - && aPoint.equal(rCandidate.getB3DPoint(nNewIndex))) - { - nNewIndex = getIndexOfSuccessor(nNewIndex, rCandidate); - } - } + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolygon& rCandidate) + { + ::basegfx::B3DRange aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); - return nNewIndex; + for(sal_uInt32 a(0L); a < nPointCount; a++) + { + const ::basegfx::B3DPoint aTestPoint(rCandidate.getB3DPoint(a)); + aRetval.expand(aTestPoint); } - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolygon& rCandidate) - { - ::basegfx::range::B3DRange aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); + return aRetval; + } + + double getEdgeLength(const ::basegfx::B3DPolygon& rCandidate, sal_uInt32 nIndex) + { + OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(nIndex < nPointCount) + { + if(rCandidate.isClosed() || nIndex + 1 != nPointCount) { - const ::basegfx::point::B3DPoint aTestPoint(rCandidate.getB3DPoint(a)); - aRetval.expand(aTestPoint); + const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); + const ::basegfx::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(nIndex)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + const ::basegfx::B3DVector aVector(aNextPoint - aCurrentPoint); + fRetval = aVector.getLength(); } + } - return aRetval; + return fRetval; + } + + double getLength(const ::basegfx::B3DPolygon& rCandidate) + { + // This method may also be implemented using a loop over getEdgeLength, but + // since this would cause a lot of sqare roots to be solved it is much better + // to sum up the quadrats first and then use a singe suare root (if necessary) + double fRetval(0.0); + const sal_uInt32 nPointCount(rCandidate.count()); + const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); + const ::basegfx::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(a)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + const ::basegfx::B3DVector aVector(aNextPoint - aCurrentPoint); + fRetval += aVector.scalar(aVector); } - double getEdgeLength(const ::basegfx::polygon::B3DPolygon& rCandidate, sal_uInt32 nIndex) + if(!::basegfx::fTools::equalZero(fRetval)) { - OSL_ENSURE(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)"); - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); + const double fOne(1.0); - if(nIndex < nPointCount) + if(!::basegfx::fTools::equal(fOne, fRetval)) { - if(rCandidate.isClosed() || nIndex + 1 != nPointCount) - { - const sal_uInt32 nNextIndex(nIndex + 1 == nPointCount ? 0L : nIndex + 1L); - const ::basegfx::point::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(nIndex)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - const ::basegfx::vector::B3DVector aVector(aNextPoint - aCurrentPoint); - fRetval = aVector.getLength(); - } + fRetval = sqrt(fRetval); } - - return fRetval; } - double getLength(const ::basegfx::polygon::B3DPolygon& rCandidate) + return fRetval; + } + + ::basegfx::B3DPoint getPositionAbsolute(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength) + { + ::basegfx::B3DPoint aRetval; + const sal_uInt32 nPointCount(rCandidate.count()); + + if(nPointCount > 1L) { - // This method may also be implemented using a loop over getEdgeLength, but - // since this would cause a lot of sqare roots to be solved it is much better - // to sum up the quadrats first and then use a singe suare root (if necessary) - double fRetval(0.0); - const sal_uInt32 nPointCount(rCandidate.count()); - const sal_uInt32 nLoopCount(rCandidate.isClosed() ? nPointCount : nPointCount - 1L); - - for(sal_uInt32 a(0L); a < nLoopCount; a++) + sal_uInt32 nIndex(0L); + sal_Bool bIndexDone(sal_False); + const double fZero(0.0); + double fEdgeLength(fZero); + + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) { - const sal_uInt32 nNextIndex(a + 1 == nPointCount ? 0L : a + 1L); - const ::basegfx::point::B3DPoint aCurrentPoint(rCandidate.getB3DPoint(a)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - const ::basegfx::vector::B3DVector aVector(aNextPoint - aCurrentPoint); - fRetval += aVector.scalar(aVector); + fLength = getLength(rCandidate); } - if(!::basegfx::numeric::fTools::equalZero(fRetval)) + // handle fDistance < 0.0 + if(::basegfx::fTools::less(fDistance, fZero)) { - const double fOne(1.0); - - if(!::basegfx::numeric::fTools::equal(fOne, fRetval)) + if(rCandidate.isClosed()) + { + // if fDistance < 0.0 increment with multiple of fLength + sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); + fDistance += double(nCount + 1L) * fLength; + } + else { - fRetval = sqrt(fRetval); + // crop to polygon start + fDistance = fZero; + bIndexDone = sal_True; } } - return fRetval; - } - - ::basegfx::point::B3DPoint getPositionAbsolute(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength) - { - ::basegfx::point::B3DPoint aRetval; - const sal_uInt32 nPointCount(rCandidate.count()); - - if(nPointCount > 1L) + // handle fDistance >= fLength + if(::basegfx::fTools::moreOrEqual(fDistance, fLength)) { - sal_uInt32 nIndex(0L); - sal_Bool bIndexDone(sal_False); - const double fZero(0.0); - double fEdgeLength(fZero); - - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) + if(rCandidate.isClosed()) { - fLength = getLength(rCandidate); + // if fDistance >= fLength decrement with multiple of fLength + sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); + fDistance -= (double)(nCount) * fLength; } - - // handle fDistance < 0.0 - if(::basegfx::numeric::fTools::less(fDistance, fZero)) + else { - if(rCandidate.isClosed()) - { - // if fDistance < 0.0 increment with multiple of fLength - sal_uInt32 nCount(sal_uInt32(-fDistance / fLength)); - fDistance += double(nCount + 1L) * fLength; - } - else - { - // crop to polygon start - fDistance = fZero; - bIndexDone = sal_True; - } + // crop to polygon end + fDistance = fZero; + nIndex = nPointCount - 1L; + bIndexDone = sal_True; } + } - // handle fDistance >= fLength - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fLength)) + // look for correct index. fDistance is now [0.0 .. fLength[ + if(!bIndexDone) + { + do { - if(rCandidate.isClosed()) + // get length of next edge + fEdgeLength = getEdgeLength(rCandidate, nIndex); + + if(::basegfx::fTools::moreOrEqual(fDistance, fEdgeLength)) { - // if fDistance >= fLength decrement with multiple of fLength - sal_uInt32 nCount(sal_uInt32(fDistance / fLength)); - fDistance -= (double)(nCount) * fLength; + // go to next edge + fDistance -= fEdgeLength; + nIndex++; } else { - // crop to polygon end - fDistance = fZero; - nIndex = nPointCount - 1L; + // it's on this edge, stop bIndexDone = sal_True; } + } while (!bIndexDone); + } + + // get the point using nIndex + aRetval = rCandidate.getB3DPoint(nIndex); + + // if fDistance != 0.0, move that length on the edge. The edge + // length is in fEdgeLength. + if(!::basegfx::fTools::equalZero(fDistance)) + { + sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); + const ::basegfx::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); + double fRelative(fZero); + + if(!::basegfx::fTools::equalZero(fEdgeLength)) + { + fRelative = fDistance / fEdgeLength; } - // look for correct index. fDistance is now [0.0 .. fLength[ - if(!bIndexDone) + // add calculated average value to the return value + aRetval += ::basegfx::average(aRetval, aNextPoint, fRelative); + } + } + + return aRetval; + } + + ::basegfx::B3DPoint getPositionRelative(const ::basegfx::B3DPolygon& rCandidate, double fDistance, double fLength) + { + // get length if not given + if(::basegfx::fTools::equalZero(fLength)) + { + fLength = getLength(rCandidate); + } + + // multiply fDistance with real length to get absolute position and + // use getPositionAbsolute + return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + } + + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B3DPolyPolygon aRetval; + + if(rCandidate.count() && fFullDashDotLen > 0.0) + { + const sal_uInt32 nCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L); + sal_uInt32 nDashDotIndex(0L); + double fDashDotLength(raDashDotArray[nDashDotIndex]); + + for(sal_uInt32 a(0L); a < nCount; a++) + { + const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); + const ::basegfx::B3DPoint aStart(rCandidate.getB3DPoint(a)); + const ::basegfx::B3DPoint aEnd(rCandidate.getB3DPoint(nNextIndex)); + ::basegfx::B3DVector aVector(aEnd - aStart); + double fLength(aVector.getLength()); + double fPosOnVector(0.0); + aVector.normalize(); + + while(fLength >= fDashDotLength) { - do + // handle [fPosOnVector .. fPosOnVector+fDashDotLength] + if(nDashDotIndex % 2) { - // get length of next edge - fEdgeLength = getEdgeLength(rCandidate, nIndex); + ::basegfx::B3DPolygon aResult; - if(::basegfx::numeric::fTools::moreOrEqual(fDistance, fEdgeLength)) + // add start point + if(fPosOnVector == 0.0) { - // go to next edge - fDistance -= fEdgeLength; - nIndex++; + aResult.append(aStart); } else { - // it's on this edge, stop - bIndexDone = sal_True; + aResult.append(aStart + (aVector * fPosOnVector)); } - } while (!bIndexDone); - } - // get the point using nIndex - aRetval = rCandidate.getB3DPoint(nIndex); + // add end point + aResult.append(aStart + (aVector * (fPosOnVector + fDashDotLength))); - // if fDistance != 0.0, move that length on the edge. The edge - // length is in fEdgeLength. - if(!::basegfx::numeric::fTools::equalZero(fDistance)) - { - sal_uInt32 nNextIndex(getIndexOfSuccessor(nIndex, rCandidate)); - const ::basegfx::point::B3DPoint aNextPoint(rCandidate.getB3DPoint(nNextIndex)); - double fRelative(fZero); - - if(!::basegfx::numeric::fTools::equalZero(fEdgeLength)) - { - fRelative = fDistance / fEdgeLength; + // add line to PolyPolygon + aRetval.append(aResult); } - // add calculated average value to the return value - aRetval += ::basegfx::tuple::average(aRetval, aNextPoint, fRelative); + // consume from fDashDotLength + fPosOnVector += fDashDotLength; + fLength -= fDashDotLength; + nDashDotIndex = (nDashDotIndex + 1L) % raDashDotArray.size(); + fDashDotLength = raDashDotArray[nDashDotIndex]; } - } - return aRetval; - } + // handle [fPosOnVector .. fPosOnVector+fLength (bzw. end)] + if((fLength > 0.0) && (nDashDotIndex % 2)) + { + ::basegfx::B3DPolygon aResult; - ::basegfx::point::B3DPoint getPositionRelative(const ::basegfx::polygon::B3DPolygon& rCandidate, double fDistance, double fLength) - { - // get length if not given - if(::basegfx::numeric::fTools::equalZero(fLength)) - { - fLength = getLength(rCandidate); - } + // add start and end point + const ::basegfx::B3DPoint aPosA(aStart + (aVector * fPosOnVector)); + aResult.append(aPosA); + aResult.append(aEnd); - // multiply fDistance with real length to get absolute position and - // use getPositionAbsolute - return getPositionAbsolute(rCandidate, fDistance * fLength, fLength); + // add line to PolyPolygon + aRetval.append(aResult); + } + + // consume from fDashDotLength + fDashDotLength -= fLength; + } } - } // end of namespace tools - } // end of namespace polygon + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// diff --git a/basegfx/source/polygon/b3dpolypolygon.cxx b/basegfx/source/polygon/b3dpolypolygon.cxx index 28e43316f369..bb78552b24e5 100644 --- a/basegfx/source/polygon/b3dpolypolygon.cxx +++ b/basegfx/source/polygon/b3dpolypolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygon.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:37 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,7 +77,7 @@ class ImplB3DPolyPolygon { - typedef ::std::vector< ::basegfx::polygon::B3DPolygon > PolygonVector; + typedef ::std::vector< ::basegfx::B3DPolygon > PolygonVector; PolygonVector maPolygons; sal_uInt32 mnRefCount; @@ -123,17 +123,17 @@ public: return sal_True; } - const ::basegfx::polygon::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const + const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const { return maPolygons[nIndex]; } - void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rPolygon) + void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon) { maPolygons[nIndex] = rPolygon; } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolygon& rPolygon, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount) { if(nCount) { @@ -144,7 +144,7 @@ public: } } - void insert(sal_uInt32 nIndex, const ::basegfx::polygon::B3DPolyPolygon& rPolyPolygon) + void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon) { const sal_uInt32 nCount = rPolyPolygon.count(); @@ -205,7 +205,7 @@ public: } } - void transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + void transform(const ::basegfx::B3DHomMatrix& rMatrix) { for(sal_uInt32 a(0L); a < maPolygons.size(); a++) { @@ -218,232 +218,229 @@ public: namespace basegfx { - namespace polygon - { - // init static default Polygon - static ImplB3DPolyPolygon maStaticDefaultPolyPolygon; + // init static default Polygon + static ImplB3DPolyPolygon maStaticDefaultPolyPolygon; - void B3DPolyPolygon::implForceUniqueCopy() + void B3DPolyPolygon::implForceUniqueCopy() + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - mpPolyPolygon = new ImplB3DPolyPolygon(*mpPolyPolygon); - } + mpPolyPolygon->decRefCount(); + mpPolyPolygon = new ImplB3DPolyPolygon(*mpPolyPolygon); } + } + + B3DPolyPolygon::B3DPolyPolygon() + : mpPolyPolygon(&maStaticDefaultPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } - B3DPolyPolygon::B3DPolyPolygon() - : mpPolyPolygon(&maStaticDefaultPolyPolygon) + B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) + : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B3DPolyPolygon::~B3DPolyPolygon() + { + if(mpPolyPolygon->getRefCount()) { - mpPolyPolygon->incRefCount(); + mpPolyPolygon->decRefCount(); } - - B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) - : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + else { - mpPolyPolygon->incRefCount(); + delete mpPolyPolygon; } + } - B3DPolyPolygon::~B3DPolyPolygon() + B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon) + { + if(mpPolyPolygon->getRefCount()) { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + mpPolyPolygon->decRefCount(); } - - B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon) + else { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } - - mpPolyPolygon = rPolyPolygon.mpPolyPolygon; - mpPolyPolygon->incRefCount(); - - return *this; + delete mpPolyPolygon; } - sal_Bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const - { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_True; - } + mpPolyPolygon = rPolyPolygon.mpPolyPolygon; + mpPolyPolygon->incRefCount(); - return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); - } + return *this; + } - sal_Bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const + sal_Bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) - { - return sal_False; - } - - return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + return sal_True; } - sal_uInt32 B3DPolyPolygon::count() const + return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } + + sal_Bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) { - return mpPolyPolygon->count(); + return sal_False; } - B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); + return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } - return mpPolyPolygon->getB3DPolygon(nIndex); - } + sal_uInt32 B3DPolyPolygon::count() const + { + return mpPolyPolygon->count(); + } - void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon) - { - OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); + B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); - if(mpPolyPolygon->getB3DPolygon(nIndex) != rPolygon) - { - implForceUniqueCopy(); - mpPolyPolygon->setB3DPolygon(nIndex, rPolygon); - } - } + return mpPolyPolygon->getB3DPolygon(nIndex); + } - void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount) - { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); + void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon) + { + OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)"); - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolygon, nCount); - } + if(mpPolyPolygon->getB3DPolygon(nIndex) != rPolygon) + { + implForceUniqueCopy(); + mpPolyPolygon->setB3DPolygon(nIndex, rPolygon); } + } - void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount) + void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolygon& rPolygon, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); + + if(nCount) { - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolygon, nCount); } + } - void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon) + void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) { - OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); - - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(nIndex, rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); } + } + + void B3DPolyPolygon::insert(sal_uInt32 nIndex, const B3DPolyPolygon& rPolyPolygon) + { + OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B3DPolyPolygon Insert outside range (!)"); - void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon) + if(rPolyPolygon.count()) { - if(rPolyPolygon.count()) - { - implForceUniqueCopy(); - mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolyPolygon); } + } - void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon) + { + if(rPolyPolygon.count()) { - OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)"); - - if(nCount) - { - implForceUniqueCopy(); - mpPolyPolygon->remove(nIndex, nCount); - } + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); } + } - void B3DPolyPolygon::clear() - { - if(mpPolyPolygon->getRefCount()) - { - mpPolyPolygon->decRefCount(); - } - else - { - delete mpPolyPolygon; - } + void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)"); - mpPolyPolygon = &maStaticDefaultPolyPolygon; - mpPolyPolygon->incRefCount(); + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->remove(nIndex, nCount); } + } - sal_Bool B3DPolyPolygon::isClosed() const + void B3DPolyPolygon::clear() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else { - sal_Bool bRetval(sal_True); + delete mpPolyPolygon; + } - // PolyPOlygon is closed when all contained Polygons are closed or - // no Polygon exists. - for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) - { - if(!(mpPolyPolygon->getB3DPolygon(a)).isClosed()) - { - bRetval = sal_False; - } - } + mpPolyPolygon = &maStaticDefaultPolyPolygon; + mpPolyPolygon->incRefCount(); + } - return bRetval; - } + sal_Bool B3DPolyPolygon::isClosed() const + { + sal_Bool bRetval(sal_True); - void B3DPolyPolygon::setClosed(sal_Bool bNew) + // PolyPOlygon is closed when all contained Polygons are closed or + // no Polygon exists. + for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++) { - if(bNew != isClosed()) + if(!(mpPolyPolygon->getB3DPolygon(a)).isClosed()) { - implForceUniqueCopy(); - mpPolyPolygon->setClosed(bNew); + bRetval = sal_False; } } - void B3DPolyPolygon::flip() + return bRetval; + } + + void B3DPolyPolygon::setClosed(sal_Bool bNew) + { + if(bNew != isClosed()) { implForceUniqueCopy(); - mpPolyPolygon->flip(); + mpPolyPolygon->setClosed(bNew); } + } - sal_Bool B3DPolyPolygon::hasDoublePoints() const - { - sal_Bool bRetval(sal_False); - - for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) - { - if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints()) - { - bRetval = sal_True; - } - } + void B3DPolyPolygon::flip() + { + implForceUniqueCopy(); + mpPolyPolygon->flip(); + } - return bRetval; - } + sal_Bool B3DPolyPolygon::hasDoublePoints() const + { + sal_Bool bRetval(sal_False); - void B3DPolyPolygon::removeDoublePoints() + for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++) { - if(hasDoublePoints()) + if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints()) { - implForceUniqueCopy(); - mpPolyPolygon->removeDoublePoints(); + bRetval = sal_True; } } - void B3DPolyPolygon::transform(const ::basegfx::matrix::B3DHomMatrix& rMatrix) + return bRetval; + } + + void B3DPolyPolygon::removeDoublePoints() + { + if(hasDoublePoints()) { implForceUniqueCopy(); - mpPolyPolygon->transform(rMatrix); + mpPolyPolygon->removeDoublePoints(); } - } // end of namespace polygon + } + + void B3DPolyPolygon::transform(const ::basegfx::B3DHomMatrix& rMatrix) + { + implForceUniqueCopy(); + mpPolyPolygon->transform(rMatrix); + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b3dpolypolygontools.cxx b/basegfx/source/polygon/b3dpolypolygontools.cxx index 3b540b258653..4a4e5a3eab2e 100644 --- a/basegfx/source/polygon/b3dpolypolygontools.cxx +++ b/basegfx/source/polygon/b3dpolypolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b3dpolypolygontools.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: aw $ $Date: 2003-11-26 14:31:41 $ + * last change: $Author: aw $ $Date: 2003-11-28 11:18:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,26 +87,37 @@ namespace basegfx { - namespace polygon + namespace tools { - namespace tools + // B3DPolyPolygon tools + ::basegfx::B3DRange getRange(const ::basegfx::B3DPolyPolygon& rCandidate) { - // B3DPolyPolygon tools - ::basegfx::range::B3DRange getRange(const ::basegfx::polygon::B3DPolyPolygon& rCandidate) + ::basegfx::B3DRange aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); + + for(sal_uInt32 a(0L); a < nPolygonCount; a++) { - ::basegfx::range::B3DRange aRetval; - const sal_uInt32 nPolygonCount(rCandidate.count()); + ::basegfx::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); + aRetval.expand(::basegfx::tools::getRange(aCandidate)); + } + + return aRetval; + } - for(sal_uInt32 a(0L); a < nPolygonCount; a++) - { - ::basegfx::polygon::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); - aRetval.expand(::basegfx::polygon::tools::getRange(aCandidate)); - } + ::basegfx::B3DPolyPolygon applyLineDashing(const ::basegfx::B3DPolyPolygon& rCandidate, const ::std::vector<double>& raDashDotArray, double fFullDashDotLen) + { + ::basegfx::B3DPolyPolygon aRetval; + const sal_uInt32 nPolygonCount(rCandidate.count()); - return aRetval; + for(sal_uInt32 a(0L); a < nPolygonCount; a++) + { + ::basegfx::B3DPolygon aCandidate = rCandidate.getB3DPolygon(a); + aRetval.append(applyLineDashing(aCandidate, raDashDotArray, fFullDashDotLen)); } - } // end of namespace tools - } // end of namespace polygon + + return aRetval; + } + } // end of namespace tools } // end of namespace basegfx ////////////////////////////////////////////////////////////////////////////// |