Debian Codegraph @

third_party/spiro/ppedit/bezctx_x3.c

raw symbols SCIP
1 /*
2 ppedit - A pattern plate editor for Spiro splines.
3 Copyright (C) 2007 Raph Levien
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19
20 */
21 #include <x3.h>
22 #include "zmisc.h"
23 #include "bezctx.h"
24 #include "bezctx_x3.h"
25
26 typedef struct {
27 bezctx base;
28 x3dc *dc;
29 int is_open;
30 } bezctx_x3;
31
32 static void
33 bezctx_x3_moveto(bezctx *z, double x, double y, int is_open) {
34 bezctx_x3 *bc = (bezctx_x3 *)z;
35
36 if (!bc->is_open) x3closepath(bc->dc);
37 x3moveto(bc->dc, x, y);
38 bc->is_open = is_open;
39 }
40
41 void
42 bezctx_x3_lineto(bezctx *z, double x, double y) {
43 bezctx_x3 *bc = (bezctx_x3 *)z;
44
45 x3lineto(bc->dc, x, y);
46 }
47
48 void
49 bezctx_x3_quadto(bezctx *z, double x1, double y1, double x2, double y2)
50 {
51 bezctx_x3 *bc = (bezctx_x3 *)z;
52 double x0, y0;
53
54 x3getcurrentpoint(bc->dc, &x0, &y0);
55 x3curveto(bc->dc,
56 x1 + (1./3) * (x0 - x1),
57 y1 + (1./3) * (y0 - y1),
58 x1 + (1./3) * (x2 - x1),
59 y1 + (1./3) * (y2 - y1),
60 x2,
61 y2);
62 }
63
64 void
65 bezctx_x3_curveto(bezctx *z, double x1, double y1, double x2, double y2,
66 double x3, double y3)
67 {
68 bezctx_x3 *bc = (bezctx_x3 *)z;
69
70 x3curveto(bc->dc, x1, y1, x2, y2, x3, y3);
71 }
72
73 void
74 bezctx_x3_finish(bezctx *z)
75 {
76 bezctx_x3 *bc = (bezctx_x3 *)z;
77
78 if (!bc->is_open)
79 x3closepath(bc->dc);
80
81 zfree(bc);
82 }
83
84 bezctx *
85 new_bezctx_x3(x3dc *dc) {
86 bezctx_x3 *result = znew(bezctx_x3, 1);
87
88 result->base.moveto = bezctx_x3_moveto;
89 result->base.lineto = bezctx_x3_lineto;
90 result->base.quadto = bezctx_x3_quadto;
91 result->base.curveto = bezctx_x3_curveto;
92 result->base.mark_knot = NULL;
93 result->dc = dc;
94 result->is_open = 1;
95 return &result->base;
96 }