diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-01-27 14:29:20 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-01-27 14:38:39 +0000 |
commit | ec7c8f4ed1893711313221dd5fc46b6b37433df9 (patch) | |
tree | 8bf0604052c2b7ba02098d65373fbb2493bc031e /basegfx | |
parent | 8cccfb8f8f793ebae4c2d5feb2674b1b2c976d9f (diff) |
nPointCount test inside nPointCount test
Change-Id: I4a78683cedd04d3daef52105d44638e3fc87d3c2
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 215 |
1 files changed, 106 insertions, 109 deletions
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index 1ab9d807bacc..a931edf41638 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -3546,145 +3546,142 @@ namespace basegfx const bool bCurve(rPolygon.areControlPointsUsed()); const bool bClosed(rPolygon.isClosed()); - if(nPointCount) + if(bCurve) { - if(bCurve) + // calculate target point count + const sal_uInt32 nLoopCount(bClosed ? nPointCount : nPointCount - 1); + + if(nLoopCount) { - // calculate target point count - const sal_uInt32 nLoopCount(bClosed ? nPointCount : nPointCount - 1); + // prepare target data. The real needed number of target points (and flags) + // could only be calculated by using two loops, so use dynamic memory + std::vector< com::sun::star::awt::Point > aCollectPoints; + std::vector< com::sun::star::drawing::PolygonFlags > aCollectFlags; - if(nLoopCount) - { - // prepare target data. The real needed number of target points (and flags) - // could only be calculated by using two loops, so use dynamic memory - std::vector< com::sun::star::awt::Point > aCollectPoints; - std::vector< com::sun::star::drawing::PolygonFlags > aCollectFlags; + // reserve maximum creatable points + const sal_uInt32 nMaxTargetCount((nLoopCount * 3) + 1); + aCollectPoints.reserve(nMaxTargetCount); + aCollectFlags.reserve(nMaxTargetCount); - // reserve maximum creatable points - const sal_uInt32 nMaxTargetCount((nLoopCount * 3) + 1); - aCollectPoints.reserve(nMaxTargetCount); - aCollectFlags.reserve(nMaxTargetCount); + // prepare current bezier segment by setting start point + B2DCubicBezier aBezierSegment; + aBezierSegment.setStartPoint(rPolygon.getB2DPoint(0)); - // prepare current bezier segment by setting start point - B2DCubicBezier aBezierSegment; - aBezierSegment.setStartPoint(rPolygon.getB2DPoint(0)); + for(sal_uInt32 a(0); a < nLoopCount; a++) + { + // add current point (always) and remember StartPointIndex for evtl. later corrections + const sal_uInt32 nStartPointIndex(aCollectPoints.size()); + aCollectPoints.push_back( + com::sun::star::awt::Point( + fround(aBezierSegment.getStartPoint().getX()), + fround(aBezierSegment.getStartPoint().getY()))); + aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); + + // prepare next segment + const sal_uInt32 nNextIndex((a + 1) % nPointCount); + aBezierSegment.setEndPoint(rPolygon.getB2DPoint(nNextIndex)); + aBezierSegment.setControlPointA(rPolygon.getNextControlPoint(a)); + aBezierSegment.setControlPointB(rPolygon.getPrevControlPoint(nNextIndex)); - for(sal_uInt32 a(0); a < nLoopCount; a++) + if(aBezierSegment.isBezier()) { - // add current point (always) and remember StartPointIndex for evtl. later corrections - const sal_uInt32 nStartPointIndex(aCollectPoints.size()); + // if bezier is used, add always two control points due to the old schema aCollectPoints.push_back( com::sun::star::awt::Point( - fround(aBezierSegment.getStartPoint().getX()), - fround(aBezierSegment.getStartPoint().getY()))); - aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); + fround(aBezierSegment.getControlPointA().getX()), + fround(aBezierSegment.getControlPointA().getY()))); + aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_CONTROL); - // prepare next segment - const sal_uInt32 nNextIndex((a + 1) % nPointCount); - aBezierSegment.setEndPoint(rPolygon.getB2DPoint(nNextIndex)); - aBezierSegment.setControlPointA(rPolygon.getNextControlPoint(a)); - aBezierSegment.setControlPointB(rPolygon.getPrevControlPoint(nNextIndex)); + aCollectPoints.push_back( + com::sun::star::awt::Point( + fround(aBezierSegment.getControlPointB().getX()), + fround(aBezierSegment.getControlPointB().getY()))); + aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_CONTROL); + } - if(aBezierSegment.isBezier()) + // test continuity with previous control point to set flag value + if(aBezierSegment.getControlPointA() != aBezierSegment.getStartPoint() && (bClosed || a)) + { + const B2VectorContinuity eCont(rPolygon.getContinuityInPoint(a)); + + if(CONTINUITY_C1 == eCont) { - // if bezier is used, add always two control points due to the old schema - aCollectPoints.push_back( - com::sun::star::awt::Point( - fround(aBezierSegment.getControlPointA().getX()), - fround(aBezierSegment.getControlPointA().getY()))); - aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_CONTROL); - - aCollectPoints.push_back( - com::sun::star::awt::Point( - fround(aBezierSegment.getControlPointB().getX()), - fround(aBezierSegment.getControlPointB().getY()))); - aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_CONTROL); + aCollectFlags[nStartPointIndex] = com::sun::star::drawing::PolygonFlags_SMOOTH; } - - // test continuity with previous control point to set flag value - if(aBezierSegment.getControlPointA() != aBezierSegment.getStartPoint() && (bClosed || a)) + else if(CONTINUITY_C2 == eCont) { - const B2VectorContinuity eCont(rPolygon.getContinuityInPoint(a)); - - if(CONTINUITY_C1 == eCont) - { - aCollectFlags[nStartPointIndex] = com::sun::star::drawing::PolygonFlags_SMOOTH; - } - else if(CONTINUITY_C2 == eCont) - { - aCollectFlags[nStartPointIndex] = com::sun::star::drawing::PolygonFlags_SYMMETRIC; - } + aCollectFlags[nStartPointIndex] = com::sun::star::drawing::PolygonFlags_SYMMETRIC; } - - // prepare next loop - aBezierSegment.setStartPoint(aBezierSegment.getEndPoint()); - } - - if(bClosed) - { - // add first point again as closing point due to old definition - aCollectPoints.push_back(aCollectPoints[0]); - aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); } - else - { - // add last point as closing point - const B2DPoint aClosingPoint(rPolygon.getB2DPoint(nPointCount - 1L)); - aCollectPoints.push_back( - com::sun::star::awt::Point( - fround(aClosingPoint.getX()), - fround(aClosingPoint.getY()))); - aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); - } - - // copy collected data to target arrays - const sal_uInt32 nTargetCount(aCollectPoints.size()); - OSL_ENSURE(nTargetCount == aCollectFlags.size(), "Unequal Point and Flag count (!)"); - rPointSequenceRetval.realloc((sal_Int32)nTargetCount); - rFlagSequenceRetval.realloc((sal_Int32)nTargetCount); - com::sun::star::awt::Point* pPointSequence = rPointSequenceRetval.getArray(); - com::sun::star::drawing::PolygonFlags* pFlagSequence = rFlagSequenceRetval.getArray(); + // prepare next loop + aBezierSegment.setStartPoint(aBezierSegment.getEndPoint()); + } - for(sal_uInt32 a(0); a < nTargetCount; a++) - { - *pPointSequence = aCollectPoints[a]; - *pFlagSequence = aCollectFlags[a]; - pPointSequence++; - pFlagSequence++; - } + if(bClosed) + { + // add first point again as closing point due to old definition + aCollectPoints.push_back(aCollectPoints[0]); + aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); + } + else + { + // add last point as closing point + const B2DPoint aClosingPoint(rPolygon.getB2DPoint(nPointCount - 1L)); + aCollectPoints.push_back( + com::sun::star::awt::Point( + fround(aClosingPoint.getX()), + fround(aClosingPoint.getY()))); + aCollectFlags.push_back(com::sun::star::drawing::PolygonFlags_NORMAL); } - } - else - { - // straightforward point list creation - const sal_uInt32 nTargetCount(nPointCount + (bClosed ? 1 : 0)); + + // copy collected data to target arrays + const sal_uInt32 nTargetCount(aCollectPoints.size()); + OSL_ENSURE(nTargetCount == aCollectFlags.size(), "Unequal Point and Flag count (!)"); rPointSequenceRetval.realloc((sal_Int32)nTargetCount); rFlagSequenceRetval.realloc((sal_Int32)nTargetCount); - com::sun::star::awt::Point* pPointSequence = rPointSequenceRetval.getArray(); com::sun::star::drawing::PolygonFlags* pFlagSequence = rFlagSequenceRetval.getArray(); - for(sal_uInt32 a(0); a < nPointCount; a++) + for(sal_uInt32 a(0); a < nTargetCount; a++) { - const B2DPoint aB2DPoint(rPolygon.getB2DPoint(a)); - const com::sun::star::awt::Point aAPIPoint( - fround(aB2DPoint.getX()), - fround(aB2DPoint.getY())); - - *pPointSequence = aAPIPoint; - *pFlagSequence = com::sun::star::drawing::PolygonFlags_NORMAL; + *pPointSequence = aCollectPoints[a]; + *pFlagSequence = aCollectFlags[a]; pPointSequence++; pFlagSequence++; } + } + } + else + { + // straightforward point list creation + const sal_uInt32 nTargetCount(nPointCount + (bClosed ? 1 : 0)); - if(bClosed) - { - // add first point as closing point - *pPointSequence = *rPointSequenceRetval.getConstArray(); - *pFlagSequence = com::sun::star::drawing::PolygonFlags_NORMAL; - } + rPointSequenceRetval.realloc((sal_Int32)nTargetCount); + rFlagSequenceRetval.realloc((sal_Int32)nTargetCount); + + com::sun::star::awt::Point* pPointSequence = rPointSequenceRetval.getArray(); + com::sun::star::drawing::PolygonFlags* pFlagSequence = rFlagSequenceRetval.getArray(); + + for(sal_uInt32 a(0); a < nPointCount; a++) + { + const B2DPoint aB2DPoint(rPolygon.getB2DPoint(a)); + const com::sun::star::awt::Point aAPIPoint( + fround(aB2DPoint.getX()), + fround(aB2DPoint.getY())); + + *pPointSequence = aAPIPoint; + *pFlagSequence = com::sun::star::drawing::PolygonFlags_NORMAL; + pPointSequence++; + pFlagSequence++; + } + + if(bClosed) + { + // add first point as closing point + *pPointSequence = *rPointSequenceRetval.getConstArray(); + *pFlagSequence = com::sun::star::drawing::PolygonFlags_NORMAL; } } } |