1 /**
2 * \file
3 * \brief PathVector - std::vector containing Geom::Path
4 * This file provides a set of operations that can be performed on PathVector,
5 * e.g. an affine transform.
6 *
7 * Authors:
8 * Johan Engelen <goejendaagh@zonnet.nl>
9 *
10 * Copyright 2008 authors
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it either under the terms of the GNU Lesser General Public
14 * License version 2.1 as published by the Free Software Foundation
15 * (the "LGPL") or, at your option, under the terms of the Mozilla
16 * Public License Version 1.1 (the "MPL"). If you do not alter this
17 * notice, a recipient may use your version of this file under either
18 * the MPL or the LGPL.
19 *
20 * You should have received a copy of the LGPL along with this library
21 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * You should have received a copy of the MPL along with this library
24 * in the file COPYING-MPL-1.1
25 *
26 * The contents of this file are subject to the Mozilla Public License
27 * Version 1.1 (the "License"); you may not use this file except in
28 * compliance with the License. You may obtain a copy of the License at
29 * http://www.mozilla.org/MPL/
30 *
31 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
32 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
33 * the specific language governing rights and limitations.
34 */
36 #ifndef SEEN_GEOM_PATHVECTOR_H
37 #define SEEN_GEOM_PATHVECTOR_H
39 #include <2geom/forward.h>
40 #include <2geom/path.h>
41 #include <2geom/transforms.h>
43 namespace Geom {
45 typedef std::vector<Geom::Path> PathVector;
47 /* general path transformation: */
48 inline
49 void operator*= (PathVector & path_in, Matrix const &m) {
50 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
51 (*it) *= m;
52 }
53 }
54 inline
55 PathVector operator*(PathVector const & path_in, Matrix const &m) {
56 PathVector ret(path_in);
57 ret *= m;
58 return ret;
59 }
61 /* specific path transformations: Translation:
62 * This makes it possible to make optimized implementations for Translate transforms */
63 inline
64 void operator*= (PathVector & path_in, Translate const &m) {
65 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
66 (*it) *= m;
67 }
68 }
69 inline
70 PathVector operator*(PathVector const & path_in, Translate const &m) {
71 PathVector ret(path_in);
72 ret *= m;
73 return ret;
74 }
76 /* user friendly approach to Translate transforms: just add an offset Point to the whole path */
77 inline
78 void operator+=(PathVector &path_in, Point const &p) {
79 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
80 (*it) *= Translate(p);
81 }
82 }
83 inline
84 PathVector operator+(PathVector const &path_in, Point const &p) {
85 PathVector ret(path_in);
86 ret *= Translate(p);
87 return ret;
88 }
90 inline
91 Geom::Point initialPoint(PathVector const &path_in)
92 {
93 return path_in.front().initialPoint();
94 }
96 inline
97 Geom::Point finalPoint(PathVector const &path_in)
98 {
99 return path_in.back().finalPoint();
100 }
102 PathVector reverse_paths_and_order (PathVector const & path_in);
104 OptRect bounds_fast( PathVector const & pv );
105 OptRect bounds_exact( PathVector const & pv );
107 struct PathVectorPosition {
108 // pathvector[path_nr].pointAt(t) is the position
109 unsigned int path_nr;
110 double t;
111 PathVectorPosition() {}
112 PathVectorPosition(unsigned int path_nr,
113 double t) : path_nr(path_nr), t(t) {}
114 };
115 boost::optional<PathVectorPosition> nearestPoint(PathVector const & path_in, Point const& _point, double *distance_squared = NULL);
117 std::vector<PathVectorPosition> allNearestPoints(PathVector const & path_in, Point const& _point, double *distance_squared = NULL);
119 inline
120 Point pointAt(PathVector const & path_in, PathVectorPosition const pvp) {
121 return path_in[pvp.path_nr].pointAt(pvp.t);
122 }
126 } // end namespace Geom
128 #endif // SEEN_GEOM_PATHVECTOR_H
130 /*
131 Local Variables:
132 mode:c++
133 c-file-style:"stroustrup"
134 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
135 indent-tabs-mode:nil
136 fill-column:99
137 End:
138 */
139 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :