Code

2geomify SPCurve::new_from_rect
[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>
23 #include "libnr/nr-forward.h"
24 #include "libnr/nr-rect.h"
26 #define SP_CURVE_LENSTEP 32
28 struct SPObject;
30 /// Wrapper around Geom::PathVector.
31 class SPCurve {
32 public:
33     /* Constructors */
34     SPCurve(guint length = SP_CURVE_LENSTEP);
35     SPCurve(Geom::PathVector const& pathv);
36     static SPCurve * new_from_bpath(NArtBpath *bpath);
37     static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
38     static SPCurve * new_from_rect(Geom::Rect const &rect);
40     virtual ~SPCurve();
42     void set_pathvector(Geom::PathVector const & new_pathv);
43     NArtBpath const * get_bpath() const;
44     Geom::PathVector const & get_pathvector() const;
46     guint get_length() const;
47     guint get_segment_count() const;
49     SPCurve * ref();
50     SPCurve * unref();
52     SPCurve * copy() const;
54     GSList * split() const;
55     void transform(NR::Matrix const &m);
56     void transform(Geom::Matrix const &m);
57     void stretch_endpoints(NR::Point const &, NR::Point const &);
58     void move_endpoints(NR::Point const &, NR::Point const &);
59     void last_point_additive_move(Geom::Point const & p);
61     void reset();
63     void moveto(Geom::Point const &p);
64     void moveto(NR::Point const &p);
65     void moveto(gdouble x, gdouble y);
66     void lineto(Geom::Point const &p);
67     void lineto(NR::Point const &p);
68     void lineto(gdouble x, gdouble y);
69     void curveto(Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2);
70     void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
71     void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
72     void closepath();
73     void closepath_current();
75     SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
77     bool is_empty() const;
78     bool is_closed() const;
79     NArtBpath const * last_bpath() const;
80     Geom::Curve const * last_segment() const;
81     Geom::Path const * last_path() const;
82     Geom::Curve const * first_segment() const;
83     Geom::Path const * first_path() const;
84     NR::Point first_point() const;
85     NR::Point last_point() const;
86     NR::Point second_point() const;
87     NR::Point penultimate_point() const;
88     guint nodes_in_path() const;
90     void append(SPCurve const *curve2, bool use_lineto);
91     SPCurve * create_reverse() const;
92     void backspace();
94     static SPCurve * concat(GSList const *list);
96     void ensure_space(guint space);
98 protected:
99     gint _refcount;
101     NArtBpath *_bpath;
102     Geom::PathVector _pathv;
104     /// Index in bpath[] of NR_END element.
105     guint _end;
107     /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
108     /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
109     /// the path (i.e., index of NR_END).
110     guint _length;
112     /// Index in bpath[] of the start (i.e., moveto element) of the last 
113     /// subpath in this path.
114     guint _substart;
116     /// Previous moveto position.
117     /// \note This is used for coalescing moveto's, whereas if we're to 
118     /// conform to the SVG spec then we mustn't coalesce movetos if we have 
119     /// midpoint markers.  Ref:
120     /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
121     /// (first subitem of the item about zero-length path segments)
122     NR::Point _movePos;
124     /// True iff current point is defined.  Initially false for a new curve; 
125     /// becomes true after moveto; becomes false on closepath.  Curveto, 
126     /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
127     bool _hascpt : 1;
128     
129     /// True iff previous was moveto.
130     bool _posSet : 1;
132     /// True iff bpath end is moving.
133     bool _moving : 1;
134     
135     /// True iff all subpaths are closed.
136     bool _closed : 1;
138 private:
139     // Don't implement these:
140     SPCurve(const SPCurve&);
141     SPCurve& operator=(const SPCurve&);
143 //friends:
144     friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
145     friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
146     template<class M> friend void tmpl_curve_transform(SPCurve * curve, M const &m);
147 };
149 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->get_length())
150 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->get_bpath())
153 #endif /* !SEEN_DISPLAY_CURVE_H */
155 /*
156   Local Variables:
157   mode:c++
158   c-file-style:"stroustrup"
159   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
160   indent-tabs-mode:nil
161   fill-column:99
162   End:
163 */
164 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :