Code

- try to use more forward declarations for less dependencies on display/curve.h
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 9 May 2008 09:37:08 +0000 (09:37 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 9 May 2008 09:37:08 +0000 (09:37 +0000)
- change _bpath to private member of SPCurve, obtain and set with get_bpath and set_bpath.
- added const methods, so protect changes to _bpath in SPCurve

46 files changed:
src/connector-context.cpp
src/connector-context.h
src/display/canvas-axonomgrid.h
src/display/canvas-bpath.cpp
src/display/canvas-grid.h
src/display/curve.cpp
src/display/curve.h
src/display/display-forward.h
src/display/nr-arena-glyphs.h
src/display/nr-arena-shape.cpp
src/display/nr-arena-shape.h
src/draw-context.cpp
src/draw-context.h
src/dyna-draw-context.cpp
src/dyna-draw-context.h
src/eraser-context.cpp
src/extension/internal/pov-out.cpp
src/libnrtype/Layout-TNG-Output.cpp
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-bendpath.cpp
src/live_effects/lpe-curvestitch.cpp
src/live_effects/lpe-knot.cpp
src/live_effects/lpe-perspective_path.cpp
src/live_effects/lpe-skeleton.cpp
src/live_effects/lpe-skeleton.h
src/live_effects/lpe-sketch.cpp
src/live_effects/lpe-slant.cpp
src/live_effects/lpe-spiro.cpp
src/live_effects/lpe-vonkoch.cpp
src/live_effects/lpegroupbbox.cpp
src/live_effects/parameter/path-reference.cpp
src/nodepath.cpp
src/object-snapper.cpp
src/object-snapper.h
src/path-chemistry.cpp
src/pen-context.cpp
src/pencil-context.cpp
src/sp-lpe-item.h
src/sp-path.cpp
src/sp-polygon.cpp
src/sp-shape.cpp
src/splivarot.cpp
src/tweak-context.cpp
src/tweak-context.h
src/verbs.cpp

index 07e512e064aa6d85d0a3f9ac7eb08156b1cf298a..3c1669fa6e4e1a3b0a3d9044af67da4148fb6e1c 100644 (file)
@@ -73,7 +73,7 @@
 #include "sp-namedview.h"
 #include "sp-text.h"
 #include "sp-flowtext.h"
-
+#include "display/curve.h"
 
 static void sp_connector_context_class_init(SPConnectorContextClass *klass);
 static void sp_connector_context_init(SPConnectorContext *conn_context);
@@ -1252,7 +1252,7 @@ static bool cc_item_is_shape(SPItem *item)
 {
     if (SP_IS_PATH(item)) {
         SPCurve *curve = (SP_SHAPE(item))->curve;
-        if ( curve && !(curve->closed) ) {
+        if ( curve && !(curve->is_closed()) ) {
             // Open paths are connectors.
             return false;
         }
@@ -1271,7 +1271,7 @@ bool cc_item_is_connector(SPItem *item)
 {
     if (SP_IS_PATH(item)) {
         if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) {
-            g_assert( !(SP_SHAPE(item)->curve->closed) );
+            g_assert( !(SP_SHAPE(item)->curve->is_closed()) );
             return true;
         }
     }
index 49c4c2a814c2e970cc1792caeef0cb8a97aefe2b..e8d9a4390d5073b21a5122760ff42c51df86afc6 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <sigc++/sigc++.h>
 #include <sigc++/connection.h>
-#include "display/curve.h"
 #include "event-context.h"
 #include <forward.h>
 #include <display/display-forward.h>
index 6c39860b9b5a5ca99d3e667722f36ef7ed674bdc..668c59649b08bdb736a3e1a208bde677ade85d67 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "ui/widget/registered-widget.h"
 #include "ui/widget/registry.h"
-//#include "ui/widget/tolerance-slider.h"
 
 #include "xml/node-event-vector.h"
 
index 6aa4136237ecddd8c0957914b0594b079475bc74..a3327308c6e1eb7a58f6c57f509fd42537d0b569 100644 (file)
@@ -142,7 +142,7 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
         Path*  thePath=new Path;
         thePath->LoadArtBPath(SP_CURVE_BPATH(cbp->curve), affine, true);
         thePath->Convert(0.25);
-        if ((cbp->fill_rgba & 0xff) && (cbp->curve->end > 2)) {
+        if ((cbp->fill_rgba & 0xff) && (cbp->curve->_end > 2)) {
             Shape* theShape=new Shape;
             thePath->Fill(theShape,0);
             if ( cbp->fill_shp == NULL ) cbp->fill_shp=new Shape;
@@ -165,7 +165,7 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
                 }
             }
         }
-        if ((cbp->stroke_rgba & 0xff) && (cbp->curve->end > 1)) {
+        if ((cbp->stroke_rgba & 0xff) && (cbp->curve->_end > 1)) {
             JoinType join=join_straight;
 //      Shape* theShape=new Shape;
             ButtType butt=butt_straight;
index 0ff2c65f1fdf953a040284a5ca4ad1cffe7f07fc..a9e317534b90dd12740b80b49aef5681741f8786 100644 (file)
@@ -23,7 +23,6 @@
 #include "ui/widget/scalar-unit.h"
 #include "ui/widget/registered-widget.h"
 #include "ui/widget/registry.h"
-//#include "ui/widget/tolerance-slider.h"
 #include "xml/node-event-vector.h"
 #include "snapper.h"
 #include "line-snapper.h"
index e97b097443c6f040f4456a919e26842d667a5c32..5b2ac024b8d39379cd7280b48e3652536cfae620 100644 (file)
@@ -16,7 +16,7 @@
  * Released under GNU GPL
  */
 
-#include <display/curve.h>
+#include "display/curve.h"
 
 #include <string.h>
 #include <glib/gmem.h>
@@ -38,16 +38,16 @@ static bool sp_bpath_closed(NArtBpath const bpath[]);
  * \param length Initial number of NArtBpath elements allocated for bpath (including NR_END
  *    element).
  */
-SPCurve::SPCurve(gint length)
-  : refcount(1),
+SPCurve::SPCurve(guint length)
+  : _refcount(1),
     _bpath(NULL),
-    end(0),
-    length(length),
-    substart(0),
-    hascpt(false),
-    posSet(false),
-    moving(false),
-    closed(false)
+    _end(0),
+    _length(length),
+    _substart(0),
+    _hascpt(false),
+    _posSet(false),
+    _moving(false),
+    _closed(false)
 {
     if (length <= 0) {
         g_error("SPCurve::SPCurve called with invalid length parameter");
@@ -71,15 +71,15 @@ SPCurve::new_from_foreign_bpath(NArtBpath const *bpath)
     SPCurve *curve = new SPCurve();
 
     curve->_bpath = new_bpath;
-    curve->length = len;
-    curve->end = curve->length - 1;
-    gint i = curve->end;
+    curve->_length = len;
+    curve->_end = curve->_length - 1;
+    gint i = curve->_end;
     for (; i > 0; i--)
         if ((curve->_bpath[i].code == NR_MOVETO) ||
             (curve->_bpath[i].code == NR_MOVETO_OPEN))
             break;
-    curve->substart = i;
-    curve->closed = sp_bpath_closed(new_bpath);
+    curve->_substart = i;
+    curve->_closed = sp_bpath_closed(new_bpath);
 
     return curve;
 }
@@ -128,7 +128,36 @@ SPCurve::~SPCurve()
 /* Methods */
 
 /**
- * Increase refcount of curve.
+ * Frees old path and sets new path
+ * This does not copy the bpath, so the new_bpath should not be deleted by caller
+ */
+void
+SPCurve::set_bpath(NArtBpath * new_bpath)
+{
+    if (new_bpath && new_bpath != _bpath) {        // FIXME, add function to SPCurve to change bpath? or a copy function?
+        if (_bpath) {
+            g_free(_bpath); //delete old bpath
+        }
+        _bpath = new_bpath;
+    }
+}
+
+/**
+ * Get pointer to bpath data. Don't keep this reference too long, because the path might change by another function.
+ */
+NArtBpath const *
+SPCurve::get_bpath() const
+{
+    return _bpath;
+};
+NArtBpath *
+SPCurve::get_bpath()
+{
+    return _bpath;
+};
+
+/**
+ * Increase _refcount of curve.
  *
  * \todo should this be shared with other refcounting code?
  */
@@ -137,7 +166,7 @@ SPCurve::ref()
 {
     g_return_val_if_fail(this != NULL, NULL);
 
-    refcount += 1;
+    _refcount += 1;
 
     return this;
 }
@@ -152,9 +181,9 @@ SPCurve::unref()
 {
     g_return_val_if_fail(this != NULL, NULL);
 
-    refcount -= 1;
+    _refcount -= 1;
 
-    if (refcount < 1) {
+    if (_refcount < 1) {
         if (_bpath) {
             g_free(_bpath);
             _bpath = NULL;
@@ -168,21 +197,21 @@ SPCurve::unref()
 /**
  * Add space for more paths in curve.
  */
-static void
-sp_curve_ensure_space(SPCurve *curve, gint space)
+void
+SPCurve::ensure_space(guint space)
 {
-    g_return_if_fail(curve != NULL);
+    g_return_if_fail(this != NULL);
     g_return_if_fail(space > 0);
 
-    if (curve->end + space < curve->length)
+    if (_end + space < _length)
         return;
 
     if (space < SP_CURVE_LENSTEP)
         space = SP_CURVE_LENSTEP;
 
-    curve->_bpath = g_renew(NArtBpath, curve->_bpath, curve->length + space);
+    _bpath = g_renew(NArtBpath, _bpath, _length + space);
 
-    curve->length += space;
+    _length += space;
 }
 
 /**
@@ -208,7 +237,7 @@ SPCurve::concat(GSList const *list)
 
     for (GSList const *l = list; l != NULL; l = l->next) {
         SPCurve *c = (SPCurve *) l->data;
-        length += c->end;
+        length += c->_end;
     }
 
     SPCurve *new_curve = new SPCurve(length + 1);
@@ -217,21 +246,21 @@ SPCurve::concat(GSList const *list)
 
     for (GSList const *l = list; l != NULL; l = l->next) {
         SPCurve *c = (SPCurve *) l->data;
-        memcpy(bp, c->_bpath, c->end * sizeof(NArtBpath));
-        bp += c->end;
+        memcpy(bp, c->_bpath, c->_end * sizeof(NArtBpath));
+        bp += c->_end;
     }
 
     bp->code = NR_END;
 
-    new_curve->end = length;
+    new_curve->_end = length;
     gint i;
-    for (i = new_curve->end; i > 0; i--) {
+    for (i = new_curve->_end; i > 0; i--) {
         if ((new_curve->_bpath[i].code == NR_MOVETO)     ||
             (new_curve->_bpath[i].code == NR_MOVETO_OPEN)  )
             break;
     }
 
-    new_curve->substart = i;
+    new_curve->_substart = i;
 
     return new_curve;
 }
@@ -247,18 +276,18 @@ SPCurve::split() const
     gint p = 0;
     GSList *l = NULL;
 
-    while (p < end) {
+    while (p < _end) {
         gint i = 1;
         while ((_bpath[p + i].code == NR_LINETO) ||
                (_bpath[p + i].code == NR_CURVETO))
             i++;
         SPCurve *new_curve = new SPCurve(i + 1);
         memcpy(new_curve->_bpath, _bpath + p, i * sizeof(NArtBpath));
-        new_curve->end = i;
+        new_curve->_end = i;
         new_curve->_bpath[i].code = NR_END;
-        new_curve->substart = 0;
-        new_curve->closed = (new_curve->_bpath->code == NR_MOVETO);
-        new_curve->hascpt = (new_curve->_bpath->code == NR_MOVETO_OPEN);
+        new_curve->_substart = 0;
+        new_curve->_closed = (new_curve->_bpath->code == NR_MOVETO);
+        new_curve->_hascpt = (new_curve->_bpath->code == NR_MOVETO_OPEN);
         l = g_slist_prepend(l, new_curve);
         p += i;
     }
@@ -275,7 +304,7 @@ tmpl_curve_transform(SPCurve *const curve, M const &m)
 {
     g_return_if_fail(curve != NULL);
 
-    for (gint i = 0; i < curve->end; i++) {
+    for (gint i = 0; i < curve->_end; i++) {
         NArtBpath *p = curve->_bpath + i;
         switch (p->code) {
             case NR_MOVETO:
@@ -323,12 +352,12 @@ SPCurve::reset()
     g_return_if_fail(this != NULL);
 
     _bpath->code = NR_END;
-    end = 0;
-    substart = 0;
-    hascpt = false;
-    posSet = false;
-    moving = false;
-    closed = false;
+    _end = 0;
+    _substart = 0;
+    _hascpt = false;
+    _posSet = false;
+    _moving = false;
+    _closed = false;
 }
 
 /* Several consecutive movetos are ALLOWED */
@@ -349,12 +378,12 @@ void
 SPCurve::moveto(NR::Point const &p)
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(!moving);
+    g_return_if_fail(!_moving);
 
-    substart = end;
-    hascpt = true;
-    posSet = true;
-    movePos = p;
+    _substart = _end;
+    _hascpt = true;
+    _posSet = true;
+    _movePos = p;
 }
 
 /**
@@ -373,49 +402,49 @@ void
 SPCurve::lineto(gdouble x, gdouble y)
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(hascpt);
+    g_return_if_fail(_hascpt);
 
-    if (moving) {
+    if (_moving) {
         /* fix endpoint */
-        g_return_if_fail(!posSet);
-        g_return_if_fail(end > 1);
-        NArtBpath *bp = _bpath + end - 1;
+        g_return_if_fail(!_posSet);
+        g_return_if_fail(_end > 1);
+        NArtBpath *bp = _bpath + _end - 1;
         g_return_if_fail(bp->code == NR_LINETO);
         bp->x3 = x;
         bp->y3 = y;
-        moving = false;
+        _moving = false;
         return;
     }
 
-    if (posSet) {
+    if (_posSet) {
         /* start a new segment */
-        sp_curve_ensure_space(this, 2);
-        NArtBpath *bp = _bpath + end;
+        ensure_space(2);
+        NArtBpath *bp = _bpath + _end;
         bp->code = NR_MOVETO_OPEN;
-        bp->setC(3, movePos);
+        bp->setC(3, _movePos);
         bp++;
         bp->code = NR_LINETO;
         bp->x3 = x;
         bp->y3 = y;
         bp++;
         bp->code = NR_END;
-        end += 2;
-        posSet = false;
-        closed = false;
+        _end += 2;
+        _posSet = false;
+        _closed = false;
         return;
     }
 
     /* add line */
 
-    g_return_if_fail(end > 1);
-    sp_curve_ensure_space(this, 1);
-    NArtBpath *bp = _bpath + end;
+    g_return_if_fail(_end > 1);
+    ensure_space(1);
+    NArtBpath *bp = _bpath + _end;
     bp->code = NR_LINETO;
     bp->x3 = x;
     bp->y3 = y;
     bp++;
     bp->code = NR_END;
-    end++;
+    _end++;
 }
 
 /// Unused
@@ -423,50 +452,50 @@ void
 SPCurve::lineto_moving(gdouble x, gdouble y)
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(hascpt);
+    g_return_if_fail(_hascpt);
 
-    if (moving) {
+    if (_moving) {
         /* change endpoint */
-        g_return_if_fail(!posSet);
-        g_return_if_fail(end > 1);
-        NArtBpath *bp = _bpath + end - 1;
+        g_return_if_fail(!_posSet);
+        g_return_if_fail(_end > 1);
+        NArtBpath *bp = _bpath + _end - 1;
         g_return_if_fail(bp->code == NR_LINETO);
         bp->x3 = x;
         bp->y3 = y;
         return;
     }
 
-    if (posSet) {
+    if (_posSet) {
         /* start a new segment */
-        sp_curve_ensure_space(this, 2);
-        NArtBpath *bp = _bpath + end;
+        ensure_space(2);
+        NArtBpath *bp = _bpath + _end;
         bp->code = NR_MOVETO_OPEN;
-        bp->setC(3, movePos);
+        bp->setC(3, _movePos);
         bp++;
         bp->code = NR_LINETO;
         bp->x3 = x;
         bp->y3 = y;
         bp++;
         bp->code = NR_END;
-        end += 2;
-        posSet = false;
-        moving = true;
-        closed = false;
+        _end += 2;
+        _posSet = false;
+        _moving = true;
+        _closed = false;
         return;
     }
 
     /* add line */
 
-    g_return_if_fail(end > 1);
-    sp_curve_ensure_space(this, 1);
-    NArtBpath *bp = _bpath + end;
+    g_return_if_fail(_end > 1);
+    ensure_space(1);
+    NArtBpath *bp = _bpath + _end;
     bp->code = NR_LINETO;
     bp->x3 = x;
     bp->y3 = y;
     bp++;
     bp->code = NR_END;
-    end++;
-    moving = true;
+    _end++;
+    _moving = true;
 }
 
 /**
@@ -489,15 +518,15 @@ void
 SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2)
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(hascpt);
-    g_return_if_fail(!moving);
+    g_return_if_fail(_hascpt);
+    g_return_if_fail(!_moving);
 
-    if (posSet) {
+    if (_posSet) {
         /* start a new segment */
-        sp_curve_ensure_space(this, 2);
-        NArtBpath *bp = _bpath + end;
+        ensure_space(2);
+        NArtBpath *bp = _bpath + _end;
         bp->code = NR_MOVETO_OPEN;
-        bp->setC(3, movePos);
+        bp->setC(3, _movePos);
         bp++;
         bp->code = NR_CURVETO;
         bp->x1 = x0;
@@ -508,17 +537,17 @@ SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdo
         bp->y3 = y2;
         bp++;
         bp->code = NR_END;
-        end += 2;
-        posSet = false;
-        closed = false;
+        _end += 2;
+        _posSet = false;
+        _closed = false;
         return;
     }
 
     /* add curve */
 
-    g_return_if_fail(end > 1);
-    sp_curve_ensure_space(this, 1);
-    NArtBpath *bp = _bpath + end;
+    g_return_if_fail(_end > 1);
+    ensure_space(1);
+    NArtBpath *bp = _bpath + _end;
     bp->code = NR_CURVETO;
     bp->x1 = x0;
     bp->y1 = y0;
@@ -528,7 +557,7 @@ SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdo
     bp->y3 = y2;
     bp++;
     bp->code = NR_END;
-    end++;
+    _end++;
 }
 
 /**
@@ -538,25 +567,25 @@ void
 SPCurve::closepath()
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(hascpt);
-    g_return_if_fail(!posSet);
-    g_return_if_fail(!moving);
-    g_return_if_fail(!closed);
+    g_return_if_fail(_hascpt);
+    g_return_if_fail(!_posSet);
+    g_return_if_fail(!_moving);
+    g_return_if_fail(!_closed);
     /* We need at least moveto, curveto, end. */
-    g_return_if_fail(end - substart > 1);
+    g_return_if_fail(_end - _substart > 1);
 
     {
-        NArtBpath *bs = _bpath + substart;
-        NArtBpath *be = _bpath + end - 1;
+        NArtBpath *bs = _bpath + _substart;
+        NArtBpath *be = _bpath + _end - 1;
 
         if (bs->c(3) != be->c(3)) {
             lineto(bs->c(3));
-            bs = _bpath + substart;
+            bs = _bpath + _substart;
         }
 
         bs->code = NR_MOVETO;
     }
-    closed = true;
+    _closed = true;
 
     for (NArtBpath const *bp = _bpath; bp->code != NR_END; bp++) {
         /** \todo
@@ -564,12 +593,12 @@ SPCurve::closepath()
          * the closed boolean).
          */
         if (bp->code == NR_MOVETO_OPEN) {
-            closed = false;
+            _closed = false;
             break;
         }
     }
 
-    hascpt = false;
+    _hascpt = false;
 }
 
 /** Like SPCurve::closepath() but sets the end point of the current
@@ -581,22 +610,22 @@ void
 SPCurve::closepath_current()
 {
     g_return_if_fail(this != NULL);
-    g_return_if_fail(hascpt);
-    g_return_if_fail(!posSet);
-    g_return_if_fail(!closed);
+    g_return_if_fail(_hascpt);
+    g_return_if_fail(!_posSet);
+    g_return_if_fail(!_closed);
     /* We need at least moveto, curveto, end. */
-    g_return_if_fail(end - substart > 1);
+    g_return_if_fail(_end - _substart > 1);
 
     {
-        NArtBpath *bs = _bpath + substart;
-        NArtBpath *be = _bpath + end - 1;
+        NArtBpath *bs = _bpath + _substart;
+        NArtBpath *be = _bpath + _end - 1;
 
         be->x3 = bs->x3;
         be->y3 = bs->y3;
 
         bs->code = NR_MOVETO;
     }
-    closed = true;
+    _closed = true;
 
     for (NArtBpath const *bp = _bpath; bp->code != NR_END; bp++) {
         /** \todo
@@ -604,13 +633,13 @@ SPCurve::closepath_current()
          * the closed boolean).
          */
         if (bp->code == NR_MOVETO_OPEN) {
-            closed = false;
+            _closed = false;
             break;
         }
     }
 
-    hascpt = false;
-    moving = false;
+    _hascpt = false;
+    _moving = false;
 }
 
 /**
@@ -624,6 +653,15 @@ SPCurve::is_empty() const
     return (_bpath->code == NR_END);
 }
 
+/**
+ * True iff all subpaths are closed.
+ */
+bool
+SPCurve::is_closed() const
+{
+    return _closed;
+}
+
 /**
  * Return last subpath or NULL.
  */
@@ -632,11 +670,11 @@ SPCurve::last_bpath() const
 {
     g_return_val_if_fail(this != NULL, NULL);
 
-    if (end == 0) {
+    if (_end == 0) {
         return NULL;
     }
 
-    return _bpath + end - 1;
+    return _bpath + _end - 1;
 }
 
 /**
@@ -647,7 +685,7 @@ SPCurve::first_bpath() const
 {
     g_return_val_if_fail(this != NULL, NULL);
 
-    if (end == 0) {
+    if (_end == 0) {
         return NULL;
     }
 
@@ -666,19 +704,19 @@ SPCurve::first_point() const
 }
 
 /**
- * Return the second point of first subpath or movePos if curve too short.
+ * Return the second point of first subpath or _movePos if curve too short.
  */
 NR::Point
 SPCurve::second_point() const
 {
     g_return_val_if_fail(this != NULL, NR::Point(0, 0));
 
-    if (end < 1) {
-        return movePos;
+    if (_end < 1) {
+        return _movePos;
     }
 
     NArtBpath *bpath = NULL;
-    if (end < 2) {
+    if (_end < 2) {
         bpath = _bpath;
     } else {
         bpath = _bpath + 1;
@@ -688,18 +726,18 @@ SPCurve::second_point() const
 }
 
 /**
- * Return the second-last point of last subpath or movePos if curve too short.
+ * Return the second-last point of last subpath or _movePos if curve too short.
  */
 NR::Point
 SPCurve::penultimate_point() const
 {
     g_return_val_if_fail(this != NULL, NR::Point(0, 0));
 
-    if (end < 2) {
-        return movePos;
+    if (_end < 2) {
+        return _movePos;
     }
 
-    NArtBpath *const bpath = _bpath + end - 2;
+    NArtBpath *const bpath = _bpath + _end - 2;
     g_return_val_if_fail(bpath != NULL, NR::Point(0, 0));
     return bpath->c(3);
 }
@@ -722,30 +760,30 @@ is_moveto(NRPathcode const c)
 }
 
 /**
- * Returns \a curve but drawn in the opposite direction.
+ * Returns a *new* \a curve but drawn in the opposite direction.
  * Should result in the same shape, but
  * with all its markers drawn facing the other direction.
  **/
 SPCurve *
-SPCurve::reverse() const
+SPCurve::create_reverse() const
 {
     /* We need at least moveto, curveto, end. */
-    g_return_val_if_fail(end - substart > 1, NULL);
+    g_return_val_if_fail(_end - _substart > 1, NULL);
 
-    NArtBpath const *be = _bpath + end - 1;
+    NArtBpath const *be = _bpath + _end - 1;
 
-    g_assert(is_moveto(_bpath[substart].code));
+    g_assert(is_moveto(_bpath[_substart].code));
     g_assert(is_moveto(_bpath[0].code));
     g_assert((be+1)->code == NR_END);
 
-    SPCurve  *new_curve = new SPCurve(length);
+    SPCurve  *new_curve = new SPCurve(_length);
     new_curve->moveto(be->c(3));
 
     for (NArtBpath const *bp = be; ; --bp) {
         switch (bp->code) {
             case NR_MOVETO:
-                g_assert(new_curve->_bpath[new_curve->substart].code == NR_MOVETO_OPEN);
-                new_curve->_bpath[new_curve->substart].code = NR_MOVETO;
+                g_assert(new_curve->_bpath[new_curve->_substart].code == NR_MOVETO_OPEN);
+                new_curve->_bpath[new_curve->_substart].code = NR_MOVETO;
                 /* FALL-THROUGH */
             case NR_MOVETO_OPEN:
                 if (bp == _bpath) {
@@ -778,35 +816,35 @@ SPCurve::append(SPCurve const *curve2,
     g_return_if_fail(this != NULL);
     g_return_if_fail(curve2 != NULL);
 
-    if (curve2->end < 1)
+    if (curve2->_end < 1)
         return;
 
     NArtBpath const *bs = curve2->_bpath;
 
-    bool _closed = this->closed;
+    bool closed = this->_closed;
 
     for (NArtBpath const *bp = bs; bp->code != NR_END; bp++) {
         switch (bp->code) {
             case NR_MOVETO_OPEN:
-                if (use_lineto && hascpt) {
+                if (use_lineto && _hascpt) {
                     lineto(bp->x3, bp->y3);
                     use_lineto = FALSE;
                 } else {
-                    if (_closed) closepath();
+                    if (closed) closepath();
                     moveto(bp->x3, bp->y3);
                 }
-                _closed = false;
+                closed = false;
                 break;
 
             case NR_MOVETO:
-                if (use_lineto && hascpt) {
+                if (use_lineto && _hascpt) {
                     lineto(bp->x3, bp->y3);
                     use_lineto = FALSE;
                 } else {
-                    if (_closed) closepath();
+                    if (closed) closepath();
                     moveto(bp->x3, bp->y3);
                 }
-                _closed = true;
+                closed = true;
                 break;
 
             case NR_LINETO:
@@ -822,7 +860,7 @@ SPCurve::append(SPCurve const *curve2,
         }
     }
 
-    if (_closed) {
+    if (closed) {
         closepath();
     }
 }
@@ -835,10 +873,10 @@ SPCurve::append_continuous(SPCurve const *c1, gdouble tolerance)
 {
     g_return_val_if_fail(this != NULL, NULL);
     g_return_val_if_fail(c1 != NULL, NULL);
-    g_return_val_if_fail(!closed, NULL);
-    g_return_val_if_fail(!c1->closed, NULL);
+    g_return_val_if_fail(!_closed, NULL);
+    g_return_val_if_fail(!c1->_closed, NULL);
 
-    if (c1->end < 1) {
+    if (c1->_end < 1) {
         return this;
     }
 
@@ -853,18 +891,18 @@ SPCurve::append_continuous(SPCurve const *c1, gdouble tolerance)
              * fixme: Strictly we mess in case of multisegment mixed
              * open/close curves
              */
-            bool _closed = false;
+            bool closed = false;
             for (bs = bs + 1; bs->code != NR_END; bs++) {
                 switch (bs->code) {
                     case NR_MOVETO_OPEN:
-                        if (_closed) closepath();
+                        if (closed) closepath();
                         moveto(bs->x3, bs->y3);
-                        _closed = false;
+                        closed = false;
                         break;
                     case NR_MOVETO:
-                        if (_closed) closepath();
+                        if (closed) closepath();
                         moveto(bs->x3, bs->y3);
-                        _closed = true;
+                        closed = true;
                         break;
                     case NR_LINETO:
                         lineto(bs->x3, bs->y3);
@@ -894,21 +932,21 @@ SPCurve::backspace()
 {
     g_return_if_fail(this != NULL);
 
-    if (end > 0) {
-        end -= 1;
-        if (end > 0) {
-            NArtBpath *bp = _bpath + end - 1;
+    if (_end > 0) {
+        _end -= 1;
+        if (_end > 0) {
+            NArtBpath *bp = _bpath + _end - 1;
             if ((bp->code == NR_MOVETO)     ||
                 (bp->code == NR_MOVETO_OPEN)  )
             {
-                hascpt = true;
-                posSet = true;
-                closed = false;
-                movePos = bp->c(3);
-                end -= 1;
+                _hascpt = true;
+                _posSet = true;
+                _closed = false;
+                _movePos = bp->c(3);
+                _end -= 1;
             }
         }
-        _bpath[end].code = NR_END;
+        _bpath[_end].code = NR_END;
     }
 }
 
@@ -993,7 +1031,7 @@ bezier_len(NR::Point const &c0,
 /**
  * Returns total length of curve, excluding length of closepath segments.
  */
-static double
+double
 sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[])
 {
     g_return_val_if_fail(curve != NULL, 0.);
@@ -1005,7 +1043,7 @@ sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[])
     }
 
     NR::Point prev(curve->_bpath->c(3));
-    for (gint i = 1; i < curve->end; ++i) {
+    for (gint i = 1; i < curve->_end; ++i) {
         NArtBpath &p = curve->_bpath[i];
         double seg_len = 0;
         switch (p.code) {
@@ -1034,7 +1072,7 @@ sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[])
  * Like sp_curve_distance_including_space(), but ensures that the
  * result >= 1e-18:  uses 1 per segment if necessary.
  */
-static double
+double
 sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[])
 {
     double const real_dist(sp_curve_distance_including_space(curve, seg2len));
index 9cbb115292d2bb6dbef1f8a76b9fcd6464d6a486..28fce31323e030b6c6fe8d2910eb7fd1a161031d 100644 (file)
 class SPCurve {
 public:
     /* Constructors */
-    SPCurve(gint length = SP_CURVE_LENSTEP);
+    SPCurve(guint length = SP_CURVE_LENSTEP);
     static SPCurve * new_from_bpath(NArtBpath *bpath);
     static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
     static SPCurve * new_from_rect(NR::Maybe<NR::Rect> const &rect);
 
     virtual ~SPCurve();
 
-    gint refcount;
-    NArtBpath *_bpath;
-    
+    void set_bpath(NArtBpath * new_bpath);
+    NArtBpath const * get_bpath() const;
+    NArtBpath * get_bpath();
+
     /// Index in bpath[] of NR_END element.
-    gint end;
+    guint _end;
 
     /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
     /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
     /// the path (i.e., index of NR_END).
-    gint length;
+    guint _length;
 
     /// Index in bpath[] of the start (i.e., moveto element) of the last 
     /// subpath in this path.
-    gint substart;
+    guint _substart;
 
     /// Previous moveto position.
     /// \note This is used for coalescing moveto's, whereas if we're to 
@@ -55,21 +56,21 @@ public:
     /// midpoint markers.  Ref:
     /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
     /// (first subitem of the item about zero-length path segments)
-    NR::Point movePos;
+    NR::Point _movePos;
 
     /// True iff current point is defined.  Initially false for a new curve; 
     /// becomes true after moveto; becomes false on closepath.  Curveto, 
     /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
-    bool hascpt : 1;
+    bool _hascpt : 1;
     
     /// True iff previous was moveto.
-    bool posSet : 1;
+    bool _posSet : 1;
 
     /// True iff bpath end is moving.
-    bool moving : 1;
+    bool _moving : 1;
     
     /// True iff all subpaths are closed.
-    bool closed : 1;
+    bool _closed : 1;
 
     SPCurve * ref();
     SPCurve * unref();
@@ -97,6 +98,7 @@ public:
     SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
 
     bool is_empty() const;
+    bool is_closed() const;
     NArtBpath * last_bpath() const;
     NArtBpath * first_bpath() const;
     NR::Point first_point() const;
@@ -105,20 +107,31 @@ public:
     NR::Point penultimate_point() const;
 
     void append(SPCurve const *curve2, bool use_lineto);
-    SPCurve * reverse() const;
+    SPCurve * create_reverse() const;
     void backspace();
 
     static SPCurve * concat(GSList const *list);
 
+    void ensure_space(guint space);
+
+protected:
+    gint _refcount;
+
+    NArtBpath *_bpath;
+
 private:
     // Don't implement these:
     SPCurve(const SPCurve&);
     SPCurve& operator=(const SPCurve&);
+
+    friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
+    friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
+    template<class M> friend void tmpl_curve_transform(SPCurve *const curve, M const &m);
 };
 
-#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->end)
-#define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->_bpath)
-#define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->_bpath + (i))
+#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->_end)
+#define SP_CURVE_BPATH(c) ((c)->get_bpath())
+#define SP_CURVE_SEGMENT(c,i) ((c)->get_bpath() + (i))
 
 #endif /* !SEEN_DISPLAY_CURVE_H */
 
index 191aac61fa1d117669484acf61ae8367d0b32e2a..25c4a6e3d3ab341f2ada8253ffeaf80135e9c33a 100644 (file)
@@ -9,7 +9,7 @@ struct SPCanvasItem;
 typedef struct _SPCanvasItemClass SPCanvasItemClass;
 struct SPCanvasGroup;
 struct SPCanvasGroupClass;
-struct SPCurve;
+class SPCurve;
 
 namespace Inkscape {
 namespace Display {
index 0c01211609cbef81157b6790046140c3f6f18667..ebf5cee6d3646910f2b151742ce26ff3c43e5989 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <libnrtype/nrtype-forward.h>
 
-#include <display/curve.h>
+#include <display/display-forward.h>
 #include <forward.h>
 #include <sp-paint-server.h>
 #include <display/nr-arena-item.h>
index 4df93a9a2d1856a5a7cf1ca8ab8f8f1e8f22660d..aba06068e1d8ef2ccc3de1a94c8ddac98209fa68 100644 (file)
@@ -17,6 +17,7 @@
 #include <display/canvas-arena.h>
 #include <display/nr-arena.h>
 #include <display/nr-arena-shape.h>
+#include "display/curve.h"
 #include <libnr/n-art-bpath.h>
 #include <libnr/nr-path.h>
 #include <libnr/nr-pixops.h>
@@ -431,7 +432,7 @@ void
 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape)
 {
     if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
-        ((shape->curve->end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) {
+        ((shape->curve->_end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) {
         if (TRUE || !shape->fill_shp) {
             NR::Matrix  cached_to_new = NR::identity();
             int isometry = 0;
index b371d2ede57bf331b7de6b3c6cb1ff0ace1d4368..2b56fbf75d90b46334fd495dd3c4c6233070e7d9 100644 (file)
@@ -17,7 +17,7 @@
 #define NR_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_CAST ((obj), NR_TYPE_ARENA_SHAPE, NRArenaShape))
 #define NR_IS_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_TYPE ((obj), NR_TYPE_ARENA_SHAPE))
 
-#include "display/curve.h"
+#include "display/display-forward.h"
 #include "display/canvas-bpath.h"
 #include "forward.h"
 #include "sp-paint-server.h"
index b48b34ed03009648a2b2f978c3b98a383582b636..50799b55fe45f2b19c9c1a95e708bf6675976e50 100644 (file)
@@ -25,6 +25,7 @@
 #include "svg/svg.h"
 #include <glibmm/i18n.h>
 #include "libnr/n-art-bpath.h"
+#include "display/curve.h"
 #include "desktop.h"
 #include "desktop-affine.h"
 #include "desktop-handles.h"
@@ -288,7 +289,7 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
         for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
             SPCurve *c;
             c = (SPCurve*)l->data;
-            g_return_if_fail( c->end > 1 );
+            g_return_if_fail( c->_end > 1 );
             if ( SP_CURVE_BPATH(c)->code == NR_MOVETO_OPEN ) {
                 NArtBpath *s, *e;
                 SPDrawAnchor *a;
@@ -378,7 +379,7 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin
 static SPCurve *
 reverse_then_unref(SPCurve *orig)
 {
-    SPCurve *ret = orig->reverse();
+    SPCurve *ret = orig->create_reverse();
     orig->unref();
     return ret;
 }
@@ -431,11 +432,11 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
     if ( dc->sa && dc->ea
          && ( dc->sa->curve == dc->ea->curve )
          && ( ( dc->sa != dc->ea )
-              || dc->sa->curve->closed ) )
+              || dc->sa->curve->is_closed() ) )
     {
         // We hit bot start and end of single curve, closing paths
         SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path."));
-        if (dc->sa->start && !(dc->sa->curve->closed) ) {
+        if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
             c = reverse_then_unref(c);
         }
         dc->sa->curve->append_continuous(c, 0.0625);
index 59ec5a92fe18ee6b7eb28432d0caf10813851139..5ac1a7d0978fe42a2d89eef2a563d4765f524dec 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <sigc++/sigc++.h>
-#include "display/curve.h"
 #include "event-context.h"
 #include <forward.h>
 #include <display/display-forward.h>
index 4de36d0d7f40f3a233c3ef3218438de3f003a51c..cc79dfd2e04d6d3e73ef2539eb6b4e7dce743120 100644 (file)
@@ -35,7 +35,7 @@
 #include "svg/svg.h"
 #include "display/canvas-bpath.h"
 #include "display/bezier-utils.h"
-
+#include "display/curve.h"
 #include <glib/gmem.h>
 #include "macros.h"
 #include "document.h"
@@ -1127,24 +1127,24 @@ accumulate_calligraphic(SPDynaDrawContext *dc)
 {
     if ( !dc->cal1->is_empty() && !dc->cal2->is_empty() ) {
         dc->accumulated->reset(); /*  Is this required ?? */
-        SPCurve *rev_cal2 = dc->cal2->reverse();
+        SPCurve *rev_cal2 = dc->cal2->create_reverse();
 
-        g_assert(dc->cal1->end > 1);
-        g_assert(rev_cal2->end > 1);
+        g_assert(dc->cal1->_end > 1);
+        g_assert(rev_cal2->_end > 1);
         g_assert(SP_CURVE_SEGMENT(dc->cal1, 0)->code == NR_MOVETO_OPEN);
         g_assert(SP_CURVE_SEGMENT(rev_cal2, 0)->code == NR_MOVETO_OPEN);
         g_assert(SP_CURVE_SEGMENT(dc->cal1, 1)->code == NR_CURVETO);
         g_assert(SP_CURVE_SEGMENT(rev_cal2, 1)->code == NR_CURVETO);
-        g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->code == NR_CURVETO);
-        g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->code == NR_CURVETO);
+        g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->code == NR_CURVETO);
+        g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->code == NR_CURVETO);
 
         dc->accumulated->append(dc->cal1, FALSE);
 
-        add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
+        add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
 
         dc->accumulated->append(rev_cal2, TRUE);
 
-        add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding);
+        add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding);
 
         dc->accumulated->closepath();
 
@@ -1183,7 +1183,7 @@ fit_and_split(SPDynaDrawContext *dc, gboolean release)
 #endif
 
         /* Current calligraphic */
-        if ( dc->cal1->end == 0 || dc->cal2->end == 0 ) {
+        if ( dc->cal1->_end == 0 || dc->cal2->_end == 0 ) {
             /* dc->npoints > 0 */
             /* g_print("calligraphics(1|2) reset\n"); */
             dc->cal1->reset();
index b3561b59a42066ded7306a16331dec5d2821eb15..40e6c6376386fb69fa08db10428a9fefde02cc20 100644 (file)
@@ -18,7 +18,6 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
-#include "display/curve.h"
 #include "event-context.h"
 #include <display/display-forward.h>
 #include <libnr/nr-point.h>
index 295e75e8704b739e1458ef89fa092b5b02eb90bd..3fe661f99b1b6a414c32e13439218de4811c41a2 100644 (file)
@@ -964,24 +964,24 @@ accumulate_eraser(SPEraserContext *dc)
 {
     if ( !dc->cal1->is_empty() && !dc->cal2->is_empty() ) {
         dc->accumulated->reset(); /*  Is this required ?? */
-        SPCurve *rev_cal2 = dc->cal2->reverse();
+        SPCurve *rev_cal2 = dc->cal2->create_reverse();
 
-        g_assert(dc->cal1->end > 1);
-        g_assert(rev_cal2->end > 1);
+        g_assert(dc->cal1->_end > 1);
+        g_assert(rev_cal2->_end > 1);
         g_assert(SP_CURVE_SEGMENT(dc->cal1, 0)->code == NR_MOVETO_OPEN);
         g_assert(SP_CURVE_SEGMENT(rev_cal2, 0)->code == NR_MOVETO_OPEN);
         g_assert(SP_CURVE_SEGMENT(dc->cal1, 1)->code == NR_CURVETO);
         g_assert(SP_CURVE_SEGMENT(rev_cal2, 1)->code == NR_CURVETO);
-        g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->code == NR_CURVETO);
-        g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->code == NR_CURVETO);
+        g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->code == NR_CURVETO);
+        g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->code == NR_CURVETO);
 
         dc->accumulated->append(dc->cal1, FALSE);
 
-        add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
+        add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
 
         dc->accumulated->append(rev_cal2, TRUE);
 
-        add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding);
+        add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding);
 
         dc->accumulated->closepath();
 
@@ -1020,7 +1020,7 @@ fit_and_split(SPEraserContext *dc, gboolean release)
 #endif
 
         /* Current eraser */
-        if ( dc->cal1->end == 0 || dc->cal2->end == 0 ) {
+        if ( dc->cal1->_end == 0 || dc->cal2->_end == 0 ) {
             /* dc->npoints > 0 */
             /* g_print("erasers(1|2) reset\n"); */
             dc->cal1->reset();
index 0f04c6a1aa0bce1deb9fcd51090babf3b0d1262d..6dd62206c20402ce101af71d7315ff91637ced89 100644 (file)
@@ -330,7 +330,7 @@ void PovOutput::doCurves(SPDocument *doc)
 
         //Count the NR_CURVETOs/LINETOs
         int segmentCount=0;
-        NArtBpath *bp = SP_CURVE_BPATH(curve);
+        NArtBpath const *bp = SP_CURVE_BPATH(curve);
         for (int curveNr=0 ; curveNr<curveLength ; curveNr++, bp++)
             if (bp->code == NR_CURVETO || bp->code == NR_LINETO)
                 segmentCount++;
index 5fa20c81c41a8591a5c95085e00b0f6002448f6c..f3fac4218611fe70df1cc7956eafdadd063cf38a 100755 (executable)
@@ -20,6 +20,7 @@
 #include "font-instance.h"
 #include "svg/svg-length.h"
 #include "extension/internal/cairo-render-context.h"
+#include "display/curve.h"
 
 namespace Inkscape {
     namespace Extension {
index 2cd88fd8b0901748889d70c74a455ae28401895e..f699248e4e411d6b9b5140b8100814f684ddf454 100644 (file)
@@ -164,18 +164,13 @@ Effect::doBeforeEffect (SPLPEItem */*lpeitem*/)
 void
 Effect::doEffect (SPCurve * curve)
 {
-    NArtBpath *new_bpath = doEffect_nartbpath(SP_CURVE_BPATH(curve));
+    NArtBpath *new_bpath = doEffect_nartbpath(curve->get_bpath());
 
-    if (new_bpath && new_bpath != SP_CURVE_BPATH(curve)) {        // FIXME, add function to SPCurve to change bpath? or a copy function?
-        if (curve->_bpath) {
-            g_free(curve->_bpath); //delete old bpath
-        }
-        curve->_bpath = new_bpath;
-    }
+    curve->set_bpath(new_bpath);
 }
 
 NArtBpath *
-Effect::doEffect_nartbpath (NArtBpath * path_in)
+Effect::doEffect_nartbpath (NArtBpath const * path_in)
 {
     try {
         std::vector<Geom::Path> orig_pathv = BPath_to_2GeomPath(path_in);
index 58010358fc5bf5447a1b4851497eb8264816a67a..7ab4537f9444edcffdae24085d43ca99dc5fa03a 100644 (file)
@@ -112,7 +112,7 @@ protected:
     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
     // doEffect(std::vector<Geom::Path> )
     virtual NArtBpath *
-            doEffect_nartbpath (NArtBpath * path_in);
+            doEffect_nartbpath (NArtBpath const * path_in) __attribute__ ((deprecated));
     virtual std::vector<Geom::Path>
             doEffect_path (std::vector<Geom::Path> const & path_in);
     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
index c37f34ce7a73dd2beb7d03d131fabda110d42d95..6b9fbbb97eaedb8712735680e297f884ffdb487c 100644 (file)
@@ -12,9 +12,7 @@
 #include "sp-item.h"
 #include "sp-path.h"
 #include "sp-item-group.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
-#include <libnr/nr-matrix-fns.h>
+//#include <libnr/n-art-bpath.h>
 #include "libnr/n-art-bpath-2geom.h"
 #include "svg/svg.h"
 #include "ui/widget/scalar.h"
index 22f20b820cff26f48423aa96d0d7de9dce65fc63..9cf9f2f26fe16311555bf41fa3ff815c7bb7fafb 100644 (file)
@@ -14,8 +14,7 @@
  */
 
 #include "live_effects/lpe-curvestitch.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
+
 #include "sp-item.h"
 #include "sp-path.h"
 #include "libnr/n-art-bpath-2geom.h"
@@ -30,7 +29,6 @@
 #include <2geom/d2.h>
 #include <2geom/matrix.h>
 
-
 #include "ui/widget/scalar.h"
 #include "libnr/nr-values.h"
 
index 245b6df0f8577e9c2f76f43d259513c2c6a83225..5ac4a98d420775fd672e79b2d4aed087f4d6c324 100644 (file)
  */
 
 #include "live_effects/lpe-knot.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
 
 #include <2geom/path.h>
-//#include <2geom/sbasis.h>
-//#include <2geom/sbasis-geometric.h>
-//#include <2geom/bezier-to-sbasis.h>
-//#include <2geom/sbasis-to-bezier.h>
 #include <2geom/d2.h>
-//#include <2geom/sbasis-math.h>
-//#include <2geom/piecewise.h>
 #include <2geom/crossing.h>
 #include <2geom/path-intersection.h>
 
index 5be5970c1593b15f85144c580939fba4bd967fe5..57bc458a945da28f879206e0b0b566866c170199 100644 (file)
@@ -26,8 +26,6 @@
 #include "document.h"
 
 #include "live_effects/lpe-perspective_path.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
 #include "sp-item-group.h"
 
 #include "inkscape.h"
index 571503d8e0df77172950aac550ee69af9a67500b..04d61bd7313cd221d15b8c542777595c727e1848 100644 (file)
@@ -20,8 +20,6 @@
  */
 
 #include "live_effects/lpe-skeleton.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
 
 // You might need to include other 2geom files. You can add them here:
 #include <2geom/path.h>
@@ -55,22 +53,6 @@ LPESkeleton::doEffect (SPCurve * curve)
     // spice this up to make the effect actually *do* something!
 }
 
-NArtBpath *
-LPESkeleton::doEffect_nartbpath (NArtBpath * path_in)
-{
-        NArtBpath *path_out;
-        unsigned ret = 0;
-        while ( path_in[ret].code != NR_END ) {
-            ++ret;
-        }
-        unsigned len = ++ret;
-        path_out = g_new(NArtBpath, len);
-
-        memcpy(path_out, path_in, len * sizeof(NArtBpath));   // spice this up to make the effect actually *do* something!
-
-        return path_out;
-}
-
 std::vector<Geom::Path>
 LPESkeleton::doEffect_path (std::vector<Geom::Path> & path_in)
 {
index 290b8a724a7854a22d9eddeefaed27ac3e1fd24c..6522e9ca3c64b83d19398ddfc5522303e11d4028 100644 (file)
@@ -28,7 +28,6 @@ public:
 
 //  Choose to implement one of the doEffect functions. You can delete or comment out the others.
 //    virtual void doEffect (SPCurve * curve);
-//    virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in);
 //    virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);
     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
 
index 4fc6fc35dc1141c8067be4aaf4891fa249200a04..d0320094176bdbc88232461cd09f6dc1765a1f1d 100644 (file)
@@ -12,8 +12,6 @@
  */
 
 #include "live_effects/lpe-sketch.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
 
 // You might need to include other 2geom files. You can add them here:
 #include <2geom/path.h>
index 407e4399293e0620d13cdfecb1154729d105fa51..7382d15e29034f4c07fbd6a0939f3f76a2d6b644 100644 (file)
@@ -29,7 +29,7 @@ LPESlant::~LPESlant()
 void
 LPESlant::doEffect(SPCurve * curve)
 {
-    NArtBpath *bpath = curve->_bpath;
+    NArtBpath *bpath = curve->get_bpath();
     int i = 0;
     while(bpath[i].code != NR_END) {
         bpath[i].y1 += (bpath[i].x1-center[Geom::X]) * factor;
index a193b1a0aed28a022e639be8387c79f8b323d4b2..6994b684bff29f0b31e345b395645161badd327c 100644 (file)
@@ -99,7 +99,7 @@ LPESpiro::doEffect(SPCurve * curve)
     bezctx *bc = new_bezctx_ink(curve);
     int len = SP_CURVE_LENGTH(csrc);
     spiro_cp *path = g_new (spiro_cp, len + 1);
-    NArtBpath *bpath = csrc->_bpath;
+    NArtBpath *bpath = csrc->get_bpath();
     int ib = 0;
     int ip = 0;
     bool closed = false;
index 088d576b1aa1c43a059fa94b60fcff013e12fb1f..ee09221ed5668c28c07a1545f630eb200dcb9dd0 100644 (file)
@@ -9,13 +9,6 @@
 #include <cstdio>
 
 #include "live_effects/lpe-vonkoch.h"
-#include "sp-shape.h"
-#include "sp-item.h"
-#include "sp-path.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
-#include <libnr/nr-matrix-fns.h>
-#include "libnr/n-art-bpath-2geom.h"
 #include "svg/svg.h"
 #include "ui/widget/scalar.h"
 #include "nodepath.h"
index 588d3ec0fa6a767f9827216177deb390d1bd15b3..50f7599c0700d26f4a43b79b55f5159618fee4a4 100644 (file)
@@ -11,9 +11,6 @@
 #include "sp-item.h"
 #include "sp-path.h"
 #include "sp-item-group.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
-#include <libnr/nr-matrix-fns.h>
 #include "libnr/n-art-bpath-2geom.h"
 #include "svg/svg.h"
 #include "ui/widget/scalar.h"
index 78f270e64db5d27b5e20fef50025c085392c8904..a76fb1b32edbdfd65764eb0381439fbc5d5ed5c2 100644 (file)
@@ -8,18 +8,8 @@
 
 #include "live_effects/parameter/path-reference.h"
 
-#include <cstring>
-#include <string>
-#include <string.h>
-
-#include "enums.h"
-
-#include "display/curve.h"
-#include "livarot/Path.h"
-#include "prefs-utils.h"
 #include "sp-shape.h"
 #include "sp-text.h"
-#include "uri.h"
 
 namespace Inkscape {
 namespace LivePathEffect {
index d50ec769e311ced918c45c8730042169eac6b890..d82b82f0d01645be6ce916da6c4cbf7cd4564064 100644 (file)
@@ -181,7 +181,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object,
         return NULL;
 
     NArtBpath *bpath = curve->first_bpath();
-    gint length = curve->end;
+    gint length = curve->_end;
     if (length == 0) {
         curve->unref();
         return NULL; // prevent crash for one-node paths
index 4e3321567e26fcaf589ea4868758f9789ac3ea81..ffb776dfeb5df57a268de0c4e87ca291dfca1db1 100644 (file)
@@ -232,9 +232,23 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s
     }
 }
 
+/**
+ * Returns index of first NR_END bpath in array.
+ */
+static unsigned sp_bpath_length(NArtBpath const bpath[])
+{
+    g_return_val_if_fail(bpath != NULL, FALSE);
+    unsigned ret = 0;
+    while ( bpath[ret].code != NR_END ) {
+        ++ret;
+    }
+    ++ret;
+    return ret;
+}
+
 void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &t,
                                          bool const &first_point,
-                                         NArtBpath *border_bpath) const
+                                         NArtBpath const *border_bpath) const
 {
     // Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap,
     // e.g. when translating an item using the selector tool, then we will only do this for the
@@ -254,8 +268,14 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &
         }
         
         // Consider the page border for snapping
-        if (border_bpath != NULL) { 
-            _bpaths_to_snap_to->push_back(border_bpath);    
+        if (border_bpath != NULL) {
+            // make our own copy of the const*
+            NArtBpath *new_bpath;
+            unsigned const len = sp_bpath_length(border_bpath);
+            new_bpath = g_new(NArtBpath, len);
+            memcpy(new_bpath, border_bpath, len * sizeof(NArtBpath));
+
+            _bpaths_to_snap_to->push_back(new_bpath);    
         }
         
         for (std::vector<SPItem*>::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) {
@@ -329,7 +349,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                                      bool const &first_point,
                                      std::vector<NR::Point> *unselected_nodes,
                                      SPPath const *selected_path,
-                                     NArtBpath *border_bpath) const
+                                     NArtBpath const *border_bpath) const
 {
     _collectPaths(t, first_point, border_bpath);
     // Now we can finally do the real snapping, using the paths collected above
@@ -482,7 +502,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
 {
     
     // Consider the page's border for snapping to
-    NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;
+    NArtBpath const *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;
     
     _collectPaths(t, first_point, border_bpath);
     
@@ -565,7 +585,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc,
     }
     
     // Consider the page's border for snapping to
-    NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;   
+    NArtBpath const *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;   
     
     if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) {
         unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size();
@@ -687,9 +707,9 @@ void Inkscape::ObjectSnapper::_clear_paths() const
     _paths_to_snap_to->clear();
 }
 
-NArtBpath* Inkscape::ObjectSnapper::_getBorderBPath() const
+NArtBpath const* Inkscape::ObjectSnapper::_getBorderBPath() const
 {
-    NArtBpath *border_bpath = NULL;
+    NArtBpath const *border_bpath = NULL;
     NR::Rect const border_rect = NR::Rect(NR::Point(0,0), NR::Point(sp_document_width(_named_view->document),sp_document_height(_named_view->document)));
     SPCurve const *border_curve = SPCurve::new_from_rect(border_rect);
     if (border_curve) {
index 94c9e5a1c2df0aac9a89acbb8f86f52ede7dcb9d..95470ed45ce2254f07f564c3f9d9f3d9bba5f012 100644 (file)
@@ -110,7 +110,7 @@ private:
                       bool const &first_point,
                       std::vector<NR::Point> *unselected_nodes,
                       SPPath const *selected_path,
-                      NArtBpath *border_bpath) const;
+                      NArtBpath const *border_bpath) const;
                       
   void _snapPathsConstrained(SnappedConstraints &sc,
                  Inkscape::Snapper::PointType const &t,
@@ -122,10 +122,10 @@ private:
   
   void _collectPaths(Inkscape::Snapper::PointType const &t, 
                   bool const &first_point,
-                  NArtBpath *border_bpath = NULL) const;
+                  NArtBpath const *border_bpath = NULL) const;
                   
   void _clear_paths() const;
-  NArtBpath* _getBorderBPath() const;
+  NArtBpath const* _getBorderBPath() const;
   
   bool _snap_to_itemnode;
   bool _snap_to_itempath;
index d43d950fb999e3a593b37ac2c539fdf72ae8ad8e..5b57e326efb52a0f6b357aac3e7adbb54d33f286 100644 (file)
@@ -435,7 +435,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
 
     // Prevent empty paths from being added to the document
     // otherwise we end up with zomby markup in the SVG file
-    if(curve->end <= 0)
+    if(curve->_end <= 0)
     {
         curve->unref();
         return NULL;
@@ -503,7 +503,7 @@ sp_selected_path_reverse()
         did = true;
         SPPath *path = SP_PATH(i->data);
 
-        SPCurve *rcurve = sp_path_get_curve_reference(path)->reverse();
+        SPCurve *rcurve = sp_path_get_curve_reference(path)->create_reverse();
 
         gchar *str = sp_svg_write_path(SP_CURVE_BPATH(rcurve));
         if ( sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path)) ) {
index 270b8148db2bab823e9037c6a53106a21c91c125..d286c6f6c00fcfc3cd0b15e2eaef33bc83879066 100644 (file)
@@ -31,7 +31,7 @@
 #include "message-context.h"
 #include "prefs-utils.h"
 #include "sp-path.h"
-
+#include "display/curve.h"
 #include "pixmaps/cursor-pen.xpm"
 #include "display/canvas-bpath.h"
 #include "display/sp-ctrlline.h"
index 0ba44dc3359ce9849077d54c1c4e6840aa601ebf..ae3a2fa48dcb10980b6136bab98f4b867d2f0eb8 100644 (file)
@@ -41,6 +41,7 @@
 #include "document.h"
 #include "desktop-style.h"
 #include "macros.h"
+#include "display/curve.h"
 
 static void sp_pencil_context_class_init(SPPencilContextClass *klass);
 static void sp_pencil_context_init(SPPencilContext *pc);
index d05b75cd09378fc5c79cc27582186440c7b8991a..b3e3d85fc5d17a1b5e31cec4b1b9a5473d6daf62 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include "sp-item.h"
-#include "display/curve.h"
+#include "display/display-forward.h"
 
 #define SP_TYPE_LPE_ITEM (sp_lpe_item_get_type())
 #define SP_LPE_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPE_ITEM, SPLPEItem))
index b25397a31b99b1fbc2685292ab3f432e9d97c261..86bc83e2b504efb50f2c391efbaaad18da134e06 100644 (file)
@@ -123,8 +123,8 @@ sp_nodes_in_path(SPPath *path)
 {
     SPCurve *curve = SP_SHAPE(path)->curve;
     if (!curve) return 0;
-    gint r = curve->end;
-    gint i = curve->length - 1;
+    gint r = curve->_end;
+    gint i = curve->_length - 1;
     if (i > r) i = r; // sometimes after switching from node editor length is wrong, e.g. f6 - draw - f2 - tab - f1, this fixes it
     for (; i >= 0; i --)
         if (SP_CURVE_BPATH(curve)[i].code == NR_MOVETO)
index 23225d714539579f3e6793fda7c307204a15805d..4d47778cf7817f125898a35bb52b7dc014e6b035 100644 (file)
@@ -208,13 +208,13 @@ static void sp_polygon_set(SPObject *object, unsigned int key, const gchar *valu
             if (has_error || *cptr != '\0') {
                 /* TODO: Flag the document as in error, as per
                  * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */
-            } else if (curve->posSet) {
+            } else if (curve->_posSet) {
                 /* We've done a moveto but no lineto.  I'm not sure how we're supposed to represent
                  * a single-point polygon in SPCurve: sp_curve_closepath at the time of writing
                  * doesn't seem to like simply moveto followed by closepath.  The following works,
                  * but won't round-trip properly: I believe it will write as two points rather than
                  * one. */
-                curve->lineto(curve->movePos);
+                curve->lineto(curve->_movePos);
             } else if (hascpt) {
                 curve->closepath();
             }
index 99ebdbe23b6a2dfcdd6d545fe31c8a92168078de..fff9de7d3434fa56b2c35f4f722fb5f3b76abaf6 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "macros.h"
 #include "display/nr-arena-shape.h"
+#include "display/curve.h"
 #include "print.h"
 #include "document.h"
 #include "style.h"
@@ -545,8 +546,8 @@ NR::Matrix
 sp_shape_marker_get_transform(SPShape const *shape, NArtBpath const *bp)
 {
     g_return_val_if_fail(( is_moveto(SP_CURVE_BPATH(shape->curve)[0].code)
-                           && ( 0 < shape->curve->end )
-                           && ( SP_CURVE_BPATH(shape->curve)[shape->curve->end].code == NR_END ) ),
+                           && ( 0 < shape->curve->_end )
+                           && ( SP_CURVE_BPATH(shape->curve)[shape->curve->_end].code == NR_END ) ),
                          NR::Matrix(NR::translate(bp->c(3))));
     double const angle1 = incoming_tangent(bp);
     double const angle2 = outgoing_tangent(bp);
index a6bd60cd69743f3b68b155e4d99e1523d6b08d9c..aec2b8f6e234dda1e9e51cf50fd5c00af8a2b4db 100644 (file)
@@ -1738,6 +1738,10 @@ Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
     return dest;
 }
 
+/* 
+ * This function is buggy: it can either return a new NArtBpath, or an existing one.
+ * It is therefore unclear whether the caller must g_free the path or not!
+*/
 NArtBpath *
 bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull)
 {
index d60282d715c004122a05a9b843017c5b65a51aaf..e4b88ffea65ad7bb0634eabe31b9dea99c7f07fe 100644 (file)
@@ -67,6 +67,7 @@
 #include "sp-flowtext.h"
 #include "display/canvas-bpath.h"
 #include "display/canvas-arena.h"
+#include "display/curve.h"
 #include "livarot/Shape.h"
 #include "isnan.h"
 #include "prefs-utils.h"
index 6a94a185b5ffc44867876adf9f2edd29eb6859b1..2157ecdaa794f817ca507f11ef5f1a8a4f96cee7 100644 (file)
@@ -12,7 +12,6 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
-#include "display/curve.h"
 #include "event-context.h"
 #include <display/display-forward.h>
 #include <libnr/nr-point.h>
index 1fb179660fe4187188e66c802f8195ae706a0466..8ac2bec8b255b5bb157bd5088231f1980ee62ad9 100644 (file)
@@ -83,7 +83,7 @@
 #include "draw-context.h"
 #include "gradient-drag.h"
 #include "sp-guide.h"
-
+#include "display/curve.h"
 
 /**
  * \brief Return the name without underscores and ellipsis, for use in dialog