diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2006-11-14 13:08:08 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2006-11-14 13:08:08 +0000 |
commit | 4fbd95d4f2a24e83e46f1b8a0a9f3fd8a05124de (patch) | |
tree | 2c9e22f2b0cba0e913f5fb788666edb2b0fbd8c1 /basegfx/source/polygon/b2dpolygontools.cxx | |
parent | 0118acc1674bbc23bae13668fdc2a70d43408629 (diff) |
INTEGRATION: CWS aw024 (1.16.2); FILE MERGED
2006/11/01 10:06:13 aw 1.16.2.15: #i67360# corrected isInside to work correctly when bWithBorder==true with horizontal touches. Added a solo isPointOnPolygon test for that
2006/09/21 21:00:57 aw 1.16.2.14: RESYNC: (1.22-1.23); FILE MERGED
2006/07/04 13:48:54 aw 1.16.2.13: RESYNC: (1.21-1.22); FILE MERGED
2005/11/18 18:59:05 aw 1.16.2.12: RESYNC: (1.20-1.21); FILE MERGED
2005/09/19 21:48:43 aw 1.16.2.11: RESYNC: (1.19-1.20); FILE MERGED
2005/07/28 14:49:17 aw 1.16.2.10: #114176#
2005/07/21 15:49:49 aw 1.16.2.9: #114176#
2005/07/13 11:11:13 aw 1.16.2.8: #114176#
2005/06/03 11:53:19 aw 1.16.2.7: #i39532#
2005/05/13 16:31:23 aw 1.16.2.6: RESYNC: (1.18-1.19); FILE MERGED
2005/05/13 12:17:31 aw 1.16.2.5: #i39529#
2005/05/12 16:35:15 aw 1.16.2.4: #i39529#
2005/04/26 14:48:49 aw 1.16.2.3: #i39528#
2005/03/24 01:11:36 aw 1.16.2.2: RESYNC: (1.16-1.18); FILE MERGED
2005/02/02 20:59:51 aw 1.16.2.1: #i39528#
Diffstat (limited to 'basegfx/source/polygon/b2dpolygontools.cxx')
-rw-r--r-- | basegfx/source/polygon/b2dpolygontools.cxx | 119 |
1 files changed, 71 insertions, 48 deletions
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx index 3d715197e57d..0dfcf9f49431 100644 --- a/basegfx/source/polygon/b2dpolygontools.cxx +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -4,9 +4,9 @@ * * $RCSfile: b2dpolygontools.cxx,v $ * - * $Revision: 1.23 $ + * $Revision: 1.24 $ * - * last change: $Author: obo $ $Date: 2006-09-17 08:02:00 $ + * last change: $Author: ihi $ $Date: 2006-11-14 14:08:08 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -436,67 +436,60 @@ namespace basegfx bool isInside(const B2DPolygon& rCandidate, const B2DPoint& rPoint, bool bWithBorder) { const B2DPolygon aCandidate(rCandidate.areControlPointsUsed() ? adaptiveSubdivideByCount(rCandidate, 6L) : rCandidate); - bool bRetval(false); - const sal_uInt32 nPointCount(aCandidate.count()); - for(sal_uInt32 a(0L); a < nPointCount; a++) + if(bWithBorder && isPointOnPolygon(aCandidate, rPoint, true)) { - const B2DPoint aCurrentPoint(aCandidate.getB2DPoint(a)); + return true; + } + else + { + bool bRetval(false); + const sal_uInt32 nPointCount(aCandidate.count()); - if(bWithBorder && aCurrentPoint.equal(rPoint)) + if(nPointCount) { - return true; - } + B2DPoint aCurrentPoint(aCandidate.getB2DPoint(nPointCount - 1L)); - // cross-over in Y? - const B2DPoint aPreviousPoint(aCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L)); - const bool bCompYA(fTools::more(aPreviousPoint.getY(), rPoint.getY())); - const bool bCompYB(fTools::more(aCurrentPoint.getY(), rPoint.getY())); + for(sal_uInt32 a(0L); a < nPointCount; a++) + { + const B2DPoint aPreviousPoint(aCurrentPoint); + aCurrentPoint = aCandidate.getB2DPoint(a); - if(bCompYA != bCompYB) - { - const bool bCompXA(fTools::more(aPreviousPoint.getX(), rPoint.getX())); - const bool bCompXB(fTools::more(aCurrentPoint.getX(), rPoint.getX())); + // cross-over in Y? + const bool bCompYA(fTools::more(aPreviousPoint.getY(), rPoint.getY())); + const bool bCompYB(fTools::more(aCurrentPoint.getY(), rPoint.getY())); - if(bCompXA == bCompXB) - { - if(bCompXA) - { - bRetval = !bRetval; - } - else + if(bCompYA != bCompYB) { - // it may still be a touch with a vertical line when bWithBorder==true, - // check for it. If it is, return true - if(bWithBorder - && fTools::equal(aPreviousPoint.getX(), rPoint.getX()) - && fTools::equal(aCurrentPoint.getX(), rPoint.getX())) + // 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) { - return true; + if(bCompXA) + { + bRetval = !bRetval; + } } - } - } - else - { - const double fCompare = - aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * - (aPreviousPoint.getX() - aCurrentPoint.getX()) / - (aPreviousPoint.getY() - aCurrentPoint.getY()); + else + { + const double fCompare( + aCurrentPoint.getX() - (aCurrentPoint.getY() - rPoint.getY()) * + (aPreviousPoint.getX() - aCurrentPoint.getX()) / + (aPreviousPoint.getY() - aCurrentPoint.getY())); - if(bWithBorder && fTools::equal(fCompare, rPoint.getX())) - { - // point on line, when bWithBorder=true, all is done - return true; - } - else if(fTools::more(fCompare, rPoint.getX())) - { - bRetval = !bRetval; + if(fTools::more(fCompare, rPoint.getX())) + { + bRetval = !bRetval; + } + } } } } - } - return bRetval; + return bRetval; + } } bool isInside(const B2DPolygon& rCandidate, const B2DPolygon& rPolygon, bool bWithBorder) @@ -2022,6 +2015,36 @@ namespace basegfx } } + bool isPointOnPolygon(const B2DPolygon& rCandidate, const B2DPoint& rPoint, bool bWithPoints) + { + const B2DPolygon aCandidate(rCandidate.areControlPointsUsed() ? adaptiveSubdivideByCount(rCandidate, 6L) : rCandidate); + const sal_uInt32 nPointCount(aCandidate.count()); + + if(nPointCount > 1L) + { + const sal_uInt32 nLoopCount(aCandidate.isClosed() ? nPointCount : nPointCount - 1L); + B2DPoint aCurrentPoint(aCandidate.getB2DPoint(0L)); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + const B2DPoint aNextPoint(aCandidate.getB2DPoint((a + 1L) % nPointCount)); + + if(isPointOnLine(aCurrentPoint, aNextPoint, rPoint, bWithPoints)) + { + return true; + } + + aCurrentPoint = aNextPoint; + } + } + else if(nPointCount && bWithPoints) + { + return rPoint.equal(aCandidate.getB2DPoint(0L)); + } + + return false; + } + bool isPointInTriangle(const B2DPoint& rA, const B2DPoint& rB, const B2DPoint& rC, const B2DPoint& rCandidate, bool bWithBorder) { if(arePointsOnSameSideOfLine(rA, rB, rC, rCandidate, bWithBorder)) |