From: jaspervdg Date: Wed, 6 Aug 2008 14:31:46 +0000 (+0000) Subject: 2Geom version of the path tests + some additional small changes. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=741dec82d06d12a1c8cbe2baf7a9b9437b5ddec5;p=inkscape.git 2Geom version of the path tests + some additional small changes. --- diff --git a/build.xml b/build.xml index c8a65cab3..4a8bb0933 100644 --- a/build.xml +++ b/build.xml @@ -52,7 +52,7 @@ - + @@ -250,7 +250,8 @@ - + + +#include "2geom/coord.h" +#include "2geom/curves.h" +#include "2geom/pathvector.h" +#include "svg/svg.h" +#include "prefs-utils.h" +#include "streq.h" +#include +#include +#include +#include + +class SvgPathGeomTest : public CxxTest::TestSuite +{ +private: + std::vector rectanglesAbsoluteClosed; + std::vector rectanglesRelativeClosed; + std::vector rectanglesAbsoluteOpen; + std::vector rectanglesRelativeOpen; + Geom::PathVector rectanglepv; +public: + SvgPathGeomTest() { + // Lots of ways to define the same rectangle + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2 Z"); + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 4,2 4,8 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 H 4 V 8 H 1 z"); + rectanglesRelativeClosed.push_back("m 1,2 l 3,0 l 0,6 l -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 3,0 0,6 -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 h 3 v 6 h -3 z"); + rectanglesAbsoluteOpen.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 4,2 4,8 1,8 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 H 4 V 8 H 1 V 2"); + rectanglesRelativeOpen.push_back("m 1,2 l 3,0 l 0,6 l -3,0 l 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 3,0 0,6 -3,0 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 h 3 v 6 h -3 v -6"); + rectanglepv.push_back(Geom::Path(Geom::Point(1,2))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(1,2),Geom::Point(4,2))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(4,2),Geom::Point(4,8))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(4,8),Geom::Point(1,8))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(1,8),Geom::Point(1,2))); + // TODO: Also test some (smooth) cubic/quadratic beziers and elliptical arcs + } + +// createSuite and destroySuite get us per-suite setup and teardown +// without us having to worry about static initialization order, etc. + static SvgPathGeomTest *createSuite() { return new SvgPathGeomTest(); } + static void destroySuite( SvgPathGeomTest *suite ) { delete suite; } + + void testReadRectanglesAbsoluteClosed() + { + rectanglepv.back().close(); + for(size_t i=0; i(ca)) + { + Geom::LineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la)[0],(*lb)[0], eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la)[0][Geom::X], (*la)[0][Geom::Y], (*lb)[0][Geom::X], (*lb)[0][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[1],(*lb)[1], eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la)[1][Geom::X], (*la)[1][Geom::Y], (*lb)[1][Geom::X], (*lb)[1][Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::HLineSegment const *la = dynamic_cast(ca)) + { + Geom::HLineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::VLineSegment const *la = dynamic_cast(ca)) + { + Geom::VLineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::CubicBezier const *la = dynamic_cast(ca)) + { + Geom::CubicBezier const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la)[0],(*lb)[0], eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la)[0][Geom::X], (*la)[0][Geom::Y], (*lb)[0][Geom::X], (*lb)[0][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[1],(*lb)[1], eps)) { + char temp[200]; + sprintf(temp, "Different 1st control point: (%g,%g) != (%g,%g)", (*la)[1][Geom::X], (*la)[1][Geom::Y], (*lb)[1][Geom::X], (*lb)[1][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[2],(*lb)[2], eps)) { + char temp[200]; + sprintf(temp, "Different 2nd control point: (%g,%g) != (%g,%g)", (*la)[2][Geom::X], (*la)[2][Geom::Y], (*lb)[2][Geom::X], (*lb)[2][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[3],(*lb)[3], eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la)[3][Geom::X], (*la)[3][Geom::Y], (*lb)[3][Geom::X], (*lb)[3][Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else + { + TS_FAIL((std::string("Unknown curve type: ") + typeid(*ca).name()).c_str()); + return false; + } + } + else // not same type + { + if(Geom::LineSegment const *la = dynamic_cast(ca)) + { + if (Geom::HLineSegment const *lb = dynamic_cast(cb)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else if (Geom::VLineSegment const *lb = dynamic_cast(cb)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else { + TS_FAIL((std::string("Different curve types: ") + typeid(*ca).name() + " != " + typeid(*cb).name()).c_str()); + return false; + } + } + else if(Geom::LineSegment const *lb = dynamic_cast(cb)) + { + if (Geom::HLineSegment const *la = dynamic_cast(ca)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else if (Geom::VLineSegment const *la = dynamic_cast(ca)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else { + TS_FAIL((std::string("Different curve types: ") + typeid(*ca).name() + " != " + typeid(*cb).name()).c_str()); + return false; + } + } + } + } + } + return true; + } +}; + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/svg/svg-path-nr-test.h b/src/svg/svg-path-nr-test.h new file mode 100644 index 000000000..df9c46051 --- /dev/null +++ b/src/svg/svg-path-nr-test.h @@ -0,0 +1,493 @@ +#include +#include "libnr/n-art-bpath.h" +#include "svg/svg.h" +#include "2geom/coord.h" +#include "prefs-utils.h" +#include "streq.h" +#include +#include +#include + +class SvgPathNRTest : public CxxTest::TestSuite +{ +private: + std::vector rectanglesAbsoluteClosed; + std::vector rectanglesRelativeClosed; + std::vector rectanglesAbsoluteOpen; + std::vector rectanglesRelativeOpen; + NArtBpath rectangleBpath[5+1]; +public: + SvgPathNRTest() { + // Lots of ways to define the same rectangle + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2 Z"); + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 4,2 4,8 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 H 4 V 8 H 1 z"); + rectanglesRelativeClosed.push_back("m 1,2 l 3,0 l 0,6 l -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 3,0 0,6 -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 h 3 v 6 h -3 z"); + rectanglesAbsoluteOpen.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 4,2 4,8 1,8 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 H 4 V 8 H 1 V 2"); + rectanglesRelativeOpen.push_back("m 1,2 l 3,0 l 0,6 l -3,0 l 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 3,0 0,6 -3,0 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 h 3 v 6 h -3 v -6"); + rectangleBpath[0].code = NR_MOVETO; + rectangleBpath[0].x3 = 1; + rectangleBpath[0].y3 = 2; + rectangleBpath[1].code = NR_LINETO; + rectangleBpath[1].x3 = 4; + rectangleBpath[1].y3 = 2; + rectangleBpath[2].code = NR_LINETO; + rectangleBpath[2].x3 = 4; + rectangleBpath[2].y3 = 8; + rectangleBpath[3].code = NR_LINETO; + rectangleBpath[3].x3 = 1; + rectangleBpath[3].y3 = 8; + rectangleBpath[4].code = NR_LINETO; + rectangleBpath[4].x3 = 1; + rectangleBpath[4].y3 = 2; + rectangleBpath[5].code = NR_END; + // TODO: Also test some (smooth) cubic/quadratic beziers and elliptical arcs + } + +// createSuite and destroySuite get us per-suite setup and teardown +// without us having to worry about static initialization order, etc. + static SvgPathNRTest *createSuite() { return new SvgPathNRTest(); } + static void destroySuite( SvgPathNRTest *suite ) { delete suite; } + + void testReadRectanglesAbsoluteClosed() + { + rectangleBpath[0].code = NR_MOVETO; + for(size_t i=0; icode != NR_END && b->code == a->code) { + switch(a->code) { + case NR_MOVETO: + case NR_MOVETO_OPEN: + case NR_LINETO: + if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; + break; + case NR_CURVETO: + if (!Geom::are_near(a->x1,b->x1, eps) || !Geom::are_near(a->y1,b->y1, eps)) return false; + if (!Geom::are_near(a->x2,b->x2, eps) || !Geom::are_near(a->y2,b->y2, eps)) return false; + if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; + break; + default: + TS_FAIL("Unknown path code!"); + } + a++; + b++; + } + return a->code == b->code; + } +}; + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/svg/svg-path-test.h b/src/svg/svg-path-test.h deleted file mode 100644 index 28173cbd1..000000000 --- a/src/svg/svg-path-test.h +++ /dev/null @@ -1,493 +0,0 @@ -#include -#include "libnr/n-art-bpath.h" -#include "svg/svg.h" -#include "2geom/coord.h" -#include "prefs-utils.h" -#include "streq.h" -#include -#include -#include - -class SvgPathTest : public CxxTest::TestSuite -{ -private: - std::vector rectanglesAbsoluteClosed; - std::vector rectanglesRelativeClosed; - std::vector rectanglesAbsoluteOpen; - std::vector rectanglesRelativeOpen; - NArtBpath rectangleBpath[5+1]; -public: - SvgPathTest() { - // Lots of ways to define the same rectangle - rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2 Z"); - rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 z"); - rectanglesAbsoluteClosed.push_back("M 1,2 4,2 4,8 1,8 z"); - rectanglesAbsoluteClosed.push_back("M 1,2 H 4 V 8 H 1 z"); - rectanglesRelativeClosed.push_back("m 1,2 l 3,0 l 0,6 l -3,0 z"); - rectanglesRelativeClosed.push_back("m 1,2 3,0 0,6 -3,0 z"); - rectanglesRelativeClosed.push_back("m 1,2 h 3 v 6 h -3 z"); - rectanglesAbsoluteOpen.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2"); - rectanglesAbsoluteOpen.push_back("M 1,2 4,2 4,8 1,8 1,2"); - rectanglesAbsoluteOpen.push_back("M 1,2 H 4 V 8 H 1 V 2"); - rectanglesRelativeOpen.push_back("m 1,2 l 3,0 l 0,6 l -3,0 l 0,-6"); - rectanglesRelativeOpen.push_back("m 1,2 3,0 0,6 -3,0 0,-6"); - rectanglesRelativeOpen.push_back("m 1,2 h 3 v 6 h -3 v -6"); - rectangleBpath[0].code = NR_MOVETO; - rectangleBpath[0].x3 = 1; - rectangleBpath[0].y3 = 2; - rectangleBpath[1].code = NR_LINETO; - rectangleBpath[1].x3 = 4; - rectangleBpath[1].y3 = 2; - rectangleBpath[2].code = NR_LINETO; - rectangleBpath[2].x3 = 4; - rectangleBpath[2].y3 = 8; - rectangleBpath[3].code = NR_LINETO; - rectangleBpath[3].x3 = 1; - rectangleBpath[3].y3 = 8; - rectangleBpath[4].code = NR_LINETO; - rectangleBpath[4].x3 = 1; - rectangleBpath[4].y3 = 2; - rectangleBpath[5].code = NR_END; - // TODO: Also test some (smooth) cubic/quadratic beziers and elliptical arcs - } - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static SvgPathTest *createSuite() { return new SvgPathTest(); } - static void destroySuite( SvgPathTest *suite ) { delete suite; } - - void testReadRectanglesAbsoluteClosed() - { - rectangleBpath[0].code = NR_MOVETO; - for(size_t i=0; icode != NR_END && b->code == a->code) { - switch(a->code) { - case NR_MOVETO: - case NR_MOVETO_OPEN: - case NR_LINETO: - if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; - break; - case NR_CURVETO: - if (!Geom::are_near(a->x1,b->x1, eps) || !Geom::are_near(a->y1,b->y1, eps)) return false; - if (!Geom::are_near(a->x2,b->x2, eps) || !Geom::are_near(a->y2,b->y2, eps)) return false; - if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; - break; - default: - TS_FAIL("Unknown path code!"); - } - a++; - b++; - } - return a->code == b->code; - } -}; - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :