Scribus
Open source desktop publishing at your fingertips
path-intersection.h
1 #ifndef __GEOM_PATH_INTERSECTION_H
2 #define __GEOM_PATH_INTERSECTION_H
3 
4 #include "path.h"
5 
6 #include "crossing.h"
7 
8 #include "sweep.h"
9 
10 namespace Geom {
11 
12 int winding(Path const &path, Point p);
13 bool path_direction(Path const &p);
14 
15 inline bool contains(Path const & p, Point i, bool evenodd = true) {
16  return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0;
17 }
18 
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 }
34 
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 };
40 
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 };
45 
47 
48 std::vector<double> path_mono_splits(Path const &p);
49 
50 CrossingSet crossings_among(std::vector<Path> const & p);
51 Crossings self_crossings(Path const & a);
52 
53 inline Crossings crossings(Path const & a, Path const & b) {
54  DefaultCrosser c = DefaultCrosser();
55  return c.crossings(a, b);
56 }
57 
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 }
62 
63 }
64 
65 #endif
Definition: angle.h:38
Definition: path-intersection.h:35
Definition: path.h:419
Definition: path.h:52
Definition: crossing.h:94
Definition: path-intersection.h:41