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/rect.h>
42 #include <2geom/transforms.h>
44 namespace Geom {
46 typedef std::vector<Geom::Path> PathVector;
48 /* general path transformation: */
49 inline
50 void operator*= (PathVector & path_in, Matrix const &m) {
51 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
52 (*it) *= m;
53 }
54 }
55 inline
56 PathVector operator*(PathVector const & path_in, Matrix const &m) {
57 PathVector ret(path_in);
58 ret *= m;
59 return ret;
60 }
62 /* specific path transformations: Translation:
63 * This makes it possible to make optimized implementations for Translate transforms */
64 inline
65 void operator*= (PathVector & path_in, Translate const &m) {
66 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
67 (*it) *= m;
68 }
69 }
70 inline
71 PathVector operator*(PathVector const & path_in, Translate const &m) {
72 PathVector ret(path_in);
73 ret *= m;
74 return ret;
75 }
77 /* user friendly approach to Translate transforms: just add an offset Point to the whole path */
78 inline
79 void operator+=(PathVector &path_in, Point const &p) {
80 for(PathVector::iterator it = path_in.begin(); it != path_in.end(); ++it) {
81 (*it) *= Translate(p);
82 }
83 }
84 inline
85 PathVector operator+(PathVector const &path_in, Point const &p) {
86 PathVector ret(path_in);
87 ret *= Translate(p);
88 return ret;
89 }
91 inline
92 Geom::Point initialPoint(PathVector const &path_in)
93 {
94 return path_in.front().initialPoint();
95 }
97 inline
98 Geom::Point finalPoint(PathVector const &path_in)
99 {
100 return path_in.back().finalPoint();
101 }
103 PathVector reverse_paths_and_order (PathVector const & path_in);
105 OptRect bounds_fast( PathVector const & pv );
106 OptRect bounds_exact( PathVector const & pv );
108 struct PathVectorPosition {
109 // pathvector[path_nr].pointAt(t) is the position
110 unsigned int path_nr;
111 double t;
112 PathVectorPosition() {}
113 PathVectorPosition(unsigned int path_nr,
114 double t) : path_nr(path_nr), t(t) {}
115 };
116 boost::optional<PathVectorPosition> nearestPoint(PathVector const & path_in, Point const& _point, double *distance_squared = NULL);
118 std::vector<PathVectorPosition> allNearestPoints(PathVector const & path_in, Point const& _point, double *distance_squared = NULL);
120 inline
121 Point pointAt(PathVector const & path_in, PathVectorPosition const pvp) {
122 return path_in[pvp.path_nr].pointAt(pvp.t);
123 }
127 } // end namespace Geom
129 #endif // SEEN_GEOM_PATHVECTOR_H
131 /*
132 Local Variables:
133 mode:c++
134 c-file-style:"stroustrup"
135 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
136 indent-tabs-mode:nil
137 fill-column:99
138 End:
139 */
140 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :