diff options
Diffstat (limited to 'basegfx/source/polygon/b2dtrapezoid.cxx')
-rw-r--r-- | basegfx/source/polygon/b2dtrapezoid.cxx | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/basegfx/source/polygon/b2dtrapezoid.cxx b/basegfx/source/polygon/b2dtrapezoid.cxx index f095a6658119..5a626e9bdde6 100644 --- a/basegfx/source/polygon/b2dtrapezoid.cxx +++ b/basegfx/source/polygon/b2dtrapezoid.cxx @@ -2,7 +2,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite @@ -47,20 +47,20 @@ namespace basegfx // currently, thus the YPositions will be equal. I did not create a special // class for this since holdingthe pointers is more effective and also can be // used as baseclass for the traversing edges - + class TrDeSimpleEdge { protected: // pointers to start and end point - const B2DPoint* mpStart; - const B2DPoint* mpEnd; + const B2DPoint* mpStart; + const B2DPoint* mpEnd; public: // constructor TrDeSimpleEdge( const B2DPoint* pStart, const B2DPoint* pEnd) - : mpStart(pStart), + : mpStart(pStart), mpEnd(pEnd) { } @@ -76,7 +76,7 @@ namespace basegfx typedef ::std::vector< TrDeSimpleEdge > TrDeSimpleEdges; ////////////////////////////////////////////////////////////////////////////// - // helper class for holding a traversing edge. It will always have some + // helper class for holding a traversing edge. It will always have some // distance in YPos. The slope (in a numerically useful form, see comments) is // hold and used in SortValue to allow sorting traversing edges by Y, X and slope // (in that order) @@ -85,7 +85,7 @@ namespace basegfx { private: // the slope in a numerical useful form for sorting - sal_uInt32 mnSortValue; + sal_uInt32 mnSortValue; public: // convenience data read access @@ -105,7 +105,7 @@ namespace basegfx // convert to sal_uInt32 value const_cast< TrDeEdgeEntry* >(this)->mnSortValue = sal_uInt32(fRadiant); - + return mnSortValue; } @@ -114,7 +114,7 @@ namespace basegfx const B2DPoint* pStart, const B2DPoint* pEnd, sal_uInt32 nSortValue = 0) - : TrDeSimpleEdge(pStart, pEnd), + : TrDeSimpleEdge(pStart, pEnd), mnSortValue(nSortValue) { // force traversal of deltaY downward @@ -135,7 +135,7 @@ namespace basegfx if(mpStart != pNewStart) { mpStart = pNewStart; - + // no horizontal edges allowed, all neeed to traverse vertivally OSL_ENSURE(mpEnd->getY() > mpStart->getY(), "Illegal TrDeEdgeEntry constructed (!)"); } @@ -149,7 +149,7 @@ namespace basegfx if(mpEnd != pNewEnd) { mpEnd = pNewEnd; - + // no horizontal edges allowed, all neeed to traverse vertivally OSL_ENSURE(mpEnd->getY() > mpStart->getY(), "Illegal TrDeEdgeEntry constructed (!)"); } @@ -163,10 +163,10 @@ namespace basegfx if(fTools::equal(getStart().getX(), rComp.getStart().getX(), fTools::getSmallValue())) { // when start points are equal, use the direction the edge is pointing - // to. That value is created on demand and derived from atan2 in the + // to. That value is created on demand and derived from atan2 in the // range ]0.0 .. pi[ (without extremas, we always have a deltaY in this - // class) and scaled to sal_uInt32 range for best precision. 0 means no angle, - // while SAL_MAX_UINT32 means pi. Thus, the higher the value, the more left + // class) and scaled to sal_uInt32 range for best precision. 0 means no angle, + // while SAL_MAX_UINT32 means pi. Thus, the higher the value, the more left // the edge traverses. return (getSortValue() > rComp.getSortValue()); } @@ -184,11 +184,11 @@ namespace basegfx // method for cut support B2DPoint getCutPointForGivenY(double fGivenY) { - // Calculate cut point locally (do not use interpolate) since it is numerically + // Calculate cut point locally (do not use interpolate) since it is numerically // necessary to guarantee the new, equal Y-coordinate const double fFactor((fGivenY - getStart().getY()) / getDeltaY()); const double fDeltaXNew(fFactor * getDeltaX()); - + return B2DPoint(getStart().getX() + fDeltaXNew, fGivenY); } }; @@ -212,10 +212,10 @@ namespace basegfx { private: // local data - sal_uInt32 mnInitialEdgeEntryCount; - TrDeEdgeEntries maTrDeEdgeEntries; - ::std::vector< B2DPoint > maPoints; - ::std::vector< B2DPoint* > maNewPoints; + sal_uInt32 mnInitialEdgeEntryCount; + TrDeEdgeEntries maTrDeEdgeEntries; + ::std::vector< B2DPoint > maPoints; + ::std::vector< B2DPoint* > maNewPoints; void addEdgeSorted( TrDeEdgeEntries::iterator aCurrent, @@ -293,12 +293,12 @@ namespace basegfx { return false; } - + if(aEdgeA.getStart().equal(aEdgeB.getEnd(), fTools::getSmallValue())) { return false; } - + if(aEdgeA.getEnd().equal(aEdgeB.getStart(), fTools::getSmallValue())) { return false; @@ -379,7 +379,7 @@ namespace basegfx { delete pNewPoint; } - + return bRetval; } @@ -435,7 +435,7 @@ namespace basegfx { // cut is in XRange of horizontal edge, potenitally needed cut B2DPoint* pNewPoint = new B2DPoint(aSplit); - + if(splitEdgeAtGivenPoint(aCompare, *pNewPoint, aCurrent)) { maNewPoints.push_back(pNewPoint); @@ -456,7 +456,7 @@ namespace basegfx public: TrapezoidSubdivider( const B2DPolyPolygon& rSourcePolyPolygon) - : mnInitialEdgeEntryCount(0), + : mnInitialEdgeEntryCount(0), maTrDeEdgeEntries(), maPoints(), maNewPoints() @@ -507,8 +507,8 @@ namespace basegfx } // Moved the edge construction to a 3rd run: doing it in the 2nd run is - // possible(and i used it), but requires a working vector::reserve() - // implementation, else the vector will be reallocated and the pointers + // possible(and i used it), but requires a working vector::reserve() + // implementation, else the vector will be reallocated and the pointers // in the edges may be wrong. Security first here. sal_uInt32 nStartIndex(0); @@ -584,7 +584,7 @@ namespace basegfx // // There always must be two edges with the same YStart value: When adding the polygons // in the constructor, there is always a topmost point from which two edges start; when - // the topmost is an edge, there is a start and end of this edge from which two edges + // the topmost is an edge, there is a start and end of this edge from which two edges // start. All cases have two edges with same StartY (QED). // // Based on this these edges get corrected when: @@ -594,7 +594,7 @@ namespace basegfx // - another edge starts inside the thought trapezoid // // All this cases again produce a valid state so that the first two edges have a common - // Ystart again. Some cases lead to a restart of the process, some allow consuming the + // Ystart again. Some cases lead to a restart of the process, some allow consuming the // edges and create the intended trapezoid. // // Be careful when doing chages here: It is essential to keep all possible paths @@ -607,8 +607,8 @@ namespace basegfx { // measuring shows that the relation between edges and created trapezoids is // mostly in the 1:1 range, thus reserve as much trapezoids as edges exist. Do - // not use maTrDeEdgeEntries.size() since that may be a non-constant time - // operation for Lists. Instead, use mnInitialEdgeEntryCount which will contain + // not use maTrDeEdgeEntries.size() since that may be a non-constant time + // operation for Lists. Instead, use mnInitialEdgeEntryCount which will contain // the roughly counted adds to the List ro_Result.reserve(ro_Result.size() + mnInitialEdgeEntryCount); } @@ -635,9 +635,9 @@ namespace basegfx if(!fTools::equal(aLeft.getStart().getY(), aRight.getStart().getY(), fTools::getSmallValue())) { - // Should not happen: We have a 2nd edge, but YStart is on another + // Should not happen: We have a 2nd edge, but YStart is on another // line; consume the single edge to not have an endless loop and start - // next. During development i constantly had breakpoints here, so i am + // next. During development i constantly had breakpoints here, so i am // sure enough to add an assertion here OSL_ENSURE(false, "Trapeziod decomposer in illegal state (!)"); maTrDeEdgeEntries.pop_front(); @@ -647,7 +647,7 @@ namespace basegfx // aLeft and aRight build a thought trapezoid now. They have a common // start line (same Y for start points). Potentially, one of the edges // is longer than the other. It is only needed to look at the shorter - // length which build the potential trapezoid. To do so, get the end points + // length which build the potential trapezoid. To do so, get the end points // locally and adapt the evtl. longer one. Use only aLeftEnd and aRightEnd // from here on, not the aLeft.getEnd() or aRight.getEnd() accesses. B2DPoint aLeftEnd(aLeft.getEnd()); @@ -657,7 +657,7 @@ namespace basegfx // needs to be prepared. Also remember which one actually is longer. const bool bEndOnSameLine(fTools::equal(aLeftEnd.getY(), aRightEnd.getY(), fTools::getSmallValue())); bool bLeftIsLonger(false); - + if(!bEndOnSameLine) { // check which edge is longer and correct accordingly @@ -699,7 +699,7 @@ namespace basegfx else { B2DPoint* pNewPoint = new B2DPoint(aRightEnd); - + if(splitEdgeAtGivenPoint(aRight, *pNewPoint, aCurrent)) { maNewPoints.push_back(pNewPoint); @@ -714,10 +714,10 @@ namespace basegfx // consume both edges and start next run maTrDeEdgeEntries.pop_front(); maTrDeEdgeEntries.pop_front(); - + continue; } - + // check if the edges self-intersect. This can only happen when // start and end point are different bool bRangesSet(false); @@ -743,7 +743,7 @@ namespace basegfx // now we need to check if there are intersections with other edges // or if other edges start inside the candidate trapezoid - if(aCurrent != maTrDeEdgeEntries.end() + if(aCurrent != maTrDeEdgeEntries.end() && fTools::less(aCurrent->getStart().getY(), aLeftEnd.getY())) { // get XRanges of edges @@ -752,11 +752,11 @@ namespace basegfx aLeftRange = B1DRange(aLeft.getStart().getX(), aLeftEnd.getX()); aRightRange = B1DRange(aRight.getStart().getX(), aRightEnd.getX()); } - + // build full XRange for fast check B1DRange aAllRange(aLeftRange); aAllRange.expand(aRightRange); - + // prepare loop iterator; aCurrent needs to stay unchanged for // eventual sorted insertions of new EdgeNodes. Also prepare stop flag TrDeEdgeEntries::iterator aLoop(aCurrent); @@ -777,7 +777,7 @@ namespace basegfx // get compare XRange const B1DRange aCompareRange(aCompare.getStart().getX(), aCompare.getEnd().getX()); - + // use fast range test first if(aAllRange.overlaps(aCompareRange)) { @@ -790,12 +790,12 @@ namespace basegfx // check for start point of aCompare being inside thought // trapezoid - if(aCompare.getStart().getX() >= aSplitLeft.getX() && + if(aCompare.getStart().getX() >= aSplitLeft.getX() && aCompare.getStart().getX() <= aSplitRight.getX()) { // is inside, correct and restart loop B2DPoint* pNewLeft = new B2DPoint(aSplitLeft); - + if(splitEdgeAtGivenPoint(aLeft, *pNewLeft, aCurrent)) { maNewPoints.push_back(pNewLeft); @@ -805,9 +805,9 @@ namespace basegfx { delete pNewLeft; } - + B2DPoint* pNewRight = new B2DPoint(aSplitRight); - + if(splitEdgeAtGivenPoint(aRight, *pNewRight, aCurrent)) { maNewPoints.push_back(pNewRight); @@ -825,7 +825,7 @@ namespace basegfx // test for concrete cut of compare edge with left edge bDone = testAndCorrectEdgeIntersection(aLeft, aCompare, aCurrent); } - + if(!bDone && aRightRange.overlaps(aCompareRange)) { // test for concrete cut of compare edge with Right edge @@ -845,14 +845,14 @@ namespace basegfx } // when we get here, the intended trapezoid can be used. It needs to - // be corrected, eventually (if prepared); but this is no reason not to + // be corrected, eventually (if prepared); but this is no reason not to // use it in the same loop iteration if(!bEndOnSameLine) { if(bLeftIsLonger) { B2DPoint* pNewPoint = new B2DPoint(aLeftEnd); - + if(splitEdgeAtGivenPoint(aLeft, *pNewPoint, aCurrent)) { maNewPoints.push_back(pNewPoint); @@ -865,7 +865,7 @@ namespace basegfx else { B2DPoint* pNewPoint = new B2DPoint(aRightEnd); - + if(splitEdgeAtGivenPoint(aRight, *pNewPoint, aCurrent)) { maNewPoints.push_back(pNewPoint); @@ -888,7 +888,7 @@ namespace basegfx aLeftEnd.getX(), aRightEnd.getX(), aLeftEnd.getY())); - + maTrDeEdgeEntries.pop_front(); maTrDeEdgeEntries.pop_front(); } @@ -908,7 +908,7 @@ namespace basegfx const double& rfBottomXLeft, const double& rfBottomXRight, const double& rfBottomY) - : mfTopXLeft(rfTopXLeft), + : mfTopXLeft(rfTopXLeft), mfTopXRight(rfTopXRight), mfTopY(rfTopY), mfBottomXLeft(rfBottomXLeft), @@ -965,9 +965,9 @@ namespace basegfx } void createLineTrapezoidFromEdge( - B2DTrapezoidVector& ro_Result, - const B2DPoint& rPointA, - const B2DPoint& rPointB, + B2DTrapezoidVector& ro_Result, + const B2DPoint& rPointA, + const B2DPoint& rPointB, double fLineWidth) { if(fTools::lessOrEqual(fLineWidth, 0.0)) @@ -1037,14 +1037,14 @@ namespace basegfx aTrDeEdgeEntries.push_back(basegfx::trapezoidhelper::TrDeEdgeEntry(&aEndLow, &aStartLow, 0)); aTrDeEdgeEntries.sort(); - // here we know we have exactly four edges, and they do not cut, touch or + // here we know we have exactly four edges, and they do not cut, touch or // intersect. This makes processing much easier. Get the first two as start // edges for the thought trapezoid basegfx::trapezoidhelper::TrDeEdgeEntries::iterator aCurrent(aTrDeEdgeEntries.begin()); basegfx::trapezoidhelper::TrDeEdgeEntries::reference aLeft(*aCurrent++); basegfx::trapezoidhelper::TrDeEdgeEntries::reference aRight(*aCurrent++); const bool bEndOnSameLine(fTools::equal(aLeft.getEnd().getY(), aRight.getEnd().getY(), fTools::getSmallValue())); - + if(bEndOnSameLine) { // create two triangle trapezoids @@ -1071,7 +1071,7 @@ namespace basegfx } else { - // create three trapezoids. Check which edge is longer and + // create three trapezoids. Check which edge is longer and // correct accordingly const bool bLeftIsLonger(fTools::more(aLeft.getEnd().getY(), aRight.getEnd().getY())); @@ -1081,7 +1081,7 @@ namespace basegfx basegfx::trapezoidhelper::TrDeEdgeEntries::reference aLeft2(*aCurrent++); const B2DPoint aSplitLeft(aLeft.getCutPointForGivenY(aRight.getEnd().getY())); const B2DPoint aSplitRight(aRight2.getCutPointForGivenY(aLeft.getEnd().getY())); - + ro_Result.push_back( B2DTrapezoid( aLeft.getStart().getX(), @@ -1090,7 +1090,7 @@ namespace basegfx aSplitLeft.getX(), aRight.getEnd().getX(), aRight.getEnd().getY())); - + ro_Result.push_back( B2DTrapezoid( aSplitLeft.getX(), @@ -1099,7 +1099,7 @@ namespace basegfx aLeft2.getStart().getX(), aSplitRight.getX(), aLeft2.getStart().getY())); - + ro_Result.push_back( B2DTrapezoid( aLeft2.getStart().getX(), @@ -1148,7 +1148,7 @@ namespace basegfx } void createLineTrapezoidFromB2DPolygon( - B2DTrapezoidVector& ro_Result, + B2DTrapezoidVector& ro_Result, const B2DPolygon& rPolygon, double fLineWidth) { @@ -1167,7 +1167,7 @@ namespace basegfx } const sal_uInt32 nPointCount(aSource.count()); - + if(!nPointCount) { return; @@ -1182,14 +1182,14 @@ namespace basegfx { const sal_uInt32 nNextIndex((a + 1) % nPointCount); const B2DPoint aNext(aSource.getB2DPoint(nNextIndex)); - + createLineTrapezoidFromEdge(ro_Result, aCurrent, aNext, fLineWidth); aCurrent = aNext; } } void createLineTrapezoidFromB2DPolyPolygon( - B2DTrapezoidVector& ro_Result, + B2DTrapezoidVector& ro_Result, const B2DPolyPolygon& rPolyPolygon, double fLineWidth) { @@ -1207,7 +1207,7 @@ namespace basegfx } const sal_uInt32 nCount(aSource.count()); - + if(!nCount) { return; @@ -1216,7 +1216,7 @@ namespace basegfx for(sal_uInt32 a(0); a < nCount; a++) { createLineTrapezoidFromB2DPolygon( - ro_Result, + ro_Result, aSource.getB2DPolygon(a), fLineWidth); } |