Scribus
Open source desktop publishing at your fingertips
bezier-utils.h
1 #ifndef __SP_BEZIER_UTILS_H__
2 #define __SP_BEZIER_UTILS_H__
3 
4 /*
5  * An Algorithm for Automatically Fitting Digitized Curves
6  * by Philip J. Schneider
7  * from "Graphics Gems", Academic Press, 1990
8  *
9  * Authors:
10  * Philip J. Schneider
11  * Lauris Kaplinski <lauris@ximian.com>
12  *
13  * Copyright (C) 1990 Philip J. Schneider
14  * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc.
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it either under the terms of the GNU Lesser General Public
18  * License version 2.1 as published by the Free Software Foundation
19  * (the "LGPL") or, at your option, under the terms of the Mozilla
20  * Public License Version 1.1 (the "MPL"). If you do not alter this
21  * notice, a recipient may use your version of this file under either
22  * the MPL or the LGPL.
23  *
24  * You should have received a copy of the LGPL along with this library
25  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  * You should have received a copy of the MPL along with this library
28  * in the file COPYING-MPL-1.1
29  *
30  * The contents of this file are subject to the Mozilla Public License
31  * Version 1.1 (the "License"); you may not use this file except in
32  * compliance with the License. You may obtain a copy of the License at
33  * http://www.mozilla.org/MPL/
34  *
35  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
36  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
37  * the specific language governing rights and limitations.
38  *
39  */
40 
41 #include "point.h"
42 
43 namespace Geom{
44 
45 /* Bezier approximation utils */
46 Point bezier_pt(unsigned degree, Point const V[], double t);
47 
48 int bezier_fit_cubic(Point bezier[], Point const data[], int len, double error);
49 
50 int bezier_fit_cubic_r(Point bezier[], Point const data[], int len, double error,
51  unsigned max_beziers);
52 
53 int bezier_fit_cubic_full(Point bezier[], int split_points[], Point const data[], int len,
54  Point const &tHat1, Point const &tHat2,
55  double error, unsigned max_beziers);
56 
57 Point darray_left_tangent(Point const d[], unsigned const len);
58 Point darray_left_tangent(Point const d[], unsigned const len, double const tolerance_sq);
59 Point darray_right_tangent(Point const d[], unsigned const length, double const tolerance_sq);
60 
61 template <typename iterator>
62 static void
63 cubic_bezier_poly_coeff(iterator b, Point *pc) {
64  double c[10] = {1,
65  -3, 3,
66  3, -6, 3,
67  -1, 3, -3, 1};
68 
69  int cp = 0;
70 
71  for(int i = 0; i < 4; i++) {
72  pc[i] = Point(0,0);
73  ++b;
74  }
75  for(int i = 0; i < 4; i++) {
76  --b;
77  for(int j = 0; j <= i; j++) {
78  pc[3 - j] += c[cp]*(*b);
79  cp++;
80  }
81  }
82 }
83 
84 }
85 #endif /* __SP_BEZIER_UTILS_H__ */
86 
87 /*
88  Local Variables:
89  mode:c++
90  c-file-style:"stroustrup"
91  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
92  indent-tabs-mode:nil
93  fill-column:99
94  End:
95 */
96 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
Definition: angle.h:38
int bezier_fit_cubic_r(Point bezier[], Point const data[], int const len, double const error, unsigned const max_beziers)
Definition: bezier-utils.cpp:131
int bezier_fit_cubic(Point *bezier, Point const *data, int len, double error)
Definition: bezier-utils.cpp:116
int bezier_fit_cubic_full(Point bezier[], int split_points[], Point const data[], int const len, Point const &tHat1, Point const &tHat2, double const error, unsigned const max_beziers)
Definition: bezier-utils.cpp:198
Point darray_right_tangent(Point const d[], unsigned const len, double const tolerance_sq)
Definition: bezier-utils.cpp:783
Point darray_left_tangent(Point const d[], unsigned const len)
Definition: bezier-utils.cpp:713
Point bezier_pt(unsigned const degree, Point const V[], double const t)
Definition: bezier-utils.cpp:673