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 | |
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')
-rw-r--r-- | basegfx/inc/basegfx/curve/b2dcubicbezier.hxx | 10 | ||||
-rw-r--r-- | basegfx/inc/basegfx/polygon/b2dpolygon.hxx | 13 | ||||
-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 |
5 files changed, 109 insertions, 32 deletions
diff --git a/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx b/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx index dd23a841d51a..85f80d5009b2 100644 --- a/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx +++ b/basegfx/inc/basegfx/curve/b2dcubicbezier.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dcubicbezier.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2004-01-16 10:33:48 $ + * last change: $Author: aw $ $Date: 2004-02-12 17:11:41 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -98,6 +98,12 @@ namespace basegfx // test if contained bezier is trivial and reset vectors accordingly void testAndSolveTrivialBezier(); + // get distance between start and end point + double getEdgeLength() const; + + // get length of control polygon + double getControlPolygonLength() const; + // data interface ::basegfx::B2DPoint getStartPoint() const { return maStartPoint; } void setStartPoint(const ::basegfx::B2DPoint& rValue) { maStartPoint = rValue; } diff --git a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx index 8bc81e641f09..cd5cb71a2511 100644 --- a/basegfx/inc/basegfx/polygon/b2dpolygon.hxx +++ b/basegfx/inc/basegfx/polygon/b2dpolygon.hxx @@ -2,9 +2,9 @@ * * $RCSfile: b2dpolygon.hxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: thb $ $Date: 2004-01-16 10:33:58 $ + * 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 @@ -121,7 +121,14 @@ namespace basegfx void setControlVectorA(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue); ::basegfx::B2DVector getControlVectorB(sal_uInt32 nIndex) const; void setControlVectorB(sal_uInt32 nIndex, const ::basegfx::B2DVector& rValue); - bool areControlPointsUsed() const; + bool areControlVectorsUsed() const; + + // ControlPoint interface + ::basegfx::B2DPoint getControlPointA(sal_uInt32 nIndex) const; + void setControlPointA(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue); + ::basegfx::B2DPoint getControlPointB(sal_uInt32 nIndex) const; + void setControlPointB(sal_uInt32 nIndex, const ::basegfx::B2DPoint& rValue); + bool areControlPointsUsed() const { return areControlVectorsUsed(); } // insert/append other 2D polygons void insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2 = 0, sal_uInt32 nCount = 0); 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); } } } |