/* * Copyright 2006, 2007 Aaron Spike * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * (the "LGPL") or, at your option, under the terms of the Mozilla * Public License Version 1.1 (the "MPL"). If you do not alter this * notice, a recipient may use your version of this file under either * the MPL or the LGPL. * * You should have received a copy of the LGPL along with this library * in the file COPYING-LGPL-2.1; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the MPL along with this library * in the file COPYING-MPL-1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY * OF ANY KIND, either express or implied. See the LGPL or the MPL for * the specific language governing rights and limitations. * */ #include #include #include #include "2geom/sbasis.h" #include "2geom/piecewise.h" #include "2geom/d2.h" #include "2geom/sbasis-math.h" #include "2geom/sbasis-geometric.h" #include "py2geom.h" #include "helpers.h" using namespace boost::python; // helpers for point tuple pwd2sb_centroid(Geom::Piecewise > const &pw) { Geom::Point p; double a; Geom::centroid(pw, p, a); return boost::python::make_tuple(p, a); } void (Geom::Piecewise::*push_pwsb)(Geom::SBasis const &, double) = &Geom::Piecewise::push; void (Geom::Piecewise::*push_seg_pwsb)(Geom::SBasis const &) = &Geom::Piecewise::push_seg; Geom::Piecewise (*portion_pwsb)(const Geom::Piecewise &, double, double) = &Geom::portion; void (Geom::Piecewise>::*push_pwd2sb)(Geom::D2 const &, double) = &Geom::Piecewise>::push; void (Geom::Piecewise>::*push_seg_pwd2sb)(Geom::D2 const &) = &Geom::Piecewise>::push_seg; Geom::Piecewise> (*portion_pwd2sb)(const Geom::Piecewise > &, double, double) = &Geom::portion; std::vector (*roots_pwsb)(const Geom::Piecewise &) = &Geom::roots; //Geom::Piecewise (*multiply_pwsb)(Geom::Piecewise const &, Geom::Piecewise const &) = &Geom::multiply; Geom::Piecewise (*divide_pwsb)(Geom::Piecewise const &, Geom::Piecewise const &, unsigned) = &Geom::divide; Geom::Piecewise (*compose_pwsb_sb)(Geom::Piecewise const &, Geom::SBasis const &) = &Geom::compose; Geom::Piecewise (*compose_pwsb)(Geom::Piecewise const &, Geom::Piecewise const &) = &Geom::compose; Geom::Piecewise (*abs_pwsb)(Geom::Piecewise const &) = &Geom::abs; Geom::Piecewise (*min_pwsb)(Geom::Piecewise const &, Geom::Piecewise const &) = &Geom::min; Geom::Piecewise (*max_pwsb)(Geom::Piecewise const &, Geom::Piecewise const &) = &Geom::max; Geom::Piecewise (*signSb_pwsb)(Geom::Piecewise const &) = &Geom::signSb; Geom::Piecewise (*sqrt_pwsb)(Geom::Piecewise const &, double, int) = &Geom::sqrt; Geom::Piecewise (*sin_pwsb)(Geom::Piecewise const &, double, int) = &Geom::sin; Geom::Piecewise (*cos_pwsb)(Geom::Piecewise const &, double, int) = &Geom::cos; //Geom::Piecewise (*log_pwsb)(Geom::Piecewise const &, double, int) = &Geom::log; Geom::Piecewise (*reciprocal_pwsb)(Geom::Piecewise const &, double, int) = &Geom::reciprocal; Geom::FragmentConcept::BoundsType (*bounds_fast_pwsb)(Geom::Piecewise const &) = &Geom::bounds_fast; Geom::FragmentConcept::BoundsType (*bounds_exact_pwsb)(Geom::Piecewise const &) = &Geom::bounds_exact; Geom::FragmentConcept::BoundsType (*bounds_local_pwsb)(Geom::Piecewise const &, const Geom::OptInterval &) = &Geom::bounds_local; Geom::SBasis getitem_pwsb(Geom::Piecewise const &p, int index) { unsigned D = p.size(); unsigned i = index; if (index < 0) { i = index = D + index; } if (index < 0 || i > (D - 1)) { PyErr_SetString(PyExc_IndexError, "index out of range"); boost::python::throw_error_already_set(); } return p[i]; } Geom::Piecewise > (*unitVector_pwd2sb)(Geom::Piecewise > const &, double, unsigned int) = &Geom::unitVector; Geom::Piecewise (*arcLengthSb_pwd2sb)(Geom::Piecewise > const &, double) = &Geom::arcLengthSb; Geom::Piecewise > (*rot90_pwd2sb)(Geom::Piecewise > const &) = &Geom::rot90; void wrap_pw() { class_ >("SBasisVec") .def(vector_indexing_suite >()) ; class_ > >("D2SBasisVec") .def(vector_indexing_suite > >()) ; def("portion", portion_pwsb); def("portion", portion_pwd2sb); //def("partition", &partition); def("roots", roots_pwsb); //def("multiply", multiply_pwsb); def("divide", divide_pwsb); def("compose", compose_pwsb_sb); def("compose", compose_pwsb); def("abs", abs_pwsb); def("min", min_pwsb); def("max", max_pwsb); def("signSb", signSb_pwsb); def("sqrt", sqrt_pwsb); def("cos", cos_pwsb); def("sin", sin_pwsb); //def("log", log_pwsb); def("reciprocal", reciprocal_pwsb); def("bounds_fast", bounds_fast_pwsb); def("bounds_exact", bounds_exact_pwsb); def("bounds_local", bounds_local_pwsb); def("derivative", (Geom::Piecewise (*)(Geom::Piecewise const & ))&Geom::derivative); def("integral", (Geom::Piecewise (*)(Geom::Piecewise const & ))&Geom::integral); def("derivative", (Geom::Piecewise > (*)(Geom::Piecewise > const &)) &Geom::derivative); def("rot90", rot90_pwd2sb); def("unit_vector", unitVector_pwd2sb); def("arcLengthSb", arcLengthSb_pwd2sb); class_ >("PiecewiseSBasis", init<>()) .def(init()) .def(init()) .def("__getitem__", getitem_pwsb) .def("__call__", &Geom::Piecewise::valueAt) .def_readonly("cuts", &Geom::Piecewise::cuts) .def_readonly("segs", &Geom::Piecewise::segs) .def("at0", &Geom::Piecewise::firstValue) .def("at1", &Geom::Piecewise::lastValue) .def("valueAt", &Geom::Piecewise::valueAt) .def("size", &Geom::Piecewise::size) .def("empty", &Geom::Piecewise::empty) .def("push", push_pwsb) .def("push_cut", &Geom::Piecewise::push_cut) .def("push_seg", push_seg_pwsb) .def("segN", &Geom::Piecewise::segN) .def("segT", &Geom::Piecewise::segT) .def("offsetDomain", &Geom::Piecewise::offsetDomain) .def("scaleDomain", &Geom::Piecewise::scaleDomain) .def("setDomain", &Geom::Piecewise::setDomain) .def("concat", &Geom::Piecewise::concat) .def("continuousConcat", &Geom::Piecewise::continuousConcat) .def("invariants", &Geom::Piecewise::invariants) .def(self + double()) .def(-self) .def(self += double()) .def(self -= double()) .def(self /= double()) .def(self * double()) .def(self *= double()) .def(self + self) .def(self - self) .def(self * self) .def(self *= self) ; class_ > >("PiecewiseD2SBasis", init<>()) .def(init >()) .def("__getitem__", getitem_pwsb) .def("__call__", &Geom::Piecewise >::valueAt) .def_readonly("cuts", &Geom::Piecewise >::cuts) .def_readonly("segs", &Geom::Piecewise >::segs) .def("valueAt", &Geom::Piecewise >::valueAt) .def("size", &Geom::Piecewise >::size) .def("empty", &Geom::Piecewise >::empty) .def("push", push_pwd2sb) .def("push_cut", &Geom::Piecewise >::push_cut) .def("push_seg", push_seg_pwd2sb) .def("segN", &Geom::Piecewise >::segN) .def("segT", &Geom::Piecewise >::segT) .def("offsetDomain", &Geom::Piecewise >::offsetDomain) .def("scaleDomain", &Geom::Piecewise >::scaleDomain) .def("setDomain", &Geom::Piecewise >::setDomain) .def("concat", &Geom::Piecewise >::concat) .def("continuousConcat", &Geom::Piecewise >::continuousConcat) .def("invariants", &Geom::Piecewise >::invariants) //.def(self + double()) .def(-self) //.def(self += double()) //.def(self -= double()) //.def(self /= double()) .def(self * double()) .def(Geom::Piecewise() * self) .def(self *= double()) .def(self + self) .def(self - self) //.def(self * self) //.def(self *= self) ; def("centroid", pwd2sb_centroid); def("make_cuts_independent", Geom::make_cuts_independent); }; /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :