Kaydet (Commit) 714d3577 authored tarafından Thorsten Behrens's avatar Thorsten Behrens

Updated unit tests

üst 2c3b8d0c
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: b2dbeziertools.hxx,v $ * $RCSfile: b2dbeziertools.hxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: thb $ $Date: 2003-12-08 13:24:04 $ * last change: $Author: thb $ $Date: 2003-12-08 16:55:59 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -149,7 +149,7 @@ namespace basegfx ...@@ -149,7 +149,7 @@ namespace basegfx
*/ */
sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly, sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly,
const B2DCubicBezier& rCurve, const B2DCubicBezier& rCurve,
double distanceBound ); double angleBound );
/** Subdivide given cubic bezier segment. /** Subdivide given cubic bezier segment.
...@@ -226,32 +226,9 @@ namespace basegfx ...@@ -226,32 +226,9 @@ namespace basegfx
@return the number of line segments created @return the number of line segments created
*/ */
sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly,
const B2DQuadraticBezier& rCurve,
double distanceBound );
/** Subdivide given quadratic bezier segment.
This function adaptively subdivides the given bezier
segment into as much straight line segments as necessary,
such that the maximal angle change between any adjacent
lines is less than the given error value.
@param rPoly
Output polygon. The subdivided bezier segment is added to
this polygon via B2DPolygon::append().
@param rCurve
The cubic bezier curve to subdivide
@param angleBound
Bound on the maximal angle difference between two adjacent
polygon lines, in degrees.
@return the number of line segments created
*/
sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly, sal_Int32 adaptiveSubdivideByAngle( B2DPolygon& rPoly,
const B2DQuadraticBezier& rCurve, const B2DQuadraticBezier& rCurve,
double angleBound ); double angleBound );
} }
#endif // _BGFX_CURVE_B2DBEZIERTOOLS_HXX2 #endif // _BGFX_CURVE_B2DBEZIERTOOLS_HXX2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <cppunit/simpleheader.hxx> #include <cppunit/simpleheader.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx> #include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/curve/b2dcubicbezier.hxx> #include <basegfx/curve/b2dcubicbezier.hxx>
#include <basegfx/curve/b2dbeziertools.hxx> #include <basegfx/curve/b2dbeziertools.hxx>
...@@ -15,6 +16,23 @@ ...@@ -15,6 +16,23 @@
using namespace ::basegfx; using namespace ::basegfx;
using namespace ::std; using namespace ::std;
namespace
{
void plotRes( const B2DPolygon& res )
{
cout << "plot '-' using ($1):($2) with lp" << endl;
unsigned int i;
for( i=0; i<res.count(); ++i )
{
const B2DPoint currPoint( res.getB2DPoint(i) );
cout << currPoint.getX() << " " << currPoint.getY() << endl;
}
cout << "e" << endl;
}
}
namespace basegfx2d namespace basegfx2d
{ {
...@@ -58,21 +76,33 @@ public: ...@@ -58,21 +76,33 @@ public:
// Choosing R=1, A=0, B=pi/2 // Choosing R=1, A=0, B=pi/2
const double h( 4.0/3.0 * tan(F_PI/8.0) ); const double h( 4.0/3.0 * tan(F_PI/8.0) );
aQuarterCircle = B2DCubicBezier(a10, aQuarterCircle = B2DCubicBezier(a10 + B2DPoint(1.0,0.0),
B2DPoint( 1.0, h ), B2DPoint( 1.0, h ) + B2DPoint(1.0,0.0),
B2DPoint( h, 1.0), B2DPoint( h, 1.0) + B2DPoint(1.0,0.0),
a01); a01 + B2DPoint(1.0,0.0));
aCusp = B2DCubicBezier(a00, a11, a01, a10); aCusp = B2DCubicBezier(a00 + B2DPoint(2.0,0.0),
a11 + B2DPoint(2.0,0.0),
aLoop = B2DCubicBezier(a00, a01, a10, a00); a01 + B2DPoint(2.0,0.0),
a10 + B2DPoint(2.0,0.0));
aStraightLineDistinctEndPoints = B2DCubicBezier(a00, middle, middle, a11);
aStraightLineIdenticalEndPoints = B2DCubicBezier(a00, a11, a11, a00); aLoop = B2DCubicBezier(a00 + B2DPoint(3.0,0.0),
aCrossing = B2DCubicBezier(a00, a01 + B2DPoint(3.0,0.0),
B2DPoint(2.0,2.0), a10 + B2DPoint(3.0,0.0),
B2DPoint(-1.0,2.0), a00 + B2DPoint(3.0,0.0));
a10);
aStraightLineDistinctEndPoints = B2DCubicBezier(a00 + B2DPoint(4.0,0.0),
middle + B2DPoint(4.0,0.0),
middle + B2DPoint(4.0,0.0),
a11 + B2DPoint(4.0,0.0));
aStraightLineIdenticalEndPoints = B2DCubicBezier(a00 + B2DPoint(5.0,0.0),
a11 + B2DPoint(5.0,0.0),
a11 + B2DPoint(5.0,0.0),
a00 + B2DPoint(5.0,0.0));
aCrossing = B2DCubicBezier(a00 + B2DPoint(6.0,0.0),
B2DPoint(2.0,2.0) + B2DPoint(6.0,0.0),
B2DPoint(-1.0,2.0) + B2DPoint(6.0,0.0),
a10 + B2DPoint(6.0,0.0));
cout << "#!/usr/bin/gnuplot -persist" << endl cout << "#!/usr/bin/gnuplot -persist" << endl
<< "#" << endl << "#" << endl
...@@ -89,6 +119,8 @@ public: ...@@ -89,6 +119,8 @@ public:
cout << "# bezier subdivision" << endl cout << "# bezier subdivision" << endl
<< "plot [t=0:1] "; << "plot [t=0:1] ";
cout << " bez(" cout << " bez("
<< aHalfCircle.getStartPoint().getX() << "," << aHalfCircle.getStartPoint().getX() << ","
<< aHalfCircle.getControlPointA().getX() << "," << aHalfCircle.getControlPointA().getX() << ","
...@@ -172,13 +204,63 @@ public: ...@@ -172,13 +204,63 @@ public:
{ {
} }
void adaptiveSubdivideByDistance() void adaptiveByDistance()
{ {
#if 0
const double fBound( 0.0001 );
B2DPolygon result;
adaptiveSubdivideByDistance( result, aHalfCircle, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aQuarterCircle, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aLoop, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aStraightLineDistinctEndPoints, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aStraightLineIdenticalEndPoints, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aCrossing, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByDistance( result, aCusp, fBound );
plotRes(result); result.clear();
#endif
CPPUNIT_ASSERT_MESSAGE("identity", true ); CPPUNIT_ASSERT_MESSAGE("identity", true );
} }
void adaptiveSubdivideByAngle() void adaptiveByAngle()
{ {
const double fBound( 5.0 );
B2DPolygon result;
adaptiveSubdivideByAngle( result, aHalfCircle, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aQuarterCircle, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aLoop, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aStraightLineDistinctEndPoints, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aStraightLineIdenticalEndPoints, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aCrossing, fBound );
plotRes(result); result.clear();
adaptiveSubdivideByAngle( result, aCusp, fBound );
plotRes(result); result.clear();
CPPUNIT_ASSERT_MESSAGE("identity", true ); CPPUNIT_ASSERT_MESSAGE("identity", true );
} }
...@@ -187,8 +269,8 @@ public: ...@@ -187,8 +269,8 @@ public:
// because these macros are need by auto register mechanism. // because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(b2dbeziertools); CPPUNIT_TEST_SUITE(b2dbeziertools);
CPPUNIT_TEST(adaptiveSubdivideByDistance); // TODO: add tests for quadratic bezier (subdivide and degree reduction) CPPUNIT_TEST(adaptiveByDistance); // TODO: add tests for quadratic bezier (subdivide and degree reduction)
CPPUNIT_TEST(adaptiveSubdivideByAngle); CPPUNIT_TEST(adaptiveByAngle);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; // class b2dcubicbezier }; // class b2dcubicbezier
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# #
# $RCSfile: export.map,v $ # $RCSfile: export.map,v $
# #
# $Revision: 1.1 $ # $Revision: 1.2 $
# #
# last change: $Author: thb $ $Date: 2003-12-08 13:21:24 $ # last change: $Author: thb $ $Date: 2003-12-08 16:56:04 $
# #
# The Contents of this file are made available subject to the terms of # The Contents of this file are made available subject to the terms of
# either of the following licenses # either of the following licenses
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment