Code

39720e40195157e00e51630e75d57c79fc0167ef
[inkscape.git] / src / display / curve.h
1 #ifndef SEEN_DISPLAY_CURVE_H
2 #define SEEN_DISPLAY_CURVE_H
4 /** \file
5  * Wrapper around an array of NArtBpath objects.
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * Copyright (C) 2000 Lauris Kaplinski
11  * Copyright (C) 2000-2001 Ximian, Inc.
12  * Copyright (C) 2002 Lauris Kaplinski
13  * Copyright (C) 2008 Johan Engelen
14  *
15  * Released under GNU GPL
16  */
18 #include <glib/gtypes.h>
19 #include <glib/gslist.h>
21 #include <2geom/forward.h>
22 #include <2geom/point.h>
24 #include "libnr/nr-forward.h"
25 #include "libnr/nr-rect.h"
27 #define SP_CURVE_LENSTEP 32
29 struct SPObject;
31 /// Wrapper around Geom::PathVector.
32 class SPCurve {
33 public:
34     /* Constructors */
35     SPCurve(guint length = SP_CURVE_LENSTEP);
36     SPCurve(Geom::PathVector const& pathv);
37     static SPCurve * new_from_bpath(NArtBpath *bpath);
38     static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
39     static SPCurve * new_from_rect(NR::Maybe<NR::Rect> const &rect);
41     virtual ~SPCurve();
43     void set_pathvector(Geom::PathVector const & new_pathv);
44     NArtBpath const * get_bpath() const;
45     Geom::PathVector const & get_pathvector() const;
47     guint get_length() const;
48     guint get_segment_count() const;
50     SPCurve * ref();
51     SPCurve * unref();
53     SPCurve * copy() const;
55     GSList * split() const;
56     void transform(NR::Matrix const &m);
57     void transform(Geom::Matrix const &m);
58     void stretch_endpoints(NR::Point const &, NR::Point const &);
59     void move_endpoints(NR::Point const &, NR::Point const &);
60     void last_point_additive_move(Geom::Point const & p);
62     void reset();
64     void moveto(Geom::Point const &p);
65     void moveto(NR::Point const &p);
66     void moveto(gdouble x, gdouble y);
67     void lineto(Geom::Point const &p);
68     void lineto(NR::Point const &p);
69     void lineto(gdouble x, gdouble y);
70     void curveto(Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2);
71     void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
72     void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
73     void closepath();
74     void closepath_current();
76     SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
78     bool is_empty() const;
79     bool is_closed() const;
80     NArtBpath const * last_bpath() const;
81     Geom::Curve const * last_segment() const;
82     Geom::Path const * last_path() const;
83     Geom::Curve const * first_segment() const;
84     Geom::Path const * first_path() const;
85     NR::Point first_point() const;
86     NR::Point last_point() const;
87     NR::Point second_point() const;
88     NR::Point penultimate_point() const;
89     guint nodes_in_path() const;
91     void append(SPCurve const *curve2, bool use_lineto);
92     SPCurve * create_reverse() const;
93     void backspace();
95     static SPCurve * concat(GSList const *list);
97     void ensure_space(guint space);
99 protected:
100     gint _refcount;
102     NArtBpath *_bpath;
103     Geom::PathVector _pathv;
105     /// Index in bpath[] of NR_END element.
106     guint _end;
108     /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
109     /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
110     /// the path (i.e., index of NR_END).
111     guint _length;
113     /// Index in bpath[] of the start (i.e., moveto element) of the last 
114     /// subpath in this path.
115     guint _substart;
117     /// Previous moveto position.
118     /// \note This is used for coalescing moveto's, whereas if we're to 
119     /// conform to the SVG spec then we mustn't coalesce movetos if we have 
120     /// midpoint markers.  Ref:
121     /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
122     /// (first subitem of the item about zero-length path segments)
123     NR::Point _movePos;
125     /// True iff current point is defined.  Initially false for a new curve; 
126     /// becomes true after moveto; becomes false on closepath.  Curveto, 
127     /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
128     bool _hascpt : 1;
129     
130     /// True iff previous was moveto.
131     bool _posSet : 1;
133     /// True iff bpath end is moving.
134     bool _moving : 1;
135     
136     /// True iff all subpaths are closed.
137     bool _closed : 1;
139 private:
140     // Don't implement these:
141     SPCurve(const SPCurve&);
142     SPCurve& operator=(const SPCurve&);
144 //friends:
145     friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
146     friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
147     template<class M> friend void tmpl_curve_transform(SPCurve * curve, M const &m);
148 };
150 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->get_length())
151 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->get_bpath())
154 #endif /* !SEEN_DISPLAY_CURVE_H */
156 /*
157   Local Variables:
158   mode:c++
159   c-file-style:"stroustrup"
160   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
161   indent-tabs-mode:nil
162   fill-column:99
163   End:
164 */
165 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :