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 struct SimpleCrosser : public Crosser<Path> {
70 Crossings crossings(Curve const &a, Curve const &b);
71 Crossings crossings(Path const &a, Path const &b) { return curve_sweep<SimpleCrosser>(a, b); }
72 CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b) { return Crosser<Path>::crossings(a, b); }
73 };
75 struct MonoCrosser : public Crosser<Path> {
76 Crossings crossings(Path const &a, Path const &b) { return crossings(std::vector<Path>(1,a), std::vector<Path>(1,b))[0]; }
77 CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b);
78 };
80 typedef SimpleCrosser DefaultCrosser;
82 std::vector<double> path_mono_splits(Path const &p);
84 CrossingSet crossings_among(std::vector<Path> const & p);
85 Crossings self_crossings(Path const & a);
87 inline Crossings crossings(Curve const & a, Curve const & b) {
88 DefaultCrosser c = DefaultCrosser();
89 return c.crossings(a, b);
90 }
92 inline Crossings crossings(Path const & a, Path const & b) {
93 DefaultCrosser c = DefaultCrosser();
94 return c.crossings(a, b);
95 }
97 inline CrossingSet crossings(std::vector<Path> const & a, std::vector<Path> const & b) {
98 DefaultCrosser c = DefaultCrosser();
99 return c.crossings(a, b);
100 }
102 }
104 #endif
106 /*
107 Local Variables:
108 mode:c++
109 c-file-style:"stroustrup"
110 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
111 indent-tabs-mode:nil
112 fill-column:99
113 End:
114 */
115 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :