From 3e659f82dedbb5ddeb2814ce5267445234f7e7fd Mon Sep 17 00:00:00 2001 From: Armin Le Grand Date: Tue, 8 Dec 2009 19:04:39 +0100 Subject: aw079: #i107360# numerical precision --- basegfx/source/polygon/b2dpolygoncutandtouch.cxx | 90 ++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'basegfx/source/polygon/b2dpolygoncutandtouch.cxx') diff --git a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx index da6ff8904725..ebc0ad418f4b 100644 --- a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx +++ b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx @@ -1202,6 +1202,96 @@ namespace basegfx return aRetval; } + B2DPolygon addPointsAtCuts(const B2DPolygon& rCandidate) + { + if(rCandidate.count()) + { + temporaryPointVector aTempPoints; + + findCuts(rCandidate, aTempPoints); + + return mergeTemporaryPointsAndPolygon(rCandidate, aTempPoints); + } + else + { + return rCandidate; + } + } + + B2DPolyPolygon addPointsAtCuts(const B2DPolyPolygon& rCandidate, bool bSelfIntersections) + { + const sal_uInt32 nCount(rCandidate.count()); + + if(nCount) + { + B2DPolyPolygon aRetval; + + if(1 == nCount) + { + if(bSelfIntersections) + { + // remove self intersections + aRetval.append(addPointsAtCuts(rCandidate.getB2DPolygon(0))); + } + else + { + // copy source + aRetval = rCandidate; + } + } + else + { + // first solve self cuts for all contained single polygons + temporaryPolygonData *pTempData = new temporaryPolygonData[nCount]; + sal_uInt32 a, b; + + for(a = 0; a < nCount; a++) + { + if(bSelfIntersections) + { + // use polygons with solved self intersections + pTempData[a].setPolygon(addPointsAtCuts(rCandidate.getB2DPolygon(a))); + } + else + { + // copy given polygons + pTempData[a].setPolygon(rCandidate.getB2DPolygon(a)); + } + } + + // now cuts and touches between the polygons + for(a = 0; a < nCount; a++) + { + for(b = 0; b < nCount; b++) + { + if(a < b) + { + // look for cuts, compare each edge polygon to following ones + if(pTempData[a].getRange().overlaps(pTempData[b].getRange())) + { + findCuts(pTempData[a].getPolygon(), pTempData[b].getPolygon(), pTempData[a].getTemporaryPointVector(), pTempData[b].getTemporaryPointVector()); + } + } + } + } + + // consolidate the result + for(a = 0L; a < nCount; a++) + { + aRetval.append(mergeTemporaryPointsAndPolygon(pTempData[a].getPolygon(), pTempData[a].getTemporaryPointVector())); + } + + delete[] pTempData; + } + + return aRetval; + } + else + { + return rCandidate; + } + } + //////////////////////////////////////////////////////////////////////////////// } // end of namespace tools -- cgit