Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
curve.h
Go to the documentation of this file.
1/* curve.h: data structures for the conversion from pixels to splines. */
2
3#ifndef CURVE_H
4#define CURVE_H
5
6#include "autotrace.h"
7#include "vector.h"
8
9/* We are simultaneously manipulating two different representations of
10 the same outline: one based on (x,y) positions in the plane, and one
11 based on parametric splines. (We are trying to match the latter to
12 the former.) Although the original (x,y)'s are pixel positions,
13 i.e., integers, after filtering they are reals. */
14
15typedef struct {
17 gfloat t;
19
20/* It turns out to be convenient to break the list of all the pixels in
21 the outline into sublists, divided at ``corners''. Then each of the
22 sublists is treated independently. Each of these sublists is a `curve'. */
23
33
34typedef struct curve *curve_type;
35
36/* Get at the coordinates and the t values. */
37#define CURVE_POINT(c, n) ((c)->point_list[n].coord)
38#define LAST_CURVE_POINT(c) ((c)->point_list[(c)->length-1].coord)
39#define CURVE_T(c, n) ((c)->point_list[n].t)
40#define LAST_CURVE_T(c) ((c)->point_list[(c)->length-1].t)
41
42/* This is the length of `point_list'. */
43#define CURVE_LENGTH(c) ((c)->length)
44
45/* A curve is ``cyclic'' if it didn't have any corners, after all, so
46 the last point is adjacent to the first. */
47#define CURVE_CYCLIC(c) ((c)->cyclic)
48
49/* If the curve is cyclic, the next and previous points should wrap
50 around; otherwise, if we get to the end, we return CURVE_LENGTH and
51 -1, respectively. */
52#define CURVE_NEXT(c, n) \
53 ((n) + 1 >= CURVE_LENGTH (c) \
54 ? CURVE_CYCLIC (c) ? ((n) + 1) % CURVE_LENGTH (c) : CURVE_LENGTH (c) \
55 : (n) + 1)
56#define CURVE_PREV(c, n) \
57 ((signed int) (n) - 1 < 0 \
58 ? CURVE_CYCLIC (c) ? (signed int) CURVE_LENGTH (c) + (signed int) (n) - 1 : -1\
59 : (signed int) (n) - 1)
60
61/* The tangents at the endpoints are computed using the neighboring curves. */
62#define CURVE_START_TANGENT(c) ((c)->start_tangent)
63#define CURVE_END_TANGENT(c) ((c)->end_tangent)
64#define PREVIOUS_CURVE(c) ((c)->previous)
65#define NEXT_CURVE(c) ((c)->next)
66
67/* Return an entirely empty curve. */
68extern curve_type new_curve(void);
69
70/* Return a curve the same as C, except without any points. */
72
73/* Free the memory C uses. */
74extern void free_curve(curve_type c);
75
76/* Append the point P to the end of C's list. */
78
79/* Like `append_pixel', for a point in real coordinates. */
81
82/* Write some or all, respectively, of the curve C in human-readable
83 form to the log file, if logging is enabled. */
84extern void log_curve(curve_type c, gboolean print_t);
86
87/* Display the curve C online, if displaying is enabled. */
89
90/* So, an outline is a list of curves. */
91typedef struct {
93 unsigned length;
94 gboolean clockwise;
95 gboolean open;
97
98/* Number of curves in the list. */
99#define CURVE_LIST_LENGTH(c_l) ((c_l).length)
100
101/* Access the individual curves. */
102#define CURVE_LIST_ELT(c_l, n) ((c_l).data[n])
103#define LAST_CURVE_LIST_ELT(c_l) ((c_l).data[CURVE_LIST_LENGTH (c_l) - 1])
104
105/* Says whether the outline that this curve list represents moves
106 clockwise or counterclockwise. */
107#define CURVE_LIST_CLOCKWISE(c_l) ((c_l).clockwise)
108
112
113/* And a character is a list of outlines. I named this
114 `curve_list_array_type' because `curve_list_list_type' seemed pretty
115 monstrous. */
116typedef struct {
118 unsigned length;
120
121/* Turns out we can use the same definitions for lists of lists as for
122 just lists. But we define the usual names, just in case. */
123#define CURVE_LIST_ARRAY_LENGTH CURVE_LIST_LENGTH
124#define CURVE_LIST_ARRAY_ELT CURVE_LIST_ELT
125#define LAST_CURVE_LIST_ARRAY_ELT LAST_CURVE_LIST_ELT
126
130
131#endif /* not CURVE_H */
curve_type new_curve(void)
void log_entire_curve(curve_type c)
curve_list_array_type new_curve_list_array(void)
void free_curve(curve_type c)
struct curve * curve_type
Definition curve.h:34
void log_curve(curve_type c, gboolean print_t)
void append_pixel(curve_type c, at_coord p)
void display_curve(curve_type)
void free_curve_list_array(curve_list_array_type *, at_progress_func, gpointer)
void append_curve(curve_list_type *, curve_type)
curve_list_type new_curve_list(void)
curve_type copy_most_of_curve(curve_type c)
void append_point(curve_type c, at_real_coord p)
void append_curve_list(curve_list_array_type *, curve_list_type)
void free_curve_list(curve_list_type *)
void(* at_progress_func)(gfloat percentage, gpointer client_data)
Definition autotrace.h:246
double c[8][4]
curve_list_type * data
Definition curve.h:117
gboolean open
Definition curve.h:95
gboolean clockwise
Definition curve.h:94
unsigned length
Definition curve.h:93
curve_type * data
Definition curve.h:92
Definition curve.h:24
struct curve * previous
Definition curve.h:30
vector_type * end_tangent
Definition curve.h:29
unsigned length
Definition curve.h:26
vector_type * start_tangent
Definition curve.h:28
point_type * point_list
Definition curve.h:25
gboolean cyclic
Definition curve.h:27
struct curve * next
Definition curve.h:31
gfloat t
Definition curve.h:17
at_real_coord coord
Definition curve.h:16