From c17a26a1df43233008981c7aebd4f504a6b532ff Mon Sep 17 00:00:00 2001 From: Armin Weiss Date: Tue, 20 Oct 2009 15:36:14 +0000 Subject: #i105065# speedup 3D/FontWork --- basegfx/source/polygon/b3dpolygontools.cxx | 167 ++++++++++++++++++++++------- 1 file changed, 131 insertions(+), 36 deletions(-) (limited to 'basegfx') diff --git a/basegfx/source/polygon/b3dpolygontools.cxx b/basegfx/source/polygon/b3dpolygontools.cxx index ea303886dd88..52e0f0fcc36f 100644 --- a/basegfx/source/polygon/b3dpolygontools.cxx +++ b/basegfx/source/polygon/b3dpolygontools.cxx @@ -875,52 +875,147 @@ namespace basegfx } else { + bool bRetval(false); const B3DVector aPlaneNormal(rCandidate.getNormal()); if(!aPlaneNormal.equalZero()) { - const double fAbsX(fabs(aPlaneNormal.getX())); - const double fAbsY(fabs(aPlaneNormal.getY())); - const double fAbsZ(fabs(aPlaneNormal.getZ())); + const sal_uInt32 nPointCount(rCandidate.count()); - if(fAbsX > fAbsY && fAbsX > fAbsZ) + if(nPointCount) { - // normal points mostly in X-Direction, use YZ-Polygon projection for check - B3DHomMatrix aTrans; + B3DPoint aCurrentPoint(rCandidate.getB3DPoint(nPointCount - 1)); + const double fAbsX(fabs(aPlaneNormal.getX())); + const double fAbsY(fabs(aPlaneNormal.getY())); + const double fAbsZ(fabs(aPlaneNormal.getZ())); - aTrans.set(0, 0, 0.0); - aTrans.set(0, 1, 1.0); - aTrans.set(1, 1, 0.0); - aTrans.set(1, 2, 1.0); - - const B2DPolygon aYZ(createB2DPolygonFromB3DPolygon(rCandidate, aTrans)); - - return isInside(aYZ, B2DPoint(rPoint.getY(), rPoint.getZ()), bWithBorder); - } - else if(fAbsY > fAbsX && fAbsY > fAbsZ) - { - // normal points mostly in Y-Direction, use XZ-Polygon projection for check - B3DHomMatrix aTrans; - - aTrans.set(1, 1, 0.0); - aTrans.set(1, 2, 1.0); - - const B2DPolygon aXZ(createB2DPolygonFromB3DPolygon(rCandidate, aTrans)); - - return isInside(aXZ, B2DPoint(rPoint.getX(), rPoint.getZ()), bWithBorder); - } - else - { - // normal points mostly in Z-Direction, use XY-Polygon projection for check - B3DHomMatrix aTrans; - - const B2DPolygon aXY(createB2DPolygonFromB3DPolygon(rCandidate, aTrans)); - - return isInside(aXY, B2DPoint(rPoint.getX(), rPoint.getY()), bWithBorder); + if(fAbsX > fAbsY && fAbsX > fAbsZ) + { + // normal points mostly in X-Direction, use YZ-Polygon projection for check + // x -> y, y -> z + for(sal_uInt32 a(0); a < nPointCount; a++) + { + const B3DPoint aPreviousPoint(aCurrentPoint); + aCurrentPoint = rCandidate.getB3DPoint(a); + + // cross-over in Z? + const bool bCompZA(fTools::more(aPreviousPoint.getZ(), rPoint.getZ())); + const bool bCompZB(fTools::more(aCurrentPoint.getZ(), rPoint.getZ())); + + if(bCompZA != bCompZB) + { + // cross-over in Y? + const bool bCompYA(fTools::more(aPreviousPoint.getY(), rPoint.getY())); + const bool bCompYB(fTools::more(aCurrentPoint.getY(), rPoint.getY())); + + if(bCompYA == bCompYB) + { + if(bCompYA) + { + bRetval = !bRetval; + } + } + else + { + const double fCompare( + aCurrentPoint.getY() - (aCurrentPoint.getZ() - rPoint.getZ()) * + (aPreviousPoint.getY() - aCurrentPoint.getY()) / + (aPreviousPoint.getZ() - aCurrentPoint.getZ())); + + if(fTools::more(fCompare, rPoint.getY())) + { + bRetval = !bRetval; + } + } + } + } + } + else if(fAbsY > fAbsX && fAbsY > fAbsZ) + { + // normal points mostly in Y-Direction, use XZ-Polygon projection for check + // x -> x, y -> z + for(sal_uInt32 a(0); a < nPointCount; a++) + { + const B3DPoint aPreviousPoint(aCurrentPoint); + aCurrentPoint = rCandidate.getB3DPoint(a); + + // cross-over in Z? + const bool bCompZA(fTools::more(aPreviousPoint.getZ(), rPoint.getZ())); + const bool bCompZB(fTools::more(aCurrentPoint.getZ(), rPoint.getZ())); + + if(bCompZA != bCompZB) + { + // cross-over in X? + const bool bCompXA(fTools::more(aPreviousPoint.getX(), rPoint.getX())); + const bool bCompXB(fTools::more(aCurrentPoint.getX(), rPoint.getX())); + + if(bCompXA == bCompXB) + { + if(bCompXA) + { + bRetval = !bRetval; + } + } + else + { + const double fCompare( + aCurrentPoint.getX() - (aCurrentPoint.getZ() - rPoint.getZ()) * + (aPreviousPoint.getX() - aCurrentPoint.getX()) / + (aPreviousPoint.getZ() - aCurrentPoint.getZ())); + + if(fTools::more(fCompare, rPoint.getX())) + { + bRetval = !bRetval; + } + } + } + } + } + else + { + // normal points mostly in Z-Direction, use XY-Polygon projection for check + // x -> x, y -> y + for(sal_uInt32 a(0); a < nPointCount; a++) + { + const B3DPoint aPreviousPoint(aCurrentPoint); + aCurrentPoint = rCandidate.getB3DPoint(a); + + // cross-over in Y? + const bool bCompYA(fTools::more(aPreviousPoint.getY(), rPoint.getY())); + const bool bCompYB(fTools::more(aCurrentPoint.getY(), rPoint.getY())); + + if(bCompYA != bCompYB) + { + // cross-over in X? + const bool bCompXA(fTools::more(aPreviousPoint.getX(), rPoint.getX())); + const bool bCompXB(fTools::more(aCurrentPoint.getX(), rPoint.getX())); + + if(bCompXA == bCompXB) + { + if(bCompXA) + { + bRetval = !bRetval; + } + } + else + { + const double fCompare( + aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * + (aPreviousPoint.getX() - aCurrentPoint.getX()) / + (aPreviousPoint.getY() - aCurrentPoint.getY())); + + if(fTools::more(fCompare, rPoint.getX())) + { + bRetval = !bRetval; + } + } + } + } + } } } - return false; + return bRetval; } } -- cgit v1.2.3