Code

NRMatrix copy constructor appears deficient; avoid it for now
[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  *
14  * Released under GNU GPL
15  */
17 #include <glib/gtypes.h>
18 #include <glib/gslist.h>
20 #include "libnr/nr-forward.h"
21 #include "libnr/nr-point.h"
23 /// Wrapper around NArtBpath.
24 struct SPCurve {
25     gint refcount;
26     NArtBpath *bpath;
27     
28     /// Index in bpath[] of NR_END element.
29     gint end;
31     /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
32     /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
33     /// the path (i.e., index of NR_END).
34     gint length;
36     /// Index in bpath[] of the start (i.e., moveto element) of the last 
37     /// subpath in this path.
38     gint substart;
40     /// Previous moveto position.
41     /// \note This is used for coalescing moveto's, whereas if we're to 
42     /// conform to the SVG spec then we mustn't coalesce movetos if we have 
43     /// midpoint markers.  Ref:
44     /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
45     /// (first subitem of the item about zero-length path segments)
46     NR::Point movePos;
48     /// True iff bpath points to read-only, static storage (see callers of
49     /// sp_curve_new_from_static_bpath), in which case we shouldn't free 
50     /// bpath and shouldn't write through it.
51     bool sbpath : 1;
52     
53     /// True iff current point is defined.  Initially false for a new curve; 
54     /// becomes true after moveto; becomes false on closepath.  Curveto, 
55     /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
56     bool hascpt : 1;
57     
58     /// True iff previous was moveto.
59     bool posSet : 1;
61     /// True iff bpath end is moving.
62     bool moving : 1;
63     
64     /// True iff all subpaths are closed.
65     bool closed : 1;
66 };
68 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->end)
69 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->bpath)
70 #define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->bpath + (i))
72 /* Constructors */
74 SPCurve *sp_curve_new();
75 SPCurve *sp_curve_new_sized(gint length);
76 SPCurve *sp_curve_new_from_bpath(NArtBpath *bpath);
77 SPCurve *sp_curve_new_from_static_bpath(NArtBpath const *bpath);
78 SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]);
80 SPCurve *sp_curve_ref(SPCurve *curve);
81 SPCurve *sp_curve_unref(SPCurve *curve);
83 SPCurve *sp_curve_copy(SPCurve *curve);
84 SPCurve *sp_curve_concat(GSList const *list);
85 GSList *sp_curve_split(SPCurve const *curve);
86 void sp_curve_transform(SPCurve *curve, NR::Matrix const &);
87 void sp_curve_transform(SPCurve *curve, NR::translate const &);
88 void sp_curve_stretch_endpoints(SPCurve *curve, NR::Point const &, NR::Point const &);
89 void sp_curve_move_endpoints(SPCurve *curve, NR::Point const &,
90         NR::Point const &);
92 /* Methods */
94 void sp_curve_reset(SPCurve *curve);
96 void sp_curve_moveto(SPCurve *curve, NR::Point const &p);
97 void sp_curve_moveto(SPCurve *curve, gdouble x, gdouble y);
98 void sp_curve_lineto(SPCurve *curve, NR::Point const &p);
99 void sp_curve_lineto(SPCurve *curve, gdouble x, gdouble y);
100 void sp_curve_lineto_moving(SPCurve *curve, gdouble x, gdouble y);
101 void sp_curve_curveto(SPCurve *curve, NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
102 void sp_curve_curveto(SPCurve *curve, gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
103 void sp_curve_closepath(SPCurve *curve);
104 void sp_curve_closepath_current(SPCurve *curve);
106 SPCurve *sp_curve_append_continuous(SPCurve *c0, SPCurve const *c1, gdouble tolerance);
108 #define sp_curve_is_empty sp_curve_empty
109 bool sp_curve_empty(SPCurve *curve);
110 NArtBpath *sp_curve_last_bpath(SPCurve const *curve);
111 NArtBpath *sp_curve_first_bpath(SPCurve const *curve);
112 NR::Point sp_curve_first_point(SPCurve const *curve);
113 NR::Point sp_curve_last_point(SPCurve const *curve);
114 NR::Point sp_curve_second_point(SPCurve const *curve);
115 NR::Point sp_curve_penultimate_point(SPCurve const *curve);
117 void sp_curve_append(SPCurve *curve, SPCurve const *curve2, bool use_lineto);
118 SPCurve *sp_curve_reverse(SPCurve const *curve);
119 void sp_curve_backspace(SPCurve *curve);
122 #endif /* !SEEN_DISPLAY_CURVE_H */
124 /*
125   Local Variables:
126   mode:c++
127   c-file-style:"stroustrup"
128   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
129   indent-tabs-mode:nil
130   fill-column:99
131   End:
132 */
133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :