Exemple #1
0
bool IsOutlineValid(const Edges& outline) {
  using std::begin;
  using std::end;
  if (outline.empty()) {
    return false;
  }
  std::vector<QPointF> points;
  auto previous = outline.back();
  for (const auto& current : outline) {
    if (AngleDistance(current, previous) == 180.0) {
      return false;
    }
    const auto point = current.Begin();
    if (!IsSameEnough(previous.End(), point)) {
      return false;
    }
    if (std::any_of(begin(points), end(points),
                    [&point](const QPointF& p) {
                      return IsSameEnough(p, point);
                    })) {
      return false;
    }
    points.push_back(point);
    previous = current;
  }
  return true;
}
Exemple #2
0
std::vector<Edges> cells(cairo_t */*cr*/, std::vector<Path> const &ps) {
    CrossingSet crs = crossings_among(ps);
    Edges es = edges(ps, crs);
    std::vector<Edges> ret = std::vector<Edges>();

    while(!es.empty()) {
        std::cout << "hello!\n";
        Edge start = es.front();
        Path p = Path();
        Edge cur = start;
        bool rev = false;
        Edges cell = Edges();
        do {
            std::cout << rev << " " << cur.from.time << ", " << cur.to.time << "\n";
            double a = 0;
            Edge was = cur;
            EndPoint curpnt = rev ? cur.from : cur.to;
            Point norm = rev ? -curpnt.norm : curpnt.norm;
            //Point to = curpnt.point + norm *20;
            
            //std::cout << norm;
            for(unsigned i = 0; i < es.size(); i++) {
                if(es[i] == was || es[i].cw != start.cw) continue;
                if((!are_near(curpnt.time, es[i].from.time)) &&
				    are_near(curpnt.point, es[i].from.point, 0.1)) {
                    double v = ang(norm, es[i].from.norm);
                    //draw_line_seg(cr, curpnt.point, to);
                    //draw_line_seg(cr, to, es[i].from.point + es[i].from.norm*30); 
                    //std::cout << v << "\n";
                    if(start.cw ? v < a : v > a ) {
                        a = v;
                        cur = es[i];
                        rev = false;
                    }
                }
                if((!are_near(curpnt.time, es[i].to.time)) &&
				    are_near(curpnt.point, es[i].to.point, 0.1)) {
                    double v = ang(norm, -es[i].to.norm);
                    if(start.cw ? v < a : v > a) {
                        a = v;
                        cur = es[i];
                        rev = true; 
                    }
                }
            }
            cell.push_back(cur);
            remove(es, cur);
			if(cur == was) break;
        } while(!(cur == start));
		if(are_near(start.to.point, rev ? cur.from.point : cur.to.point)) {
			ret.push_back(cell);
		}
    }
    return ret;
}