diff options
Diffstat (limited to 'src/2geom')
| -rw-r--r-- | src/2geom/2geom.h | 75 | ||||
| -rw-r--r-- | src/2geom/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | src/2geom/bezier-curve.cpp | 2 | ||||
| -rw-r--r-- | src/2geom/bezier-curve.h | 1 | ||||
| -rw-r--r-- | src/2geom/generic-rect.h | 18 | ||||
| -rw-r--r-- | src/2geom/int-rect.h | 1 | ||||
| -rw-r--r-- | src/2geom/path-intersection.cpp | 4 | ||||
| -rw-r--r-- | src/2geom/point.cpp | 4 | ||||
| -rw-r--r-- | src/2geom/solve-bezier-parametric.cpp | 12 | ||||
| -rw-r--r-- | src/2geom/solver.h | 4 | ||||
| -rw-r--r-- | src/2geom/transforms.cpp | 41 |
11 files changed, 141 insertions, 32 deletions
diff --git a/src/2geom/2geom.h b/src/2geom/2geom.h new file mode 100644 index 000000000..000f3423d --- /dev/null +++ b/src/2geom/2geom.h @@ -0,0 +1,75 @@ +/** + * \file + * \brief Include everything + *//* + * Authors: + * Krzysztof KosiĆski <tweenk.pl@gmail.com> + * + * Copyright 2011 Authors + * + * 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. + */ + +#ifndef SEEN_LIB2GEOM_2GEOM_H +#define SEEN_LIB2GEOM_2GEOM_H + +#include <2geom/forward.h> + +// primitives +#include <2geom/coord.h> +#include <2geom/point.h> +#include <2geom/interval.h> +#include <2geom/rect.h> +#include <2geom/angle.h> +#include <2geom/ray.h> +#include <2geom/line.h> +#include <2geom/affine.h> +#include <2geom/transforms.h> + +// curves and paths +#include <2geom/curves.h> +#include <2geom/path.h> +#include <2geom/pathvector.h> + +// fragments +#include <2geom/d2.h> +#include <2geom/linear.h> +#include <2geom/bezier.h> +#include <2geom/sbasis.h> + +// others +#include <2geom/math-utils.h> +#include <2geom/utils.h> + +#endif // SEEN_LIB2GEOM_HEADER_H +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/2geom/CMakeLists.txt b/src/2geom/CMakeLists.txt index bc3f64bdc..dc261b5bd 100644 --- a/src/2geom/CMakeLists.txt +++ b/src/2geom/CMakeLists.txt @@ -27,6 +27,7 @@ set(2geom_SRC point.cpp poly.cpp quadtree.cpp + rect.cpp # recursive-bezier-intersection.cpp region.cpp sbasis-2d.cpp @@ -43,6 +44,7 @@ set(2geom_SRC svg-path-parser.cpp svg-path.cpp sweep.cpp + toposweep.cpp transforms.cpp utils.cpp @@ -76,10 +78,14 @@ set(2geom_SRC elliptical-arc.h exception.h forward.h + generic-interval.h + generic-rect.h geom.h hvlinesegment.h + int-interval.h + int-point.h + int-rect.h interval.h - isnan.h line.h linear.h math-utils.h @@ -89,7 +95,6 @@ set(2geom_SRC path.h pathvector.h piecewise.h - point-l.h point-ops.h point.h poly.h @@ -106,11 +111,11 @@ set(2geom_SRC sbasis.h shape.h solver.h - sturm.h svg-elliptical-arc.h svg-path-parser.h svg-path.h sweep.h + toposweep.h transforms.h utils.h diff --git a/src/2geom/bezier-curve.cpp b/src/2geom/bezier-curve.cpp index 8c40e5e42..6dfb0f0b3 100644 --- a/src/2geom/bezier-curve.cpp +++ b/src/2geom/bezier-curve.cpp @@ -108,7 +108,7 @@ BezierCurve::BezierCurve(std::vector<Point> const &pts) { inner = D2<Bezier>(Bezier::Order(pts.size() - 1), Bezier::Order(pts.size() - 1)); for (unsigned d = 0; d < 2; ++d) { - for(unsigned i = 0; i < pts.size(); i++) { + for (unsigned i = 0; i < pts.size(); i++) { inner[d][i] = pts[i][d]; } } diff --git a/src/2geom/bezier-curve.h b/src/2geom/bezier-curve.h index d13ff8321..c0224e850 100644 --- a/src/2geom/bezier-curve.h +++ b/src/2geom/bezier-curve.h @@ -47,7 +47,6 @@ class BezierCurve : public Curve { protected: D2<Bezier> inner; BezierCurve() {} - BezierCurve(BezierCurve const &b) : inner(b.inner) {} BezierCurve(D2<Bezier> const &b) : inner(b) {} BezierCurve(Bezier const &x, Bezier const &y) : inner(x, y) {} BezierCurve(std::vector<Point> const &pts); diff --git a/src/2geom/generic-rect.h b/src/2geom/generic-rect.h index 6dc57b169..2db30dfa9 100644 --- a/src/2geom/generic-rect.h +++ b/src/2geom/generic-rect.h @@ -54,10 +54,10 @@ class GenericOptRect; */ template <typename C> class GenericRect - : boost::additive< GenericRect<C>, typename CoordTraits<C>::PointType - , boost::equality_comparable< GenericRect<C> - , boost::orable< GenericRect<C> - , boost::orable< GenericRect<C>, typename CoordTraits<C>::OptRectType + : boost::additive< typename CoordTraits<C>::RectType, typename CoordTraits<C>::PointType + , boost::equality_comparable< typename CoordTraits<C>::RectType + , boost::orable< typename CoordTraits<C>::RectType + , boost::orable< typename CoordTraits<C>::RectType, typename CoordTraits<C>::OptRectType > > > > { typedef typename CoordTraits<C>::IntervalType CInterval; @@ -225,7 +225,7 @@ public: f[X].expandTo(p[X]); f[Y].expandTo(p[Y]); } /** @brief Enlarge the rectangle to contain the given rectangle. */ - void unionWith(GenericRect<C> const &b) { + void unionWith(CRect const &b) { f[X].unionWith(b[X]); f[Y].unionWith(b[Y]); } /** @brief Enlarge the rectangle to contain the given rectangle. @@ -265,7 +265,7 @@ public: return *this; } /** @brief Union two rectangles. */ - GenericRect<C> &operator|=(GenericRect<C> const &o) { + GenericRect<C> &operator|=(CRect const &o) { unionWith(o); return *this; } @@ -285,9 +285,9 @@ public: template <typename C> class GenericOptRect : public boost::optional<typename CoordTraits<C>::RectType> - , boost::orable< GenericOptRect<C> - , boost::andable< GenericOptRect<C> - , boost::andable< GenericOptRect<C>, typename CoordTraits<C>::RectType + , boost::orable< typename CoordTraits<C>::OptRectType + , boost::andable< typename CoordTraits<C>::OptRectType + , boost::andable< typename CoordTraits<C>::OptRectType, typename CoordTraits<C>::RectType > > > { typedef typename CoordTraits<C>::IntervalType CInterval; diff --git a/src/2geom/int-rect.h b/src/2geom/int-rect.h index a143b3ac5..567d42da5 100644 --- a/src/2geom/int-rect.h +++ b/src/2geom/int-rect.h @@ -32,7 +32,6 @@ #define LIB2GEOM_SEEN_INT_RECT_H #include <2geom/coord.h> -#include <2geom/int-point.h> #include <2geom/int-interval.h> #include <2geom/generic-rect.h> diff --git a/src/2geom/path-intersection.cpp b/src/2geom/path-intersection.cpp index be3e3b7cc..c38776304 100644 --- a/src/2geom/path-intersection.cpp +++ b/src/2geom/path-intersection.cpp @@ -226,8 +226,8 @@ intersect_polish_f (const gsl_vector * x, void *params, #endif static void -intersect_polish_root (Curve const &A, double &s, - Curve const &B, double &t) { +intersect_polish_root (Curve const &A, double &s, Curve const &B, double &t) +{ std::vector<Point> as, bs; as = A.pointAndDerivatives(s, 2); bs = B.pointAndDerivatives(t, 2); diff --git a/src/2geom/point.cpp b/src/2geom/point.cpp index cafc0fdba..3ad9dd1fd 100644 --- a/src/2geom/point.cpp +++ b/src/2geom/point.cpp @@ -49,8 +49,8 @@ namespace Geom { * from the origin (point at 0,0) to the stored coordinates, * and has methods implementing several vector operations (like length()). * - * @par Operator note - * @par + * @section OpNotePoint Operator note + * * Most operators are provided by Boost operator helpers, so they are not visible in this class. * If @a p, @a q, @a r denote points, @a s a floating-point scalar, and @a m a transformation matrix, * then the following operations are available: diff --git a/src/2geom/solve-bezier-parametric.cpp b/src/2geom/solve-bezier-parametric.cpp index 437f073a3..76cf65e17 100644 --- a/src/2geom/solve-bezier-parametric.cpp +++ b/src/2geom/solve-bezier-parametric.cpp @@ -68,13 +68,13 @@ find_parametric_bezier_roots(Geom::Point const *w, /* The control points */ break; } - // Otherwise, solve recursively after subdividing control polygon - std::vector<Geom::Point> Left(degree + 1); // New left and right - std::vector<Geom::Point> Right(degree + 1); // control polygons - Bezier(w, degree, 0.5, &Left[0], &Right[0]); + /* Otherwise, solve recursively after subdividing control polygon */ + Geom::Point Left[degree+1], /* New left and right */ + Right[degree+1]; /* control polygons */ + Bezier(w, degree, 0.5, Left, Right); total_subs ++; - find_parametric_bezier_roots(&Left[0], degree, solutions, depth + 1); - find_parametric_bezier_roots(&Right[0], degree, solutions, depth + 1); + find_parametric_bezier_roots(Left, degree, solutions, depth+1); + find_parametric_bezier_roots(Right, degree, solutions, depth+1); } diff --git a/src/2geom/solver.h b/src/2geom/solver.h index 5e77f13dc..793939b2a 100644 --- a/src/2geom/solver.h +++ b/src/2geom/solver.h @@ -1,7 +1,7 @@ /** * \file - * \brief \todo brief description - * + * \brief Finding roots of Bernstein-Bezier polynomials + *//* * Authors: * ? <?@?.?> * diff --git a/src/2geom/transforms.cpp b/src/2geom/transforms.cpp index 2658719c4..b8355cadc 100644 --- a/src/2geom/transforms.cpp +++ b/src/2geom/transforms.cpp @@ -35,9 +35,21 @@ #include <boost/concept_check.hpp> #include <2geom/point.h> #include <2geom/transforms.h> +#include <2geom/rect.h> namespace Geom { +/** @brief Zoom between rectangles. + * Given two rectangles, compute a zoom that maps one to the other. + * Rectangles are assumed to have the same aspect ratio. */ +Zoom Zoom::map_rect(Rect const &old_r, Rect const &new_r) +{ + Zoom ret; + ret._scale = new_r.width() / old_r.width(); + ret._trans = new_r.min() - old_r.min(); + return ret; +} + // Point transformation methods. Point &Point::operator*=(Translate const &t) { @@ -68,6 +80,14 @@ Point &Point::operator*=(VShear const &v) _pt[Y] += v.f * _pt[Y]; return *this; } +Point &Point::operator*=(Zoom const &z) +{ + _pt[X] += z._trans[X]; + _pt[Y] += z._trans[Y]; + _pt[X] *= z._scale; + _pt[Y] *= z._scale; + return *this; +} // Affine multiplication methods. @@ -110,6 +130,14 @@ Affine &Affine::operator*=(VShear const &v) { return *this; } +Affine &Affine::operator*=(Zoom const &z) { + _c[0] *= z._scale; _c[1] *= z._scale; + _c[2] *= z._scale; _c[3] *= z._scale; + _c[4] += z._trans[X]; _c[5] += z._trans[Y]; + _c[4] *= z._scale; _c[5] *= z._scale; + return *this; +} + // this checks whether the requirements of TransformConcept are satisfied for all transforms. // if you add a new transform type, include it here! void check_transforms() @@ -120,6 +148,7 @@ void check_transforms() BOOST_CONCEPT_ASSERT((TransformConcept<Rotate>)); BOOST_CONCEPT_ASSERT((TransformConcept<HShear>)); BOOST_CONCEPT_ASSERT((TransformConcept<VShear>)); + BOOST_CONCEPT_ASSERT((TransformConcept<Zoom>)); BOOST_CONCEPT_ASSERT((TransformConcept<Affine>)); // Affine is also a transform #endif @@ -130,14 +159,16 @@ void check_transforms() Rotate r(Rotate::identity()); HShear h(HShear::identity()); VShear v(VShear::identity()); + Zoom z(Zoom::identity()); // notice that the first column is always the same and enumerates all transform types, // while the second one changes to each transform type in turn. - m = t * t; m = t * s; m = t * r; m = t * h; m = t * v; - m = s * t; m = s * s; m = s * r; m = s * h; m = s * v; - m = r * t; m = r * s; m = r * r; m = r * h; m = r * v; - m = h * t; m = h * s; m = h * r; m = h * h; m = h * v; - m = v * t; m = v * s; m = v * r; m = v * h; m = v * v; + m = t * t; m = t * s; m = t * r; m = t * h; m = t * v; m = t * z; + m = s * t; m = s * s; m = s * r; m = s * h; m = s * v; m = s * z; + m = r * t; m = r * s; m = r * r; m = r * h; m = r * v; m = r * z; + m = h * t; m = h * s; m = h * r; m = h * h; m = h * v; m = h * z; + m = v * t; m = v * s; m = v * r; m = v * h; m = v * v; m = v * z; + m = z * t; m = z * s; m = z * r; m = z * h; m = z * v; m = z * z; } } |
