Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
bezier.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2006, 2007 Aaron Spike <aaron@ekips.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it either under the terms of the GNU Lesser General Public
6 * License version 2.1 as published by the Free Software Foundation
7 * (the "LGPL") or, at your option, under the terms of the Mozilla
8 * Public License Version 1.1 (the "MPL"). If you do not alter this
9 * notice, a recipient may use your version of this file under either
10 * the MPL or the LGPL.
11 *
12 * You should have received a copy of the LGPL along with this library
13 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * You should have received a copy of the MPL along with this library
16 * in the file COPYING-MPL-1.1
17 *
18 * The contents of this file are subject to the Mozilla Public License
19 * Version 1.1 (the "License"); you may not use this file except in
20 * compliance with the License. You may obtain a copy of the License at
21 * http://www.mozilla.org/MPL/
22 *
23 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
24 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
25 * the specific language governing rights and limitations.
26 *
27 */
28
29#include <boost/python.hpp>
30#include <boost/python/implicit.hpp>
31#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
32
33#include "py2geom.h"
34#include "helpers.h"
35
36#include "2geom/bezier.h"
37#include "2geom/point.h"
38
39using namespace boost::python;
40
41double bezier_getitem(Geom::Bezier const& p, int index)
42{
43 int D = p.size();
44 if (index < 0)
45 {
46 index = D + index;
47 }
48 if ((index < 0) || (index > (D - 1))) {
49 PyErr_SetString(PyExc_IndexError, "index out of range");
50 boost::python::throw_error_already_set();
51 }
52 return p[index];
53}
54
56 //bezier.h
57
58 class_<Geom::Bezier>("Bezier", init<double>())
59 .def(init<double, double>())
60 .def(init<double, double, double>())
61 .def(init<double, double, double, double>())
62 .def(self_ns::str(self))
63 //TODO: add important vector funcs
64 .def("__getitem__", &bezier_getitem)
65
66 .def("isZero", &Geom::Bezier::isZero)
67 .def("isFinite", &Geom::Bezier::isFinite)
68 .def("at0", (double (Geom::Bezier::*)() const) &Geom::Bezier::at0)
69 .def("at1", (double (Geom::Bezier::*)() const) &Geom::Bezier::at1)
70 .def("valueAt", &Geom::Bezier::valueAt)
71 .def("toSBasis", &Geom::Bezier::toSBasis)
72
73 .def(self + float())
74 .def(self - float())
75
76 .def(self * float())
77 ;
78};
79
80/*
81 Local Variables:
82 mode:c++
83 c-file-style:"stroustrup"
84 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
85 indent-tabs-mode:nil
86 fill-column:99
87 End:
88*/
89// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
Bernstein-Bezier polynomial.
Polynomial in Bernstein-Bezier basis.
Definition bezier.h:126
bool isFinite() const
Definition bezier.h:266
bool isZero(double eps=EPSILON) const
Definition bezier.h:254
unsigned size() const
Definition bezier.h:147
Coord at0() const
Definition bezier.h:272
SBasis toSBasis() const
Definition bezier.cpp:187
Coord valueAt(double t) const
Definition bezier.h:277
Coord at1() const
Definition bezier.h:274
void wrap_bezier()
Definition bezier.cpp:55
double bezier_getitem(Geom::Bezier const &p, int index)
Definition bezier.cpp:41
int index