1
/* Copyright (C) 2001-2007 Peter Selinger.
2
This file is part of Potrace. It is free software and it is covered
3
by the GNU General Public License. See the file COPYING for details. */
5
/* $Id: curve.cpp 16345 2007-10-26 21:01:30Z ishmal $ */
6
/* private part of the path and curve data structures */
12
#include "potracelib.h"
16
#define SAFE_MALLOC(var, n, typ) \
17
if ((var = (typ *)malloc((n)*sizeof(typ))) == NULL) goto malloc_error
19
/* ---------------------------------------------------------------------- */
20
/* allocate and free path objects */
22
path_t *path_new(void) {
24
privpath_t *priv = NULL;
26
SAFE_MALLOC(p, 1, path_t);
27
memset(p, 0, sizeof(path_t));
28
SAFE_MALLOC(priv, 1, privpath_t);
29
memset(priv, 0, sizeof(privpath_t));
39
/* free the members of the given curve structure. Leave errno unchanged. */
40
static void privcurve_free_members(privcurve_t *curve) {
49
/* free a path. Leave errno untouched. */
50
void path_free(path_t *p) {
57
privcurve_free_members(&p->priv->curve);
58
privcurve_free_members(&p->priv->ocurve);
61
/* do not free p->fcurve ! */
66
/* free a pathlist, leaving errno untouched. */
67
void pathlist_free(path_t *plist) {
70
list_forall_unlink(p, plist) {
75
/* ---------------------------------------------------------------------- */
76
/* initialize and finalize curve structures */
78
typedef dpoint_t dpoint3_t[3];
80
/* initialize the members of the given curve structure to size m.
81
Return 0 on success, 1 on error with errno set. */
82
int privcurve_init(privcurve_t *curve, int n) {
83
memset(curve, 0, sizeof(privcurve_t));
85
SAFE_MALLOC(curve->tag, n, int);
86
SAFE_MALLOC(curve->c, n, dpoint3_t);
87
SAFE_MALLOC(curve->vertex, n, dpoint_t);
88
SAFE_MALLOC(curve->alpha, n, double);
89
SAFE_MALLOC(curve->alpha0, n, double);
90
SAFE_MALLOC(curve->beta, n, double);
103
/* copy private to public curve structure */
104
void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c) {