Code

update 2geom
[inkscape.git] / src / 2geom / pathvector.cpp
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_CPP
36 #define SEEN_GEOM_PATHVECTOR_CPP
38 #include "pathvector.h"
40 #include "path.h"
41 #include "matrix.h"
43 namespace Geom {
45 // TODO: see which of these functions can be inlined for optimization
47 PathVector operator* (PathVector const & path_in, Matrix const &m)
48 {
49     PathVector path_out;
50     for(PathVector::const_iterator it = path_in.begin(); it != path_in.end(); ++it) {
51         path_out.push_back( (*it) * m );
52     }
53     return path_out;
54 }
56 /**
57  * Reverses all Paths and the order of paths in the vector as well
58  **/
59 PathVector reverse_paths_and_order (PathVector const & path_in)
60 {
61     PathVector path_out;
62     for (PathVector::const_reverse_iterator it = path_in.rbegin(); it != path_in.rend(); ++it) {
63         path_out.push_back( (*it).reverse() );
64     }
65     return path_out;
66 }
68 Rect bounds_fast( PathVector const& pv )
69 {
70     typedef PathVector::const_iterator const_iterator;
71     
72     Rect bound;
73     if (pv.empty()) return bound;
74     
75     bound = (pv.begin())->boundsFast();
76     double top = bound.top();
77     double bottom = bound.bottom();
78     double left = bound.left();
79     double right = bound.right();
80     for (const_iterator it = ++(pv.begin()); it != pv.end(); ++it)
81     {
82         bound = it->boundsFast();
83         if ( top > bound.top() )           top = bound.top();
84         if ( bottom < bound.bottom() )     bottom = bound.bottom();
85         if ( left > bound.left() )         left = bound.left();
86         if ( right < bound.right() )       right = bound.right();
87     }
88     bound[0][0] = left;
89     bound[0][1] = right;
90     bound[1][0] = top;
91     bound[1][1] = bottom;
92     return bound;
93 }
95 Rect bounds_exact( PathVector const& pv )
96 {
97     typedef PathVector::const_iterator const_iterator;
98     
99     Rect bound;
100     if (pv.empty()) return bound;
101     
102     bound = (pv.begin())->boundsExact();
103     double top = bound.top();
104     double bottom = bound.bottom();
105     double left = bound.left();
106     double right = bound.right();
107     for (const_iterator it = ++(pv.begin()); it != pv.end(); ++it)
108     {
109         bound = it->boundsExact();
110         if ( top > bound.top() )           top = bound.top();
111         if ( bottom < bound.bottom() )     bottom = bound.bottom();
112         if ( left > bound.left() )         left = bound.left();
113         if ( right < bound.right() )       right = bound.right();
114     }
115     bound[0][0] = left;
116     bound[0][1] = right;
117     bound[1][0] = top;
118     bound[1][1] = bottom;
119     return bound;
122 } // namespace Geom
124 #endif // SEEN_GEOM_PATHVECTOR_CPP
126 /*
127   Local Variables:
128   mode:c++
129   c-file-style:"stroustrup"
130   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131   indent-tabs-mode:nil
132   fill-column:99
133   End:
134 */
135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :