diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/bezctx.h | 5 | ||||
| -rw-r--r-- | src/live_effects/bezctx_intf.h | 5 | ||||
| -rw-r--r-- | src/live_effects/lpe-spiro.cpp | 78 | ||||
| -rw-r--r-- | src/live_effects/spiro.cpp | 95 | ||||
| -rw-r--r-- | src/live_effects/spiro.h | 51 |
5 files changed, 146 insertions, 88 deletions
diff --git a/src/live_effects/bezctx.h b/src/live_effects/bezctx.h index 057312e5a..df074676e 100644 --- a/src/live_effects/bezctx.h +++ b/src/live_effects/bezctx.h @@ -1,3 +1,6 @@ +#ifndef INKSCAPE_SPIRO_bezctx_H +#define INKSCAPE_SPIRO_bezctx_H + #include "bezctx_intf.h" struct _bezctx { @@ -8,3 +11,5 @@ struct _bezctx { double x3, double y3); void (*mark_knot)(bezctx *bc, int knot_idx); }; + +#endif diff --git a/src/live_effects/bezctx_intf.h b/src/live_effects/bezctx_intf.h index a47b8ef5a..05ea79a63 100644 --- a/src/live_effects/bezctx_intf.h +++ b/src/live_effects/bezctx_intf.h @@ -1,3 +1,6 @@ +#ifndef INKSCAPE_SPIRO_bezctx_intf_H +#define INKSCAPE_SPIRO_bezctx_intf_H + typedef struct _bezctx bezctx; bezctx * @@ -18,3 +21,5 @@ bezctx_curveto(bezctx *bc, double x1, double y1, double x2, double y2, void bezctx_mark_knot(bezctx *bc, int knot_idx); + +#endif diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 22974fe13..7f700bddd 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -15,8 +15,6 @@ #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" -#include "live_effects/bezctx.h" -#include "live_effects/bezctx_intf.h" #include "live_effects/spiro.h" // For handling un-continuous paths: @@ -24,82 +22,6 @@ #include "inkscape.h" #include "desktop.h" -#define SPIRO_SHOW_INFINITE_COORDINATE_CALLS - -typedef struct { - bezctx base; - SPCurve *curve; - int is_open; -} bezctx_ink; - -void bezctx_ink_moveto(bezctx *bc, double x, double y, int /*is_open*/) -{ - bezctx_ink *bi = (bezctx_ink *) bc; - if ( IS_FINITE(x) && IS_FINITE(y) ) { - bi->curve->moveto(x, y); - } -#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS - else { - g_message("lpe moveto not finite"); - } -#endif -} - -void bezctx_ink_lineto(bezctx *bc, double x, double y) -{ - bezctx_ink *bi = (bezctx_ink *) bc; - if ( IS_FINITE(x) && IS_FINITE(y) ) { - bi->curve->lineto(x, y); - } -#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS - else { - g_message("lpe lineto not finite"); - } -#endif -} - -void bezctx_ink_quadto(bezctx *bc, double xm, double ym, double x3, double y3) -{ - bezctx_ink *bi = (bezctx_ink *) bc; - - if ( IS_FINITE(xm) && IS_FINITE(ym) && IS_FINITE(x3) && IS_FINITE(y3) ) { - bi->curve->quadto(xm, ym, x3, y3); - } -#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS - else { - g_message("lpe quadto not finite"); - } -#endif -} - -void bezctx_ink_curveto(bezctx *bc, double x1, double y1, double x2, double y2, - double x3, double y3) -{ - bezctx_ink *bi = (bezctx_ink *) bc; - if ( IS_FINITE(x1) && IS_FINITE(y1) && IS_FINITE(x2) && IS_FINITE(y2) ) { - bi->curve->curveto(x1, y1, x2, y2, x3, y3); - } -#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS - else { - g_message("lpe curveto not finite"); - } -#endif -} - -bezctx * -new_bezctx_ink(SPCurve *curve) { - bezctx_ink *result = g_new(bezctx_ink, 1); - result->base.moveto = bezctx_ink_moveto; - result->base.lineto = bezctx_ink_lineto; - result->base.quadto = bezctx_ink_quadto; - result->base.curveto = bezctx_ink_curveto; - result->base.mark_knot = NULL; - result->curve = curve; - return &result->base; -} - - - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index b98e12213..b916a2cf7 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -1,6 +1,8 @@ /* -ppedit - A pattern plate editor for Spiro splines. -Copyright (C) 2007 Raph Levien +Copyright (C) 2007-2012 Authors + +Authors: Raph Levien + Johan Engelen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,12 +22,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */ /* C implementation of third-order polynomial spirals. */ +#include "spiro.h" + #include <math.h> #include <stdlib.h> #include <string.h> #include "bezctx_intf.h" -#include "spiro.h" +#include "display/curve.h" +#include <2geom/math-utils.h> + +#define SPIRO_SHOW_INFINITE_COORDINATE_CALLS + + +/************************************ + * Spiro math + */ struct spiro_seg_s { double x; @@ -922,6 +934,83 @@ get_knot_th(const spiro_seg *s, int i) } } + +/************************************ + * Conversion to Inkscape's curve + */ + +void bezctx_ink_moveto(bezctx *bc, double x, double y, int /*is_open*/) +{ + bezctx_ink *bi = (bezctx_ink *) bc; + if ( IS_FINITE(x) && IS_FINITE(y) ) { + bi->curve->moveto(x, y); + } +#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS + else { + g_message("Spiro: moveto not finite"); + } +#endif +} + +void bezctx_ink_lineto(bezctx *bc, double x, double y) +{ + bezctx_ink *bi = (bezctx_ink *) bc; + if ( IS_FINITE(x) && IS_FINITE(y) ) { + bi->curve->lineto(x, y); + } +#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS + else { + g_message("Spiro: lineto not finite"); + } +#endif +} + +void bezctx_ink_quadto(bezctx *bc, double xm, double ym, double x3, double y3) +{ + bezctx_ink *bi = (bezctx_ink *) bc; + + if ( IS_FINITE(xm) && IS_FINITE(ym) && IS_FINITE(x3) && IS_FINITE(y3) ) { + bi->curve->quadto(xm, ym, x3, y3); + } +#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS + else { + g_message("Spiro: quadto not finite"); + } +#endif +} + +void bezctx_ink_curveto(bezctx *bc, double x1, double y1, double x2, double y2, + double x3, double y3) +{ + bezctx_ink *bi = (bezctx_ink *) bc; + if ( IS_FINITE(x1) && IS_FINITE(y1) && IS_FINITE(x2) && IS_FINITE(y2) ) { + bi->curve->curveto(x1, y1, x2, y2, x3, y3); + } +#ifdef SPIRO_SHOW_INFINITE_COORDINATE_CALLS + else { + g_message("Spiro: curveto not finite"); + } +#endif +} + +bezctx * new_bezctx_ink(SPCurve *curve) +{ + bezctx_ink *result = g_new(bezctx_ink, 1); + result->base.moveto = bezctx_ink_moveto; + result->base.lineto = bezctx_ink_lineto; + result->base.quadto = bezctx_ink_quadto; + result->base.curveto = bezctx_ink_curveto; + result->base.mark_knot = NULL; + result->curve = curve; + return &result->base; +} + + +/************************************ + * Unit_test code + */ + + #ifdef UNIT_TEST #include <stdio.h> #include <sys/time.h> /* for gettimeofday */ diff --git a/src/live_effects/spiro.h b/src/live_effects/spiro.h index 54de40465..f39fbded6 100644 --- a/src/live_effects/spiro.h +++ b/src/live_effects/spiro.h @@ -1,3 +1,34 @@ +/* +Copyright (C) 2007-2012 Authors + +Authors: Raph Levien + Johan Engelen + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. + +*/ + +#ifndef INKSCAPE_SPIRO_H +#define INKSCAPE_SPIRO_H + +#include "live_effects/bezctx.h" +#include "live_effects/bezctx_intf.h" + +class SPCurve; + typedef struct { double x; double y; @@ -6,13 +37,19 @@ typedef struct { typedef struct spiro_seg_s spiro_seg; -spiro_seg * -run_spiro(const spiro_cp *src, int n); +spiro_seg * run_spiro(const spiro_cp *src, int n); +void free_spiro(spiro_seg *s); +void spiro_to_bpath(const spiro_seg *s, int n, bezctx *bc); +double get_knot_th(const spiro_seg *s, int i); -void -free_spiro(spiro_seg *s); -void -spiro_to_bpath(const spiro_seg *s, int n, bezctx *bc); +typedef struct { + bezctx base; + SPCurve *curve; + int is_open; +} bezctx_ink; -double get_knot_th(const spiro_seg *s, int i); +bezctx * new_bezctx_ink(SPCurve *curve); + + +#endif // INKSCAPE_SPIRO_H
\ No newline at end of file |
