Code

dropper modes: replace undecipherable icons with text labels
[inkscape.git] / src / 2geom / path-intersection.h
1 #ifndef __GEOM_PATH_INTERSECTION_H
2 #define __GEOM_PATH_INTERSECTION_H
4 #include "path.h"
6 #include "crossing.h"
8 #include "sweep.h"
10 namespace Geom {
12 int winding(Path const &path, Point p);
13 bool path_direction(Path const &p);
15 inline bool contains(Path const & p, Point i, bool evenodd = true) {
16     return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0;
17 }
19 template<typename T>
20 Crossings curve_sweep(Path const &a, Path const &b) {
21     T t;
22     Crossings ret;
23     std::vector<Rect> bounds_a = bounds(a), bounds_b = bounds(b);
24     std::vector<std::vector<unsigned> > ixs = sweep_bounds(bounds_a, bounds_b);
25     for(unsigned i = 0; i < a.size(); i++) {
26         for(std::vector<unsigned>::iterator jp = ixs[i].begin(); jp != ixs[i].end(); jp++) {
27             Crossings cc = t.crossings(a[i], b[*jp]);
28             offset_crossings(cc, i, *jp);
29             ret.insert(ret.end(), cc.begin(), cc.end());
30         }
31     }
32     return ret;
33 }
35 struct SimpleCrosser : public Crosser<Path> {
36     Crossings crossings(Curve const &a, Curve const &b);
37     Crossings crossings(Path const &a, Path const &b) { return curve_sweep<SimpleCrosser>(a, b); }
38     CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b) { return Crosser<Path>::crossings(a, b); }
39 };
41 struct MonoCrosser : public Crosser<Path> {
42     Crossings crossings(Path const &a, Path const &b) { return crossings(std::vector<Path>(1,a), std::vector<Path>(1,b))[0]; }
43     CrossingSet crossings(std::vector<Path> const &a, std::vector<Path> const &b);
44 };
46 typedef SimpleCrosser DefaultCrosser;
48 std::vector<double> path_mono_splits(Path const &p);
50 CrossingSet crossings_among(std::vector<Path> const & p);
51 Crossings self_crossings(Path const & a);
53 inline Crossings crossings(Path const & a, Path const & b) {
54     DefaultCrosser c = DefaultCrosser();
55     return c.crossings(a, b);
56 }
58 inline CrossingSet crossings(std::vector<Path> const & a, std::vector<Path> const & b) {
59     DefaultCrosser c = DefaultCrosser();
60     return c.crossings(a, b);
61 }
63 }
65 #endif