summaryrefslogtreecommitdiff
path: root/basegfx/test
diff options
context:
space:
mode:
authorThorsten Behrens <thb@openoffice.org>2004-02-04 11:11:33 +0000
committerThorsten Behrens <thb@openoffice.org>2004-02-04 11:11:33 +0000
commit5a5cf6254f4ee164237a208237e216931063ebc0 (patch)
treea27fae393bc4340ee4f530a6e7aa310bfa136701 /basegfx/test
parent43f1f1e9a867aee306508cf7f7f204633eb52ef7 (diff)
Finished test code for adaptive bezier subdivision, and added generic gnuplot output code
Diffstat (limited to 'basegfx/test')
-rw-r--r--basegfx/test/basegfx2d.cxx211
-rw-r--r--basegfx/test/makefile.mk7
2 files changed, 77 insertions, 141 deletions
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx
index 747e5e4ff033..57dd55c07ef6 100644
--- a/basegfx/test/basegfx2d.cxx
+++ b/basegfx/test/basegfx2d.cxx
@@ -12,26 +12,11 @@
#endif
#include <iostream>
+#include <fstream>
+#include "tools.hxx"
using namespace ::basegfx;
-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
{
@@ -43,7 +28,9 @@ private:
B2DCubicBezier aQuarterCircle; // not exactly, but a look-alike
B2DCubicBezier aLoop; // identical endpoints, curve goes back to where it started
B2DCubicBezier aStraightLineDistinctEndPoints; // truly a line
+ B2DCubicBezier aStraightLineDistinctEndPoints2; // truly a line, with slightly different control points
B2DCubicBezier aStraightLineIdenticalEndPoints; // degenerate case of aLoop
+ B2DCubicBezier aStraightLineIdenticalEndPoints2;// degenerate case of aLoop, with slightly different control points
B2DCubicBezier aCrossing; // curve self-intersects somewhere in the middle
B2DCubicBezier aCusp; // curve has a point of undefined tangency
@@ -57,6 +44,8 @@ public:
const B2DPoint a11(1.0, 1.0);
const B2DPoint a01(0.0, 1.0);
const B2DPoint middle( 0.5, 0.5 );
+ const B2DPoint quarterDown( 0.25, 0.25 );
+ const B2DPoint quarterUp( 0.75, 0.75 );
aHalfCircle = B2DCubicBezier(a00, a01, a11, a10);
@@ -95,109 +84,39 @@ public:
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
- << "#" << endl
- << "# automatically generated by bezierclip, don't change!" << endl
- << "#" << endl
- << "set parametric" << endl
- << "bez(p,q,r,s,t) = p*(1-t)**3+q*3*(1-t)**2*t+r*3*(1-t)*t**2+s*t**3" << endl
- << "bezd(p,q,r,s,t) = 3*(q-p)*(1-t)**2+6*(r-q)*(1-t)*t+3*(s-r)*t**2" << endl
- << "pointmarkx(c,t) = c-0.03*t" << endl
- << "pointmarky(c,t) = c+0.03*t" << endl
- << "linex(a,b,c,t) = a*-c + t*-b" << endl
- << "liney(a,b,c,t) = b*-c + t*a" << endl << endl
- << "# end of setup" << endl << endl;
-
- cout << "# bezier subdivision" << endl
- << "plot [t=0:1] ";
-
-
- cout << " bez("
- << aHalfCircle.getStartPoint().getX() << ","
- << aHalfCircle.getControlPointA().getX() << ","
- << aHalfCircle.getControlPointB().getX() << ","
- << aHalfCircle.getEndPoint().getX()
- << ",t),bez("
- << aHalfCircle.getStartPoint().getY() << ","
- << aHalfCircle.getControlPointA().getY() << ","
- << aHalfCircle.getControlPointB().getY() << ","
- << aHalfCircle.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aQuarterCircle.getStartPoint().getX() << ","
- << aQuarterCircle.getControlPointA().getX() << ","
- << aQuarterCircle.getControlPointB().getX() << ","
- << aQuarterCircle.getEndPoint().getX()
- << ",t),bez("
- << aQuarterCircle.getStartPoint().getY() << ","
- << aQuarterCircle.getControlPointA().getY() << ","
- << aQuarterCircle.getControlPointB().getY() << ","
- << aQuarterCircle.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aCusp.getStartPoint().getX() << ","
- << aCusp.getControlPointA().getX() << ","
- << aCusp.getControlPointB().getX() << ","
- << aCusp.getEndPoint().getX()
- << ",t),bez("
- << aCusp.getStartPoint().getY() << ","
- << aCusp.getControlPointA().getY() << ","
- << aCusp.getControlPointB().getY() << ","
- << aCusp.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aLoop.getStartPoint().getX() << ","
- << aLoop.getControlPointA().getX() << ","
- << aLoop.getControlPointB().getX() << ","
- << aLoop.getEndPoint().getX()
- << ",t),bez("
- << aLoop.getStartPoint().getY() << ","
- << aLoop.getControlPointA().getY() << ","
- << aLoop.getControlPointB().getY() << ","
- << aLoop.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aStraightLineDistinctEndPoints.getStartPoint().getX() << ","
- << aStraightLineDistinctEndPoints.getControlPointA().getX() << ","
- << aStraightLineDistinctEndPoints.getControlPointB().getX() << ","
- << aStraightLineDistinctEndPoints.getEndPoint().getX()
- << ",t),bez("
- << aStraightLineDistinctEndPoints.getStartPoint().getY() << ","
- << aStraightLineDistinctEndPoints.getControlPointA().getY() << ","
- << aStraightLineDistinctEndPoints.getControlPointB().getY() << ","
- << aStraightLineDistinctEndPoints.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aStraightLineIdenticalEndPoints.getStartPoint().getX() << ","
- << aStraightLineIdenticalEndPoints.getControlPointA().getX() << ","
- << aStraightLineIdenticalEndPoints.getControlPointB().getX() << ","
- << aStraightLineIdenticalEndPoints.getEndPoint().getX()
- << ",t),bez("
- << aStraightLineIdenticalEndPoints.getStartPoint().getY() << ","
- << aStraightLineIdenticalEndPoints.getControlPointA().getY() << ","
- << aStraightLineIdenticalEndPoints.getControlPointB().getY() << ","
- << aStraightLineIdenticalEndPoints.getEndPoint().getY()
- << ",t),";
- cout << " bez("
- << aCrossing.getStartPoint().getX() << ","
- << aCrossing.getControlPointA().getX() << ","
- << aCrossing.getControlPointB().getX() << ","
- << aCrossing.getEndPoint().getX()
- << ",t),bez("
- << aCrossing.getStartPoint().getY() << ","
- << aCrossing.getControlPointA().getY() << ","
- << aCrossing.getControlPointB().getY() << ","
- << aCrossing.getEndPoint().getY()
- << ",t)," << endl;
+
+ aStraightLineDistinctEndPoints2 = B2DCubicBezier(a00 + B2DPoint(5.0,0.0),
+ quarterDown + B2DPoint(5.0,0.0),
+ quarterUp + B2DPoint(5.0,0.0),
+ a11 + B2DPoint(5.0,0.0));
+
+ aStraightLineIdenticalEndPoints = B2DCubicBezier(a00 + B2DPoint(6.0,0.0),
+ a11 + B2DPoint(6.0,0.0),
+ a11 + B2DPoint(6.0,0.0),
+ a00 + B2DPoint(6.0,0.0));
+
+ aStraightLineIdenticalEndPoints2 = B2DCubicBezier(a00 + B2DPoint(7.0,0.0),
+ quarterDown + B2DPoint(7.0,0.0),
+ quarterUp + B2DPoint(7.0,0.0),
+ a00 + B2DPoint(7.0,0.0));
+
+ aCrossing = B2DCubicBezier(a00 + B2DPoint(8.0,0.0),
+ B2DPoint(2.0,2.0) + B2DPoint(8.0,0.0),
+ B2DPoint(-1.0,2.0) + B2DPoint(8.0,0.0),
+ a10 + B2DPoint(8.0,0.0));
+
+ ::std::ofstream output("bez_testcases.gnuplot");
+ testtools::Plotter aPlotter( output );
+
+ aPlotter.plot( aHalfCircle );
+ aPlotter.plot( aQuarterCircle );
+ aPlotter.plot( aCusp );
+ aPlotter.plot( aLoop );
+ aPlotter.plot( aStraightLineDistinctEndPoints );
+ aPlotter.plot( aStraightLineDistinctEndPoints2 );
+ aPlotter.plot( aStraightLineIdenticalEndPoints );
+ aPlotter.plot( aStraightLineIdenticalEndPoints2 );
+ aPlotter.plot( aCrossing );
}
void tearDown()
@@ -206,33 +125,40 @@ public:
void adaptiveByDistance()
{
-#if 0
+ ::std::ofstream output("bez_adaptiveByDistance.gnuplot");
+ testtools::Plotter aPlotter( output );
+
const double fBound( 0.0001 );
B2DPolygon result;
adaptiveSubdivideByDistance( result, aHalfCircle, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aQuarterCircle, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aLoop, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aStraightLineDistinctEndPoints, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
+
+ adaptiveSubdivideByDistance( result, aStraightLineDistinctEndPoints2, fBound );
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aStraightLineIdenticalEndPoints, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
+
+ adaptiveSubdivideByDistance( result, aStraightLineIdenticalEndPoints2, fBound );
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aCrossing, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByDistance( result, aCusp, fBound );
- plotRes(result); result.clear();
-#endif
+ aPlotter.plot(result); result.clear();
- CPPUNIT_ASSERT_MESSAGE("identity", true );
+ CPPUNIT_ASSERT_MESSAGE("adaptiveByDistance", true );
}
void adaptiveByAngle()
@@ -240,28 +166,37 @@ public:
const double fBound( 5.0 );
B2DPolygon result;
+ ::std::ofstream output("bez_adaptiveByAngle.gnuplot");
+ testtools::Plotter aPlotter( output );
+
adaptiveSubdivideByAngle( result, aHalfCircle, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aQuarterCircle, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aLoop, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aStraightLineDistinctEndPoints, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
+
+ adaptiveSubdivideByAngle( result, aStraightLineDistinctEndPoints2, fBound );
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aStraightLineIdenticalEndPoints, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
+
+ adaptiveSubdivideByAngle( result, aStraightLineIdenticalEndPoints2, fBound );
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aCrossing, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
adaptiveSubdivideByAngle( result, aCusp, fBound );
- plotRes(result); result.clear();
+ aPlotter.plot(result); result.clear();
- CPPUNIT_ASSERT_MESSAGE("identity", true );
+ CPPUNIT_ASSERT_MESSAGE("adaptiveByAngle", true );
}
// Change the following lines only, if you add, remove or rename
diff --git a/basegfx/test/makefile.mk b/basegfx/test/makefile.mk
index c697dce8341e..3830f088340d 100644
--- a/basegfx/test/makefile.mk
+++ b/basegfx/test/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.2 $
+# $Revision: 1.3 $
#
-# last change: $Author: thb $ $Date: 2003-12-08 13:24:09 $
+# last change: $Author: thb $ $Date: 2004-02-04 12:11:33 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -78,7 +78,8 @@ ENABLE_EXCEPTIONS=TRUE
SHL1OBJS= \
$(SLO)$/basegfx1d.obj \
$(SLO)$/basegfx2d.obj \
- $(SLO)$/basegfx3d.obj
+ $(SLO)$/basegfx3d.obj \
+ $(SLO)$/tools.obj
SHL1TARGET= tests
SHL1STDLIBS= $(TOOLSLIB) \