summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorArmin Weiss <aw@openoffice.org>2003-11-11 08:48:14 +0000
committerArmin Weiss <aw@openoffice.org>2003-11-11 08:48:14 +0000
commitd2e3aaa262de3815c4ba165590ee5e98e5db2ac5 (patch)
treee185b552683e4ebb859f7b52aea58f5ecf1bb760 /basegfx
parent5d6413171a0f9d92a3cf331ab05b18e06c98fde2 (diff)
Added functionality at the Poly and PolyPolygon tools for subdivides, corrected polygon clipper further
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/inc/basegfx/polygon/b2dpolygontools.hxx9
-rw-r--r--basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx7
-rw-r--r--basegfx/source/polygon/b2dpolygontools.cxx86
-rw-r--r--basegfx/source/polygon/b2dpolypolygontools.cxx28
4 files changed, 121 insertions, 9 deletions
diff --git a/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx b/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx
index ae69b4078280..efc77e678d21 100644
--- a/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx
+++ b/basegfx/inc/basegfx/polygon/b2dpolygontools.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolygontools.hxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: aw $ $Date: 2003-11-10 11:45:47 $
+ * last change: $Author: aw $ $Date: 2003-11-11 09:48:12 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -102,7 +102,7 @@ namespace basegfx
method corrects this (removes double start/end points)
and sets the Closed()-state of the polygon correctly.
*/
- void checkClosed(polygon::B2DPolygon& rCandidate);
+ void checkClosed(::basegfx::polygon::B2DPolygon& rCandidate);
// Get index of outmost point (e.g. biggest X and biggest Y)
sal_uInt32 getIndexOfOutmostPoint(const ::basegfx::polygon::B2DPolygon& rCandidate);
@@ -153,6 +153,9 @@ namespace basegfx
// Continuity check for point with given index
::basegfx::vector::B2DVectorContinuity getContinuityInPoint(const ::basegfx::polygon::B2DPolygon& rCandidate, sal_uInt32 nIndex);
+ // Subdivide all contained curves. Use distanceBound value if given.
+ ::basegfx::polygon::B2DPolygon adaptiveSubdivide(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistanceBound = 0.0);
+
// Definitions for the cut flags used from the findCut methods
typedef sal_uInt16 CutFlagValue;
diff --git a/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx b/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx
index e640dbb9f295..926fa918035a 100644
--- a/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx
+++ b/basegfx/inc/basegfx/polygon/b2dpolypolygontools.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolypolygontools.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:30:25 $
+ * last change: $Author: aw $ $Date: 2003-11-11 09:48:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -107,6 +107,9 @@ namespace basegfx
void removeIntersections(::basegfx::polygon::B2DPolyPolygon& rCandidate,
sal_Bool bForceOrientation = sal_True, sal_Bool bInvertRemove = sal_False);
+ // Subdivide all contained curves. Use distanceBound value if given.
+ ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivide(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fDistanceBound = 0.0);
+
} // end of namespace tools
} // end of namespace polygon
} // end of namespace basegfx
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx
index 5061acfbfae4..bef74f8389ef 100644
--- a/basegfx/source/polygon/b2dpolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolygontools.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: aw $ $Date: 2003-11-10 11:45:50 $
+ * last change: $Author: aw $ $Date: 2003-11-11 09:48:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -75,6 +75,14 @@
#include <basegfx/range/b2drange.hxx>
#endif
+#ifndef _BGFX_CURVE_B2DCUBICBEZIER_HXX
+#include <basegfx/curve/b2dcubicbezier.hxx>
+#endif
+
+#ifndef _BGFX_CURVE_B2DBEZIERTOOLS_HXX
+#include <basegfx/curve/b2dbeziertools.hxx>
+#endif
+
//////////////////////////////////////////////////////////////////////////////
namespace basegfx
@@ -230,6 +238,80 @@ namespace basegfx
return eRetval;
}
+ ::basegfx::polygon::B2DPolygon adaptiveSubdivide(const ::basegfx::polygon::B2DPolygon& rCandidate, double fDistanceBound)
+ {
+ ::basegfx::polygon::B2DPolygon aRetval(rCandidate);
+
+ if(aRetval.areControlPointsUsed())
+ {
+ const sal_uInt32 nPointCount(rCandidate.isClosed() ? rCandidate.count() : rCandidate.count() - 1L);
+ aRetval.clear();
+
+ for(sal_uInt32 a(0L); a < nPointCount; a++)
+ {
+ const ::basegfx::vector::B2DVector aVectorA(rCandidate.getControlVectorA(a));
+ const ::basegfx::vector::B2DVector aVectorB(rCandidate.getControlVectorB(a));
+
+ if(!aVectorA.equalZero() || !aVectorB.equalZero())
+ {
+ // vectors are used, get points
+ const sal_uInt32 nNext(getIndexOfSuccessor(a, rCandidate));
+ ::basegfx::point::B2DPoint aPointA(rCandidate.getB2DPoint(a));
+ ::basegfx::point::B2DPoint aPointB(rCandidate.getB2DPoint(nNext));
+
+ // build CubicBezier segment
+ ::basegfx::curve::B2DCubicBezier aBezier(
+ aPointA, aPointA + aVectorA, aPointB + aVectorB, aPointB);
+
+ // generate DistanceBound
+ double fBound;
+
+ if(0.0 == fDistanceBound)
+ {
+ // If not set, calculate rough length of bezier segment by taking
+ // half of the sum of the edge and the control polygon
+ ::basegfx::vector::B2DVector aSimpleDistance(aPointB - aPointA);
+ ::basegfx::vector::B2DVector aTripleDistanceTop((aPointB + aVectorB) - (aPointA + aVectorA));
+ const double fRoughLength(
+ (aSimpleDistance.getLength()
+ + (aVectorA.getLength() + aVectorB.getLength() + aTripleDistanceTop.getLength())) / 2.0);
+
+ // take 1/100th of the rouch curve length
+ fBound = fRoughLength * 0.01;
+ }
+ else
+ {
+ // use given bound value
+ fBound = fDistanceBound;
+ }
+
+ // make sure bound value is not too small. The base units are 1/100th mm, thus
+ // just make sure it's not smaller then 1/100th of that
+ if(fBound < 0.01)
+ {
+ fBound = 0.01;
+ }
+
+ // call adaptive subdivide
+ ::basegfx::curve::adaptiveSubdivide(aRetval, aBezier, fBound);
+ }
+ else
+ {
+ // no vectors used, add point
+ aRetval.append(rCandidate.getB2DPoint(a));
+ }
+ }
+
+ // check closed flag, aRetval was cleared and thus it may be invalid.
+ if(aRetval.isClosed() != rCandidate.isClosed())
+ {
+ aRetval.setClosed(rCandidate.isClosed());
+ }
+ }
+
+ return aRetval;
+ }
+
sal_Bool isInside(const ::basegfx::polygon::B2DPolygon& rCandidate, const ::basegfx::point::B2DPoint& rPoint, sal_Bool bWithBorder)
{
sal_Bool bRetval(sal_False);
diff --git a/basegfx/source/polygon/b2dpolypolygontools.cxx b/basegfx/source/polygon/b2dpolypolygontools.cxx
index 07ada131585d..bd5b03a3549b 100644
--- a/basegfx/source/polygon/b2dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolypolygontools.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dpolypolygontools.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: aw $ $Date: 2003-11-06 16:30:29 $
+ * last change: $Author: aw $ $Date: 2003-11-11 09:48:14 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -172,6 +172,30 @@ namespace basegfx
rCandidate.clear();
aCutter.getPolyPolygon(rCandidate);
}
+
+ ::basegfx::polygon::B2DPolyPolygon adaptiveSubdivide(const ::basegfx::polygon::B2DPolyPolygon& rCandidate, double fDistanceBound)
+ {
+ ::basegfx::polygon::B2DPolyPolygon aRetval(rCandidate);
+
+ if(aRetval.areControlPointsUsed())
+ {
+ const sal_uInt32 nPolygonCount(aRetval.count());
+
+ for(sal_uInt32 a(0L); aRetval.areControlPointsUsed() && a < nPolygonCount; a++)
+ {
+ ::basegfx::polygon::B2DPolygon aCandidate = aRetval.getPolygon(a);
+
+ if(aCandidate.areControlPointsUsed())
+ {
+ aCandidate = ::basegfx::polygon::tools::adaptiveSubdivide(aCandidate, fDistanceBound);
+ aRetval.setPolygon(a, aCandidate);
+ }
+ }
+ }
+
+ return aRetval;
+ }
+
} // end of namespace tools
} // end of namespace polygon
} // end of namespace basegfx