Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / src / 2geom / path-intersection.h
1 /**
2  * \file
3  * \brief  \todo brief description
4  *
5  * Authors:
6  *      ? <?@?.?>
7  * 
8  * Copyright ?-?  authors
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it either under the terms of the GNU Lesser General Public
12  * License version 2.1 as published by the Free Software Foundation
13  * (the "LGPL") or, at your option, under the terms of the Mozilla
14  * Public License Version 1.1 (the "MPL"). If you do not alter this
15  * notice, a recipient may use your version of this file under either
16  * the MPL or the LGPL.
17  *
18  * You should have received a copy of the LGPL along with this library
19  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  * You should have received a copy of the MPL along with this library
22  * in the file COPYING-MPL-1.1
23  *
24  * The contents of this file are subject to the Mozilla Public License
25  * Version 1.1 (the "License"); you may not use this file except in
26  * compliance with the License. You may obtain a copy of the License at
27  * http://www.mozilla.org/MPL/
28  *
29  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31  * the specific language governing rights and limitations.
32  *
33  */
35 #ifndef __GEOM_PATH_INTERSECTION_H
36 #define __GEOM_PATH_INTERSECTION_H
38 #include <2geom/path.h>
40 #include <2geom/crossing.h>
42 #include <2geom/sweep.h>
44 namespace Geom {
46 int winding(Path const &path, Point p);
47 bool path_direction(Path const &p);
49 inline bool contains(Path const & p, Point i, bool evenodd = true) {
50     return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0;
51 }
53 template<typename T>
54 Crossings curve_sweep(Path const &a, Path const &b) {
55     T t;
56     Crossings ret;
57     std::vector<Rect> bounds_a = bounds(a), bounds_b = bounds(b);
58     std::vector<std::vector<unsigned> > ixs = sweep_bounds(bounds_a, bounds_b);
59     for(unsigned i = 0; i < a.size(); i++) {
60         for(std::vector<unsigned>::iterator jp = ixs[i].begin(); jp != ixs[i].end(); jp++) {
61             Crossings cc = t.crossings(a[i], b[*jp]);
62             offset_crossings(cc, i, *jp);
63             ret.insert(ret.end(), cc.begin(), cc.end());
64         }
65     }
66     return ret;
67 }
69 Crossings pair_intersect(Curve const & A, Interval const &Ad,
70                     Curve const & B, Interval const &Bd);
71 Crossings mono_intersect(Curve const & A, Interval const &Ad,
72                     Curve const & B, Interval const &Bd);
73                     
74 struct SimpleCrosser : public Crosser<Path> {
75     Crossings crossings(Curve const &a, Curve const &b);
76     Crossings crossings(Path const &a, Path const &b) { return curve_sweep<SimpleCrosser>(a, b); }
77     CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b) { return Crosser<Path>::crossings(a, b); }
78 };
80 struct MonoCrosser : public Crosser<Path> {
81     Crossings crossings(Path const &a, Path const &b) { return crossings(std::vector<Path>(1,a), std::vector<Path>(1,b))[0]; }
82     CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b);
83 };
85 typedef SimpleCrosser DefaultCrosser;
87 std::vector<double> path_mono_splits(Path const &p);
89 CrossingSet crossings_among(std::vector<Path> const & p);
90 Crossings self_crossings(Path const & a);
92 inline Crossings crossings(Curve const & a, Curve const & b) {
93     DefaultCrosser c = DefaultCrosser();
94     return c.crossings(a, b);
95 }
97 inline Crossings crossings(Path const & a, Path const & b) {
98     DefaultCrosser c = DefaultCrosser();
99     return c.crossings(a, b);
102 inline CrossingSet crossings(std::vector<Path> const & a, std::vector<Path> const & b) {
103     DefaultCrosser c = DefaultCrosser();
104     return c.crossings(a, b);
109 #endif
111 /*
112   Local Variables:
113   mode:c++
114   c-file-style:"stroustrup"
115   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
116   indent-tabs-mode:nil
117   fill-column:99
118   End:
119 */
120 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :