diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-06-06 01:43:35 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-06-06 01:43:35 +0000 |
| commit | 8a38c52bce619b07117cdd87a183eb05fb51e28e (patch) | |
| tree | 39b9f2af1ce9df43884a3b33ca2445097fe8f5a5 /src/libnr | |
| parent | oops. sys/wait.h not on win32 (diff) | |
| download | inkscape-8a38c52bce619b07117cdd87a183eb05fb51e28e.tar.gz inkscape-8a38c52bce619b07117cdd87a183eb05fb51e28e.zip | |
merge gsoc2008_johan_path2geom into trunk
(bzr r5823)
Diffstat (limited to 'src/libnr')
| -rw-r--r-- | src/libnr/in-svg-plane-test.cpp | 4 | ||||
| -rw-r--r-- | src/libnr/in-svg-plane-test.h | 4 | ||||
| -rw-r--r-- | src/libnr/n-art-bpath-2geom.cpp | 92 | ||||
| -rw-r--r-- | src/libnr/n-art-bpath-2geom.h | 2 | ||||
| -rw-r--r-- | src/libnr/nr-convert2geom.h | 24 | ||||
| -rw-r--r-- | src/libnr/nr-point-fns-test.cpp | 10 | ||||
| -rw-r--r-- | src/libnr/nr-point-fns-test.h | 14 | ||||
| -rw-r--r-- | src/libnr/nr-point-fns.cpp | 2 | ||||
| -rw-r--r-- | src/libnr/nr-types.cpp | 2 |
9 files changed, 44 insertions, 110 deletions
diff --git a/src/libnr/in-svg-plane-test.cpp b/src/libnr/in-svg-plane-test.cpp index f5620c32b..138812655 100644 --- a/src/libnr/in-svg-plane-test.cpp +++ b/src/libnr/in-svg-plane-test.cpp @@ -19,8 +19,8 @@ int main(int argc, char *argv[]) NR::Point const small_n3_4(-3.0 * small, 4.0 * small); NR::Point const part_nan(3., nan); - assert(isNaN(nan)); - assert(!isNaN(small)); + assert(IS_NAN(nan)); + assert(!IS_NAN(small)); UTEST_TEST("in_svg_plane") { UTEST_ASSERT(in_svg_plane(p3n4)); diff --git a/src/libnr/in-svg-plane-test.h b/src/libnr/in-svg-plane-test.h index 6cd29bd6a..ced9f978c 100644 --- a/src/libnr/in-svg-plane-test.h +++ b/src/libnr/in-svg-plane-test.h @@ -21,8 +21,8 @@ public: small_n3_4( -3.0 * small, 4.0 * small ), part_nan( 3., nan ) { - setupValid &= isNaN(nan); - setupValid &= !isNaN(small); + setupValid &= IS_NAN(nan); + setupValid &= !IS_NAN(small); } virtual ~InSvgPlaneTest() {} diff --git a/src/libnr/n-art-bpath-2geom.cpp b/src/libnr/n-art-bpath-2geom.cpp index 89ac85b2b..e9dd9f5a6 100644 --- a/src/libnr/n-art-bpath-2geom.cpp +++ b/src/libnr/n-art-bpath-2geom.cpp @@ -3,91 +3,18 @@ /** \file * Contains functions to convert from NArtBpath to 2geom's Path * - * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Johan Engelen 2007-2008 <j.b.c.engelen@utwente.nl> * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "libnr/n-art-bpath-2geom.h" + #include "svg/svg.h" #include <glib.h> #include <2geom/path.h> #include <2geom/svg-path.h> #include <2geom/svg-path-parser.h> -#include <2geom/sbasis-to-bezier.h> - -//########################################################## - -#include <iostream> -#include <sstream> -#include <string> -#include <boost/format.hpp> - -static void curve_to_svgd(std::ostream & f, Geom::Curve const* c) { - if(Geom::LineSegment const *line_segment = dynamic_cast<Geom::LineSegment const *>(c)) { - f << boost::format("L %g,%g ") % (*line_segment)[1][0] % (*line_segment)[1][1]; - } - else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const *>(c)) { - f << boost::format("Q %g,%g %g,%g ") % (*quadratic_bezier)[1][0] % (*quadratic_bezier)[1][0] - % (*quadratic_bezier)[2][0] % (*quadratic_bezier)[2][1]; - } - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const *>(c)) { - f << boost::format("C %g,%g %g,%g %g,%g ") - % (*cubic_bezier)[1][0] % (*cubic_bezier)[1][1] - % (*cubic_bezier)[2][0] % (*cubic_bezier)[2][1] - % (*cubic_bezier)[3][0] % (*cubic_bezier)[3][1]; - } -// else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast<Geom::SVGEllipticalArc *>(c)) { -// //get at the innards and spit them out as svgd -// } - else { - //this case handles sbasis as well as all other curve types - Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); - - //recurse to convert the new path resulting from the sbasis to svgd - for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { - curve_to_svgd(f, &(*iter)); - } - } -} - -static void write_svgd(std::ostream & f, Geom::Path const &p) { - if(f == NULL) { - f << "ERRRRRRORRRRR"; - return; - } - - f << boost::format("M %g,%g ") % p.initialPoint()[0] % p.initialPoint()[1]; - - for(Geom::Path::const_iterator iter(p.begin()), end(p.end()); iter != end; ++iter) { - curve_to_svgd(f, &(*iter)); - } - if(p.closed()) - f << "Z "; -} - -static void write_svgd(std::ostream & f, std::vector<Geom::Path> const &p) { - std::vector<Geom::Path>::const_iterator it(p.begin()); - for(; it != p.end(); it++) { - write_svgd(f, *it); - } -} - -std::vector<Geom::Path> -SVGD_to_2GeomPath (char const *svgd) -{ - std::vector<Geom::Path> pathv; - - try { - pathv = Geom::parse_svg_path(svgd); - } - catch (std::runtime_error e) { - g_warning("SVGPathParseError: %s", e.what()); - } - - return pathv; -} std::vector<Geom::Path> @@ -99,26 +26,15 @@ BPath_to_2GeomPath(NArtBpath const * bpath) g_warning("BPath_to_2GeomPath - empty path returned"); return pathv; } - pathv = SVGD_to_2GeomPath(svgpath); + pathv = sp_svg_read_pathv(svgpath); g_free(svgpath); return pathv; } -char * -SVGD_from_2GeomPath(std::vector<Geom::Path> const & path) -{ - std::ostringstream ss; - write_svgd(ss, path); - ss.flush(); - std::string str = ss.str(); - char * svgd = g_strdup(str.c_str()); - return svgd; -} - NArtBpath * BPath_from_2GeomPath(std::vector<Geom::Path> const & path) { - char * svgd = SVGD_from_2GeomPath(path); + char * svgd = sp_svg_write_path(path); NArtBpath *bpath = sp_svg_read_path(svgd); g_free(svgd); return bpath; diff --git a/src/libnr/n-art-bpath-2geom.h b/src/libnr/n-art-bpath-2geom.h index 21995656b..bf1592e28 100644 --- a/src/libnr/n-art-bpath-2geom.h +++ b/src/libnr/n-art-bpath-2geom.h @@ -13,9 +13,7 @@ #include <2geom/path.h> #include <libnr/n-art-bpath.h> -std::vector<Geom::Path> SVGD_to_2GeomPath (char const *svgd); std::vector<Geom::Path> BPath_to_2GeomPath (NArtBpath const *bpath); -char * SVGD_from_2GeomPath(std::vector<Geom::Path> const & path); NArtBpath * BPath_from_2GeomPath (std::vector<Geom::Path> const & path); diff --git a/src/libnr/nr-convert2geom.h b/src/libnr/nr-convert2geom.h index 7741e7782..5e6021569 100644 --- a/src/libnr/nr-convert2geom.h +++ b/src/libnr/nr-convert2geom.h @@ -9,16 +9,36 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <2geom/matrix.h> #include <libnr/nr-matrix.h> -#include <2geom/d2.h> #include <libnr/nr-rect.h> +#include <libnr/nr-point.h> +#include <2geom/matrix.h> +#include <2geom/d2.h> +#include <2geom/transforms.h> +#include <2geom/point.h> + +inline Geom::Point to_2geom(NR::Point const & _pt) { + return Geom::Point(_pt[0], _pt[1]); +} + +inline NR::Point from_2geom(Geom::Point const & _pt) { + return NR::Point(_pt[0], _pt[1]); +} inline Geom::Matrix to_2geom(NR::Matrix const & mat) { Geom::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); return mat2geom; } +inline NR::Matrix from_2geom(Geom::Matrix const & mat) { + NR::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); + return mat2geom; +} + +inline Geom::Translate to_2geom(NR::translate const & mat) { + return Geom::Translate( mat.offset[0], mat.offset[1] ); +} + inline NR::Rect from_2geom(Geom::Rect const & rect2geom) { NR::Rect rect(rect2geom.min(), rect2geom.max()); return rect; diff --git a/src/libnr/nr-point-fns-test.cpp b/src/libnr/nr-point-fns-test.cpp index 11181436b..00a704b59 100644 --- a/src/libnr/nr-point-fns-test.cpp +++ b/src/libnr/nr-point-fns-test.cpp @@ -24,8 +24,8 @@ int main(int argc, char *argv[]) Point const part_nan(3., nan); Point const inf_left(-inf, 5.0); - assert(isNaN(nan)); - assert(!isNaN(small)); + assert(IS_NAN(nan)); + assert(!IS_NAN(small)); UTEST_TEST("L1") { UTEST_ASSERT( NR::L1(p0) == 0.0 ); @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) UTEST_ASSERT( NR::L1(small_left) == small ); UTEST_ASSERT( NR::L1(inf_left) == inf ); UTEST_ASSERT( NR::L1(small_n3_4) == 7.0 * small ); - UTEST_ASSERT(isNaN(NR::L1(part_nan))); + UTEST_ASSERT(IS_NAN(NR::L1(part_nan))); } UTEST_TEST("L2") { @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) UTEST_ASSERT( NR::L2(small_left) == small ); UTEST_ASSERT( NR::L2(inf_left) == inf ); UTEST_ASSERT( NR::L2(small_n3_4) == 5.0 * small ); - UTEST_ASSERT(isNaN(NR::L2(part_nan))); + UTEST_ASSERT(IS_NAN(NR::L2(part_nan))); } UTEST_TEST("LInfty") { @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) UTEST_ASSERT( NR::LInfty(small_left) == small ); UTEST_ASSERT( NR::LInfty(inf_left) == inf ); UTEST_ASSERT( NR::LInfty(small_n3_4) == 4.0 * small ); - UTEST_ASSERT(isNaN(NR::LInfty(part_nan))); + UTEST_ASSERT(IS_NAN(NR::LInfty(part_nan))); } UTEST_TEST("is_zero") { diff --git a/src/libnr/nr-point-fns-test.h b/src/libnr/nr-point-fns-test.h index 509d9d2fa..a94ef1b73 100644 --- a/src/libnr/nr-point-fns-test.h +++ b/src/libnr/nr-point-fns-test.h @@ -26,11 +26,11 @@ public: part_nan( 3., nan ), inf_left( -inf, 5.0 ) { - TS_ASSERT( isNaN(nan) ); - TS_ASSERT( !isNaN(small) ); + TS_ASSERT( IS_NAN(nan) ); + TS_ASSERT( !IS_NAN(small) ); - setupValid &= isNaN(nan); - setupValid &= !isNaN(small); + setupValid &= IS_NAN(nan); + setupValid &= !IS_NAN(small); } virtual ~NrPointFnsTest() {} @@ -65,7 +65,7 @@ public: TS_ASSERT_EQUALS( NR::L1(small_left), small ); TS_ASSERT_EQUALS( NR::L1(inf_left), inf ); TS_ASSERT_EQUALS( NR::L1(small_n3_4), 7.0 * small ); - TS_ASSERT(isNaN(NR::L1(part_nan))); + TS_ASSERT(IS_NAN(NR::L1(part_nan))); } void testL2(void) @@ -75,7 +75,7 @@ public: TS_ASSERT_EQUALS( NR::L2(small_left), small ); TS_ASSERT_EQUALS( NR::L2(inf_left), inf ); TS_ASSERT_EQUALS( NR::L2(small_n3_4), 5.0 * small ); - TS_ASSERT( isNaN(NR::L2(part_nan)) ); + TS_ASSERT( IS_NAN(NR::L2(part_nan)) ); } void testLInfty(void) @@ -85,7 +85,7 @@ public: TS_ASSERT_EQUALS( NR::LInfty(small_left), small ); TS_ASSERT_EQUALS( NR::LInfty(inf_left), inf ); TS_ASSERT_EQUALS( NR::LInfty(small_n3_4), 4.0 * small ); - TS_ASSERT( isNaN(NR::LInfty(part_nan)) ); + TS_ASSERT( IS_NAN(NR::LInfty(part_nan)) ); } void testIsZero(void) diff --git a/src/libnr/nr-point-fns.cpp b/src/libnr/nr-point-fns.cpp index a7b128bdb..f73f71e3b 100644 --- a/src/libnr/nr-point-fns.cpp +++ b/src/libnr/nr-point-fns.cpp @@ -7,7 +7,7 @@ using NR::Point; NR::Coord NR::LInfty(Point const &p) { NR::Coord const a(fabs(p[0])); NR::Coord const b(fabs(p[1])); - return ( a < b || isNaN(b) + return ( a < b || IS_NAN(b) ? b : a ); } diff --git a/src/libnr/nr-types.cpp b/src/libnr/nr-types.cpp index 98054a551..a4e16d127 100644 --- a/src/libnr/nr-types.cpp +++ b/src/libnr/nr-types.cpp @@ -18,7 +18,7 @@ void NR::Point::normalize() { double len = hypot(_pt[0], _pt[1]); g_return_if_fail(len != 0); - g_return_if_fail(!isNaN(len)); + g_return_if_fail(!IS_NAN(len)); static double const inf = 1e400; if(len != inf) { *this /= len; |
