Code

enable safe support for motion hints
[inkscape.git] / src / display / curve.h
index 847d09f46628df9b483374b7126018c284a1285a..39720e40195157e00e51630e75d57c79fc0167ef 100644 (file)
@@ -10,6 +10,7 @@
  * Copyright (C) 2000 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
  * Copyright (C) 2002 Lauris Kaplinski
+ * Copyright (C) 2008 Johan Engelen
  *
  * Released under GNU GPL
  */
 #include <glib/gtypes.h>
 #include <glib/gslist.h>
 
+#include <2geom/forward.h>
+#include <2geom/point.h>
+
 #include "libnr/nr-forward.h"
-#include "libnr/nr-point.h"
 #include "libnr/nr-rect.h"
 
-/// Wrapper around NArtBpath.
-struct SPCurve {
-    gint refcount;
+#define SP_CURVE_LENSTEP 32
+
+struct SPObject;
+
+/// Wrapper around Geom::PathVector.
+class SPCurve {
+public:
+    /* Constructors */
+    SPCurve(guint length = SP_CURVE_LENSTEP);
+    SPCurve(Geom::PathVector const& pathv);
+    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();
+
+    void set_pathvector(Geom::PathVector const & new_pathv);
+    NArtBpath const * get_bpath() const;
+    Geom::PathVector const & get_pathvector() const;
+
+    guint get_length() const;
+    guint get_segment_count() const;
+
+    SPCurve * ref();
+    SPCurve * unref();
+
+    SPCurve * copy() const;
+
+    GSList * split() const;
+    void transform(NR::Matrix const &m);
+    void transform(Geom::Matrix const &m);
+    void stretch_endpoints(NR::Point const &, NR::Point const &);
+    void move_endpoints(NR::Point const &, NR::Point const &);
+    void last_point_additive_move(Geom::Point const & p);
+
+    void reset();
+
+    void moveto(Geom::Point const &p);
+    void moveto(NR::Point const &p);
+    void moveto(gdouble x, gdouble y);
+    void lineto(Geom::Point const &p);
+    void lineto(NR::Point const &p);
+    void lineto(gdouble x, gdouble y);
+    void curveto(Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2);
+    void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
+    void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
+    void closepath();
+    void closepath_current();
+
+    SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
+
+    bool is_empty() const;
+    bool is_closed() const;
+    NArtBpath const * last_bpath() const;
+    Geom::Curve const * last_segment() const;
+    Geom::Path const * last_path() const;
+    Geom::Curve const * first_segment() const;
+    Geom::Path const * first_path() const;
+    NR::Point first_point() const;
+    NR::Point last_point() const;
+    NR::Point second_point() const;
+    NR::Point penultimate_point() const;
+    guint nodes_in_path() const;
+
+    void append(SPCurve const *curve2, bool use_lineto);
+    SPCurve * create_reverse() const;
+    void backspace();
+
+    static SPCurve * concat(GSList const *list);
+
+    void ensure_space(guint space);
+
+protected:
+    gint _refcount;
+
     NArtBpath *_bpath;
-    
+    Geom::PathVector _pathv;
+
     /// 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 
@@ -44,75 +120,35 @@ struct SPCurve {
     /// 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;
-};
-
-#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))
-
-/* Constructors */
+    bool _closed : 1;
 
-SPCurve *sp_curve_new();
-SPCurve *sp_curve_new_sized(gint length);
-SPCurve *sp_curve_new_from_bpath(NArtBpath *bpath);
-SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]);
-SPCurve *sp_curve_new_from_rect(NR::Maybe<NR::Rect> const &rect);
+private:
+    // Don't implement these:
+    SPCurve(const SPCurve&);
+    SPCurve& operator=(const SPCurve&);
 
-SPCurve *sp_curve_ref(SPCurve *curve);
-SPCurve *sp_curve_unref(SPCurve *curve);
-
-SPCurve *sp_curve_copy(SPCurve *curve);
-SPCurve *sp_curve_concat(GSList const *list);
-GSList *sp_curve_split(SPCurve const *curve);
-void sp_curve_transform(SPCurve *curve, NR::Matrix const &);
-void sp_curve_transform(SPCurve *curve, NR::translate const &);
-void sp_curve_stretch_endpoints(SPCurve *curve, NR::Point const &, NR::Point const &);
-void sp_curve_move_endpoints(SPCurve *curve, NR::Point const &,
-        NR::Point const &);
-
-/* Methods */
-
-void sp_curve_reset(SPCurve *curve);
-
-void sp_curve_moveto(SPCurve *curve, NR::Point const &p);
-void sp_curve_moveto(SPCurve *curve, gdouble x, gdouble y);
-void sp_curve_lineto(SPCurve *curve, NR::Point const &p);
-void sp_curve_lineto(SPCurve *curve, gdouble x, gdouble y);
-void sp_curve_lineto_moving(SPCurve *curve, gdouble x, gdouble y);
-void sp_curve_curveto(SPCurve *curve, NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
-void sp_curve_curveto(SPCurve *curve, gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
-void sp_curve_closepath(SPCurve *curve);
-void sp_curve_closepath_current(SPCurve *curve);
-
-SPCurve *sp_curve_append_continuous(SPCurve *c0, SPCurve const *c1, gdouble tolerance);
-
-#define sp_curve_is_empty sp_curve_empty
-bool sp_curve_empty(SPCurve *curve);
-NArtBpath *sp_curve_last_bpath(SPCurve const *curve);
-NArtBpath *sp_curve_first_bpath(SPCurve const *curve);
-NR::Point sp_curve_first_point(SPCurve const *curve);
-NR::Point sp_curve_last_point(SPCurve const *curve);
-NR::Point sp_curve_second_point(SPCurve const *curve);
-NR::Point sp_curve_penultimate_point(SPCurve const *curve);
+//friends:
+    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 * curve, M const &m);
+};
 
-void sp_curve_append(SPCurve *curve, SPCurve const *curve2, bool use_lineto);
-SPCurve *sp_curve_reverse(SPCurve const *curve);
-void sp_curve_backspace(SPCurve *curve);
+#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->get_length())
+#define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->get_bpath())
 
 
 #endif /* !SEEN_DISPLAY_CURVE_H */
@@ -126,4 +162,4 @@ void sp_curve_backspace(SPCurve *curve);
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :