Code

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