summaryrefslogtreecommitdiff
path: root/basegfx/source/polygon
diff options
context:
space:
mode:
authorArmin Weiss <aw@openoffice.org>2003-11-10 10:45:52 +0000
committerArmin Weiss <aw@openoffice.org>2003-11-10 10:45:52 +0000
commitff3c6dbe35436fa508356a45b7367d4055cd6387 (patch)
tree5325d2cd5ce67961f59260d70784e083c67bdad7 /basegfx/source/polygon
parente7fb8a71b60f4c6e94b4cafbe9d0badf427316e3 (diff)
Some error corrections, some additions to polygon stuff, making PolyPolygonCutter work
Diffstat (limited to 'basegfx/source/polygon')
-rw-r--r--basegfx/source/polygon/b2dpolygon.cxx16
-rw-r--r--basegfx/source/polygon/b2dpolygontools.cxx72
-rw-r--r--basegfx/source/polygon/b2dpolypolygon.cxx21
-rw-r--r--basegfx/source/polygon/b2dpolypolygoncutter.cxx38
4 files changed, 106 insertions, 41 deletions
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx
index e5bcd66a2e04..09d4429aa181 100644
--- a/basegfx/source/polygon/b2dpolygon.cxx
+++ b/basegfx/source/polygon/b2dpolygon.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolygon.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:30:29 $
+ * last change: $Author: aw $ $Date: 2003-11-10 11:45:50 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -118,6 +118,10 @@ public:
{
}
+ ~CoordinateDataArray2D()
+ {
+ }
+
sal_uInt32 count() const
{
return maVector.size();
@@ -182,7 +186,7 @@ public:
{
const sal_uInt32 nHalfSize(maVector.size() >> 1L);
CoordinateData2DVector::iterator aStart(maVector.begin());
- CoordinateData2DVector::iterator aEnd(maVector.end());
+ CoordinateData2DVector::iterator aEnd(maVector.end() - 1L);
for(sal_uInt32 a(0); a < nHalfSize; a++)
{
@@ -290,6 +294,10 @@ public:
}
}
+ ~ControlVectorArray2D()
+ {
+ }
+
sal_uInt32 count() const
{
return maVector.size();
@@ -1137,7 +1145,7 @@ namespace basegfx
void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
{
- DBG_ASSERT(nIndex + nCount > mpPolygon->count(), "B2DPolygon Remove outside range (!)");
+ DBG_ASSERT(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)");
if(nCount)
{
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx
index c7211c12bd07..5061acfbfae4 100644
--- a/basegfx/source/polygon/b2dpolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolygontools.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:30:29 $
+ * last change: $Author: aw $ $Date: 2003-11-10 11:45:50 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -86,15 +86,11 @@ namespace basegfx
// B2DPolygon tools
void checkClosed(polygon::B2DPolygon& rCandidate)
{
- while(rCandidate.count() > 1L)
+ while(rCandidate.count() > 1L
+ && rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L)))
{
- sal_Bool bFirstLastPointEqual(rCandidate.getB2DPoint(0L).equal(rCandidate.getB2DPoint(rCandidate.count() - 1L)));
-
- if(bFirstLastPointEqual)
- {
- rCandidate.setClosed(sal_True);
- rCandidate.remove(rCandidate.count() - 1L);
- }
+ rCandidate.setClosed(sal_True);
+ rCandidate.remove(rCandidate.count() - 1L);
}
}
@@ -134,6 +130,8 @@ namespace basegfx
// is none. Same for successor.
sal_uInt32 getIndexOfPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate)
{
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
+
if(nIndex)
{
return nIndex - 1L;
@@ -150,6 +148,8 @@ namespace basegfx
sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate)
{
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
+
if(nIndex + 1L < rCandidate.count())
{
return nIndex + 1L;
@@ -162,9 +162,12 @@ namespace basegfx
sal_uInt32 getIndexOfDifferentPredecessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate)
{
+ sal_uInt32 nNewIndex(nIndex);
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
+
if(rCandidate.count() > 1)
{
- sal_uInt32 nNewIndex = getIndexOfPredecessor(nIndex, rCandidate);
+ nNewIndex = getIndexOfPredecessor(nIndex, rCandidate);
::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex));
while(nNewIndex != nIndex
@@ -174,14 +177,17 @@ namespace basegfx
}
}
- return nIndex;
+ return nNewIndex;
}
sal_uInt32 getIndexOfDifferentSuccessor(sal_uInt32 nIndex, const ::basegfx::polygon::B2DPolygon& rCandidate)
{
+ sal_uInt32 nNewIndex(nIndex);
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
+
if(rCandidate.count() > 1)
{
- sal_uInt32 nNewIndex = getIndexOfSuccessor(nIndex, rCandidate);
+ nNewIndex = getIndexOfSuccessor(nIndex, rCandidate);
::basegfx::point::B2DPoint aPoint(rCandidate.getB2DPoint(nIndex));
while(nNewIndex != nIndex
@@ -191,7 +197,7 @@ namespace basegfx
}
}
- return nIndex;
+ return nNewIndex;
}
::basegfx::vector::B2DVectorOrientation getOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate)
@@ -207,7 +213,24 @@ namespace basegfx
return eRetval;
}
- sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint)
+ ::basegfx::vector::B2DVectorContinuity getContinuityInPoint(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex)
+ {
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
+ ::basegfx::vector::B2DVectorContinuity eRetval(::basegfx::vector::CONTINUITY_NONE);
+
+ if(rCandidate.count() > 1L && rCandidate.areControlPointsUsed())
+ {
+ sal_uInt32 nPrevInd(getIndexOfPredecessor(nIndex, rCandidate));
+ const ::basegfx::vector::B2DVector aForwardVector(rCandidate.getControlVectorA(nIndex));
+ const ::basegfx::vector::B2DVector aBackVector(rCandidate.getControlVectorB(nPrevInd));
+
+ eRetval = ::basegfx::vector::getContinuity(aBackVector, aForwardVector);
+ }
+
+ return eRetval;
+ }
+
+ sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder)
{
sal_Bool bRetval(sal_False);
const sal_uInt32 nPointCount(rCandidate.count());
@@ -215,9 +238,14 @@ namespace basegfx
for(sal_uInt32 a(0L); a < nPointCount; a++)
{
const ::basegfx::point::B2DPoint aCurrentPoint(rCandidate.getB2DPoint(a));
- const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L));
+
+ if(bWithBorder && aCurrentPoint.equal(rPoint))
+ {
+ return sal_True;
+ }
// cross-over in Y?
+ const ::basegfx::point::B2DPoint aPreviousPoint(rCandidate.getB2DPoint((!a) ? nPointCount - 1L : a - 1L));
const sal_Bool bCompYA(::basegfx::numeric::fTools::more(aPreviousPoint.getY(), rPoint.getY()));
const sal_Bool bCompYB(::basegfx::numeric::fTools::more(aCurrentPoint.getY(), rPoint.getY()));
@@ -240,7 +268,11 @@ namespace basegfx
(aPreviousPoint.getX() - aCurrentPoint.getX()) /
(aPreviousPoint.getY() - aCurrentPoint.getY());
- if(::basegfx::numeric::fTools::more(fCompare, rPoint.getX()))
+ if(bWithBorder && ::basegfx::numeric::fTools::more(fCompare, rPoint.getX()))
+ {
+ bRetval = !bRetval;
+ }
+ else if(::basegfx::numeric::fTools::moreOrEqual(fCompare, rPoint.getX()))
{
bRetval = !bRetval;
}
@@ -251,7 +283,7 @@ namespace basegfx
return bRetval;
}
- sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::polygon::B2DPolygon& rPolygon)
+ sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::polygon::B2DPolygon& rPolygon, sal_Bool bWithBorder)
{
const sal_uInt32 nPointCount(rPolygon.count());
@@ -259,7 +291,7 @@ namespace basegfx
{
const ::basegfx::point::B2DPoint aTestPoint(rPolygon.getB2DPoint(a));
- if(!isInside(rCandidate, aTestPoint))
+ if(!isInside(rCandidate, aTestPoint, bWithBorder))
{
return sal_False;
}
@@ -313,6 +345,7 @@ namespace basegfx
double getEdgeLength(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex)
{
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
double fRetval(0.0);
const sal_uInt32 nPointCount(rCandidate.count());
@@ -476,6 +509,7 @@ namespace basegfx
::basegfx::vector::B2DVectorOrientation getPointOrientation(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex)
{
+ DBG_ASSERT(nIndex < rCandidate.count(), "getIndexOfPredecessor: Access to polygon out of range (!)");
::basegfx::vector::B2DVectorOrientation eRetval(::basegfx::vector::ORIENTATION_NEUTRAL);
if(rCandidate.count() > 2)
diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx
index 7b15b1282a71..fdd1e30276d3 100644
--- a/basegfx/source/polygon/b2dpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dpolypolygon.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolypolygon.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:30:29 $
+ * last change: $Author: aw $ $Date: 2003-11-10 11:45:50 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -312,6 +312,21 @@ namespace basegfx
}
}
+ sal_Bool B2DPolyPolygon::areControlPointsUsed() const
+ {
+ for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
+ {
+ const ::basegfx::polygon::B2DPolygon& rPolygon = mpPolyPolygon->getPolygon(a);
+
+ if(rPolygon.areControlPointsUsed())
+ {
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+ }
+
void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount)
{
DBG_ASSERT(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)");
@@ -354,7 +369,7 @@ namespace basegfx
void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
{
- DBG_ASSERT(nIndex + nCount > mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)");
+ DBG_ASSERT(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)");
if(nCount)
{
diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
index 46b86ab10e40..31df5fee4628 100644
--- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx
+++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolypolygoncutter.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:29:33 $
+ * last change: $Author: aw $ $Date: 2003-11-10 11:45:51 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -242,21 +242,26 @@ namespace basegfx
return aRetval;
}
- sal_Bool B2DPolygonNode::isInside(const ::basegfx::point::B2DPoint& rPnt) const
+ sal_Bool B2DPolygonNode::isInside(const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder) const
{
sal_Bool bInside(sal_False);
const B2DPolygonNode* pCurrent = this;
do
{
+ if(bWithBorder && pCurrent->getPosition().equal(rPoint))
+ {
+ return sal_True;
+ }
+
B2DPolygonNode* pNext = pCurrent->getNext();
- const sal_Bool bCompYA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getY(), rPnt.getY()));
- const sal_Bool bCompYB(::basegfx::numeric::fTools::more(pNext->getPosition().getY(), rPnt.getY()));
+ const sal_Bool bCompYA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getY(), rPoint.getY()));
+ const sal_Bool bCompYB(::basegfx::numeric::fTools::more(pNext->getPosition().getY(), rPoint.getY()));
if(bCompYA != bCompYB)
{
- const sal_Bool bCompXA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getX(), rPnt.getX()));
- const sal_Bool bCompXB(::basegfx::numeric::fTools::more(pNext->getPosition().getX(), rPnt.getX()));
+ const sal_Bool bCompXA(::basegfx::numeric::fTools::more(pCurrent->getPosition().getX(), rPoint.getX()));
+ const sal_Bool bCompXB(::basegfx::numeric::fTools::more(pNext->getPosition().getX(), rPoint.getX()));
if(bCompXA == bCompXB)
{
@@ -268,11 +273,15 @@ namespace basegfx
else
{
double fCmp =
- pNext->getPosition().getX() - (pNext->getPosition().getY() - rPnt.getY()) *
+ pNext->getPosition().getX() - (pNext->getPosition().getY() - rPoint.getY()) *
(pCurrent->getPosition().getX() - pNext->getPosition().getX()) /
(pCurrent->getPosition().getY() - pNext->getPosition().getY());
- if(::basegfx::numeric::fTools::more(fCmp, rPnt.getX()))
+ if(bWithBorder && ::basegfx::numeric::fTools::more(fCmp, rPoint.getX()))
+ {
+ bInside = !bInside;
+ }
+ else if(::basegfx::numeric::fTools::moreOrEqual(fCmp, rPoint.getX()))
{
bInside = !bInside;
}
@@ -287,13 +296,13 @@ namespace basegfx
return bInside;
}
- sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly) const
+ sal_Bool B2DPolygonNode::isPolygonInside(B2DPolygonNode* pPoly, sal_Bool bWithBorder) const
{
B2DPolygonNode* pTest = pPoly;
sal_Bool bAllAInside(sal_True);
do {
- bAllAInside = isInside(pTest->getPosition());
+ bAllAInside = isInside(pTest->getPosition(), bWithBorder);
pTest = pTest->getNext();
} while(bAllAInside && pTest != pPoly);
@@ -397,8 +406,8 @@ namespace basegfx
if(a != b && doRangesInclude(rInfoA.getRange(), rInfoB.getRange()))
{
- // volume B in A, test pA, pB for inclusion
- if(maPolygonList[a]->isPolygonInside(maPolygonList[b]))
+ // volume B in A, test pA, pB for inclusion, with border
+ if(maPolygonList[a]->isPolygonInside(maPolygonList[b], sal_True))
{
// pB is inside pA
rInfoB.changeDepth(rInfoA.getOrientation());
@@ -567,10 +576,9 @@ namespace basegfx
if(nCount > 2L)
{
B2DPolygon aNewPolygon;
- nCount = 0L;
do {
- aNewPolygon.setB2DPoint(nCount++, pAct->getPosition());
+ aNewPolygon.append(pAct->getPosition());
pAct = pAct->getNext();
} while(pAct != pCand);