1 #ifndef __GEOM_CROSSING_H
2 #define __GEOM_CROSSING_H
15 Crossing() : dir(
false), ta(0), tb(1), a(0), b(1) {}
16 Crossing(
double t_a,
double t_b,
bool direction) : dir(direction), ta(t_a), tb(t_b), a(0), b(1) {}
17 Crossing(
double t_a,
double t_b,
unsigned ai,
unsigned bi,
bool direction) : dir(direction), ta(t_a), tb(t_b), a(ai), b(bi) {}
18 bool operator==(
const Crossing & other)
const {
return a == other.a && b == other.b && dir == other.dir && ta == other.ta && tb == other.tb; }
19 bool operator!=(
const Crossing & other)
const {
return !(*
this == other); }
21 unsigned getOther(
unsigned cur)
const {
return a == cur ? b : a; }
22 double getTime(
unsigned cur)
const {
return a == cur ? ta : tb; }
23 double getOtherTime(
unsigned cur)
const {
return a == cur ? tb : ta; }
24 bool onIx(
unsigned ix)
const {
return a == ix || b == ix; }
32 Edge(
unsigned p,
double t,
bool r) : path(p), time(t), reverse(r) {}
33 bool operator==(
Edge const &other)
const {
return other.path == path && other.time == time && other.reverse == reverse; }
37 std::vector<Edge> edges;
39 explicit CrossingNode(std::vector<Edge> es) : edges(es) {}
40 void add_edge(
Edge const &e) {
41 if(std::find(edges.begin(), edges.end(), e) == edges.end())
44 double time_on(
unsigned p) {
45 for(
unsigned i = 0; i < edges.size(); i++)
46 if(edges[i].path == p)
return edges[i].time;
47 std::cout <<
"CrossingNode time_on failed\n";
52 typedef std::vector<Crossing> Crossings;
54 typedef std::vector<CrossingNode> CrossingGraph;
58 return a.time < b.time;
63 CrossingGraph create_crossing_graph(std::vector<Path>
const &p, Crossings
const &crs);
76 return (ix == a.a ? a.ta : a.tb) <
77 (ix == b.a ? b.ta : b.tb);
82 typedef std::vector<Crossings> CrossingSet;
85 std::vector<Rect> bounds(C
const &a) {
87 for(
unsigned i = 0; i < a.size(); i++) rs.push_back(a[i].boundsFast());
91 inline void sort_crossings(Crossings &cr,
unsigned ix) { std::sort(cr.begin(), cr.end(), CrossingOrder(ix)); }
96 virtual Crossings crossings(T
const &a, T
const &b) {
return crossings(std::vector<T>(1,a), std::vector<T>(1,b))[0]; }
97 virtual CrossingSet crossings(std::vector<T>
const &a, std::vector<T>
const &b) {
98 CrossingSet results(a.size() + b.size(), Crossings());
100 std::vector<std::vector<unsigned> > cull = sweep_bounds(bounds(a), bounds(b));
101 for(
unsigned i = 0; i < cull.size(); i++) {
102 for(
unsigned jx = 0; jx < cull[i].size(); jx++) {
103 unsigned j = cull[i][jx];
104 unsigned jc = j + a.size();
105 Crossings cr = crossings(a[i], b[j]);
106 for(
unsigned k = 0; k < cr.size(); k++) { cr[k].a = i; cr[k].b = jc; }
109 sort_crossings(cr, i);
110 Crossings n(results[i].size() + cr.size());
111 std::merge(results[i].begin(), results[i].end(), cr.begin(), cr.end(), n.begin(),
CrossingOrder(i));
115 sort_crossings(cr, jc);
116 n.resize(results[jc].size() + cr.size());
117 std::merge(results[jc].begin(), results[jc].end(), cr.begin(), cr.end(), n.begin(),
CrossingOrder(jc));
124 void merge_crossings(Crossings &a, Crossings &b,
unsigned i);
125 void offset_crossings(Crossings &cr,
double a,
double b);
127 Crossings reverse_ta(Crossings
const &cr, std::vector<double> max);
128 Crossings reverse_tb(Crossings
const &cr,
unsigned split, std::vector<double> max);
129 CrossingSet reverse_ta(CrossingSet
const &cr,
unsigned split, std::vector<double> max);
130 CrossingSet reverse_tb(CrossingSet
const &cr,
unsigned split, std::vector<double> max);
132 void clean(Crossings &cr_a, Crossings &cr_b);
Definition: crossing.h:94
Definition: crossing.h:36
Definition: crossing.h:56
Definition: crossing.h:28
Definition: crossing.h:72
Definition: crossing.h:11