diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-18 18:17:44 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-18 18:17:44 +0000 |
| commit | 71508f76c3ddc33c41664599f9c10bf84d994d62 (patch) | |
| tree | 68f69fd8c5b36c4f5a288bb8b2521405724cf9ce /src/helper | |
| parent | update to trunk (diff) | |
| parent | Latvian translation update (diff) | |
| download | inkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.tar.gz inkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.zip | |
update to trunk
(bzr r13879.1.11)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/helper/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/helper/geom.cpp | 49 | ||||
| -rw-r--r-- | src/helper/geom.h | 1 | ||||
| -rw-r--r-- | src/helper/mathfns.h | 82 |
5 files changed, 134 insertions, 0 deletions
diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index b0e473ddd..74ce2c85d 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -32,6 +32,7 @@ set(helper_SRC geom-nodetype.h geom.h gnome-utils.h + mathfns.h pixbuf-ops.h png-write.h stock-items.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 4c6437f13..5cb4cea8d 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -14,6 +14,7 @@ ink_common_sources += \ helper/geom-nodetype.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ + helper/mathfns.h \ helper/png-write.cpp \ helper/png-write.h \ helper/sp-marshal.cpp \ diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 6eba6e949..91689375f 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -556,6 +556,55 @@ pathv_to_linear( Geom::PathVector const &pathv, double /*maxdisp*/) return output; } +/* + * Converts all segments in all paths to Geom Cubic bezier. + * This is used in lattice2 LPE, maybe is better move the function to the effect + * But maybe could be usable by others, so i put here. + * The straight curve part is needed as it for the effect to work apropiately + */ +Geom::PathVector +pathv_to_cubicbezier( Geom::PathVector const &pathv) +{ + Geom::PathVector output; + double cubicGap = 0.01; + for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) { + output.push_back( Geom::Path() ); + output.back().start( pit->initialPoint() ); + output.back().close( pit->closed() ); + bool end_open = false; + if (pit->closed()) { + const Geom::Curve &closingline = pit->back_closed(); + if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { + end_open = true; + } + } + Geom::Path pitCubic = (Geom::Path)(*pit); + if(end_open && pit->closed()){ + pitCubic.close(false); + pitCubic.appendNew<Geom::LineSegment>( pitCubic.initialPoint() ); + pitCubic.close(true); + } + for (Geom::Path::const_iterator cit = pitCubic.begin(); cit != pitCubic.end_open(); ++cit) { + if (is_straight_curve(*cit)) { + Geom::CubicBezier b(cit->initialPoint(), cit->pointAt(0.3334) + Geom::Point(cubicGap,cubicGap), cit->finalPoint(), cit->finalPoint()); + output.back().append(b); + } else { + Geom::BezierCurve const *curve = dynamic_cast<Geom::BezierCurve const *>(&*cit); + if (curve && curve->order() == 3) { + Geom::CubicBezier b((*curve)[0], (*curve)[1], (*curve)[2], (*curve)[3]); + output.back().append(b); + } else { + // convert all other curve types to cubicbeziers + Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1); + output.back().append(cubicbezier_path); + } + } + } + } + + return output; +} + // The next routine is modified from curv4_div::recursive_bezier from file agg_curves.cpp //---------------------------------------------------------------------------- // Anti-Grain Geometry (AGG) - Version 2.5 diff --git a/src/helper/geom.h b/src/helper/geom.h index caff95733..3232d9fd5 100644 --- a/src/helper/geom.h +++ b/src/helper/geom.h @@ -27,6 +27,7 @@ void pathv_matrix_point_bbox_wind_distance ( Geom::PathVector const & pathv, Geo Geom::PathVector pathv_to_linear_and_cubic_beziers( Geom::PathVector const &pathv ); Geom::PathVector pathv_to_linear( Geom::PathVector const &pathv, double maxdisp ); +Geom::PathVector pathv_to_cubicbezier( Geom::PathVector const &pathv); void recursive_bezier4(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, const double x4, const double y4, std::vector<Geom::Point> &pointlist, diff --git a/src/helper/mathfns.h b/src/helper/mathfns.h new file mode 100644 index 000000000..8fb88dc26 --- /dev/null +++ b/src/helper/mathfns.h @@ -0,0 +1,82 @@ +/* + * ... some mathmatical functions + * + * Authors: + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 2007 Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_UTIL_MATHFNS_H +#define SEEN_INKSCAPE_UTIL_MATHFNS_H + +#include <2geom/point.h> + +namespace Inkscape { + +namespace Util { + +/** + * Returns area in triangle given by points; may be negative. + */ +inline double +triangle_area (Geom::Point p1, Geom::Point p2, Geom::Point p3) +{ + using Geom::X; + using Geom::Y; + return (p1[X]*p2[Y] + p1[Y]*p3[X] + p2[X]*p3[Y] - p2[Y]*p3[X] - p1[Y]*p2[X] - p1[X]*p3[Y]); +} + +/** + * \return x rounded to the nearest multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_nearest_multiple_plus(double x, double const c1, double const c0) +{ + return floor((x - c0) / c1 + .5) * c1 + c0; +} + +/** + * \return x rounded to the lower multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_lower_multiple_plus(double x, double const c1, double const c0 = 0) +{ + return floor((x - c0) / c1) * c1 + c0; +} + +/** + * \return x rounded to the upper multiple of c1 plus c0. + * + * \note + * If c1==0 (and c0 is finite), then returns +/-inf. This makes grid spacing of zero + * mean "ignore the grid in this dimension". + */ +inline double round_to_upper_multiple_plus(double x, double const c1, double const c0 = 0) +{ + return ceil((x - c0) / c1) * c1 + c0; +} + +} + +} + +#endif +/* + 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 : |
