diff options
author | Armin Weiss <aw@openoffice.org> | 2004-02-12 16:11:42 +0000 |
---|---|---|
committer | Armin Weiss <aw@openoffice.org> | 2004-02-12 16:11:42 +0000 |
commit | b23dfd18d71d77164ae51be108de09f3ed00f7a7 (patch) | |
tree | d3ea51cafc59d781440215e88d7b4c13d1d950b2 /basegfx/source | |
parent | 634b32e4ea0c9da79e7c6c4eafc023ce0c5dfa6f (diff) |
Changed usages of (G/S)etControlVector(A/B) to use the new curve convention that both vectors are relative to the point of the edge. Before, B was relative to the next edge.
Also added (G/S)etControlPoint(A/B) interface for B2DPolygon.
Diffstat (limited to 'basegfx/source')
-rw-r--r-- | basegfx/source/curve/b2dcubicbezier.cxx | 22 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolygon.cxx | 70 | ||||
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 26 |
3 files changed, 91 insertions, 27 deletions
diff --git a/basegfx/source/curve/b2dcubicbezier.cxx b/basegfx/source/curve/b2dcubicbezier.cxx index 7ff14e13601b..ff6430d7fa13 100644 --- a/basegfx/source/curve/b2dcubicbezier.cxx +++ b/basegfx/source/curve/b2dcubicbezier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dcubicbezier.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: thb $ $Date: 2004-01-16 10:34:19 $ + * last change: $Author: aw $ $Date: 2004-02-12 17:11:42 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -63,6 +63,10 @@ #include <basegfx/curve/b2dcubicbezier.hxx> #endif +#ifndef _BGFX_VECTOR_B2DVECTOR_HXX +#include <basegfx/vector/b2dvector.hxx> +#endif + ////////////////////////////////////////////////////////////////////////////// namespace basegfx @@ -147,6 +151,20 @@ namespace basegfx { // TODO } + + double B2DCubicBezier::getEdgeLength() const + { + ::basegfx::B2DVector aEdge(maEndPoint - maStartPoint); + return aEdge.getLength(); + } + + double B2DCubicBezier::getControlPolygonLength() const + { + ::basegfx::B2DVector aVectorA(maControlPointA - maStartPoint); + ::basegfx::B2DVector aVectorB(maEndPoint - maControlPointB); + ::basegfx::B2DVector aTop(maControlPointB - maControlPointA); + return (aVectorA.getLength() + aVectorB.getLength() + aTop.getLength()); + } } // end of namespace basegfx // eof diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index 0c2c921dd64a..381e5b75d5ea 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygon.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: thb $ $Date: 2004-01-16 10:34:32 $ + * last change: $Author: aw $ $Date: 2004-02-12 17:11:42 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -660,11 +660,6 @@ public: } } - bool areControlPointsUsed() const - { - return (mpControlVector && mpControlVector->isUsed()); - } - const ::basegfx::B2DVector& getControlVectorB(sal_uInt32 nIndex) const { if(mpControlVector) @@ -699,6 +694,11 @@ public: } } + bool areControlVectorsUsed() const + { + return (mpControlVector && mpControlVector->isUsed()); + } + void insert(sal_uInt32 nIndex, const ImplB2DPolygon& rSource) { const sal_uInt32 nCount(rSource.maPoints.count()); @@ -1144,9 +1144,61 @@ namespace basegfx } } - bool B2DPolygon::areControlPointsUsed() const + bool B2DPolygon::areControlVectorsUsed() const + { + return mpPolygon->areControlVectorsUsed(); + } + + ::basegfx::B2DPoint B2DPolygon::getControlPointA(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->areControlVectorsUsed()) + { + return mpPolygon->getPoint(nIndex) + mpPolygon->getControlVectorA(nIndex); + } + else + { + return mpPolygon->getPoint(nIndex); + } + } + + void B2DPolygon::setControlPointA(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector aNewVector(rValue - mpPolygon->getPoint(nIndex)); + + if(mpPolygon->getControlVectorA(nIndex) != aNewVector) + { + implForceUniqueCopy(); + mpPolygon->setControlVectorA(nIndex, aNewVector); + } + } + + ::basegfx::B2DPoint B2DPolygon::getControlPointB(sal_uInt32 nIndex) const + { + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->areControlVectorsUsed()) + { + return mpPolygon->getPoint(nIndex) + mpPolygon->getControlVectorB(nIndex); + } + else + { + return mpPolygon->getPoint(nIndex); + } + } + + void B2DPolygon::setControlPointB(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue) { - return mpPolygon->areControlPointsUsed(); + OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + ::basegfx::B2DVector aNewVector(rValue - mpPolygon->getPoint(nIndex)); + + if(mpPolygon->getControlVectorB(nIndex) != aNewVector) + { + implForceUniqueCopy(); + mpPolygon->setControlVectorB(nIndex, aNewVector); + } } void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index 4deefd85f184..f6841306f850 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygontools.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: aw $ $Date: 2004-02-03 18:18:22 $ + * last change: $Author: aw $ $Date: 2004-02-12 17:11:42 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -234,9 +234,9 @@ namespace basegfx if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed()) { - sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); + const sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate)); const B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex)); - const B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd)); + const B2DVector aBackVector(rCandidate.getControlPointB(nPrevInd) - rCandidate.getB2DPoint(nIndex)); eRetval = getContinuity(aBackVector, aForwardVector); } @@ -267,20 +267,16 @@ namespace basegfx // build CubicBezier segment B2DCubicBezier aBezier( - aPointA, B2DPoint(aPointA + aVectorA), B2DPoint(aPointB + aVectorB), aPointB); + aPointA, B2DPoint(aPointA + aVectorA), B2DPoint(aPointA + aVectorB), aPointB); // generate DistanceBound double 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 - B2DVector aSimpleDistance(aPointB - aPointA); - B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA)); - const double fRoughLength( - (aSimpleDistance.getLength() - + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0); + // If not set, use B2DCubicBezier functionality to guess a rough + // value + const double fRoughLength((aBezier.getEdgeLength() + aBezier.getControlPolygonLength()) / 2.0); // take 1/100th of the rouch curve length fBound = fRoughLength * 0.01; @@ -341,7 +337,7 @@ namespace basegfx // build CubicBezier segment B2DCubicBezier aBezier( - aPointA, B2DPoint(aPointA + aVectorA), B2DPoint(aPointB + aVectorB), aPointB); + aPointA, B2DPoint(aPointA + aVectorA), B2DPoint(aPointA + aVectorB), aPointB); // generate AngleBound double fBound(fAngleBound); @@ -463,9 +459,7 @@ namespace basegfx if(!aVectorB.equalZero()) { - const sal_uInt32 nNextIndex(getIndexOfSuccessor(a, rCandidate)); - const B2DPoint aNextPoint(rCandidate.getB2DPoint(nNextIndex)); - aRetval.expand(aNextPoint + aVectorB); + aRetval.expand(aTestPoint + aVectorB); } } } |