Code

cec1c144a0ebcff0e3f1e3b6e162b6ebc0dbfd13
[inkscape.git] / src / 2geom / pathvector.h
1 /*
2  * PathVector - std::vector containing Geom::Path
3  * This file provides a set of operations that can be performed on PathVector,
4  * e.g. an affine transform.
5  *
6  * Authors:
7  *  Johan Engelen <goejendaagh@zonnet.nl>
8  * 
9  * Copyright 2008  authors
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it either under the terms of the GNU Lesser General Public
13  * License version 2.1 as published by the Free Software Foundation
14  * (the "LGPL") or, at your option, under the terms of the Mozilla
15  * Public License Version 1.1 (the "MPL"). If you do not alter this
16  * notice, a recipient may use your version of this file under either
17  * the MPL or the LGPL.
18  *
19  * You should have received a copy of the LGPL along with this library
20  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  * You should have received a copy of the MPL along with this library
23  * in the file COPYING-MPL-1.1
24  *
25  * The contents of this file are subject to the Mozilla Public License
26  * Version 1.1 (the "License"); you may not use this file except in
27  * compliance with the License. You may obtain a copy of the License at
28  * http://www.mozilla.org/MPL/
29  *
30  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
31  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
32  * the specific language governing rights and limitations.
33  */
35 #ifndef SEEN_GEOM_PATHVECTOR_H
36 #define SEEN_GEOM_PATHVECTOR_H
38 #include <2geom/forward.h>
39 #include <2geom/path.h>
40 #include <2geom/rect.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();
102 PathVector reverse_paths_and_order (PathVector const & path_in);
104 Rect bounds_fast( PathVector const & pv );
105 Rect 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 };
112 PathVectorPosition nearestPoint(PathVector const & path_in, Point const& _point, double *distance_squared = NULL);
115 } // end namespace Geom
117 #endif // SEEN_GEOM_PATHVECTOR_H
119 /*
120   Local Variables:
121   mode:c++
122   c-file-style:"stroustrup"
123   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
124   indent-tabs-mode:nil
125   fill-column:99
126   End:
127 */
128 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :