示例#1
0
// directed (one end is wider than the other)
vector<Poly> dir_thick_line(const Vector2d &from, const Vector2d &to,
			    double fr_width, double to_width)
{
  vector<Poly> p;
  if (fr_width < 0.001 || to_width < 0.001) return p;
  if (to.squared_distance(from) < 0.001) return p;
  if ((fr_width < 0) != (to_width < 0)) return p;
  Poly poly;
  Vector2d fdir = (to-from); fdir.normalize();
  Vector2d tdir = fdir;
  fdir *= fr_width/4.;
  tdir *= to_width/4.;
  Vector2d fr_dirp(-fdir.y(), fdir.x());
  Vector2d to_dirp(-tdir.y(), tdir.x());
  poly.addVertex(from-fdir-fr_dirp);
  poly.addVertex(from-fdir+fr_dirp);
  poly.addVertex(to+tdir+to_dirp);
  poly.addVertex(to+tdir-to_dirp);
  p.push_back(poly);
  return p;
  //return Clipping::getOffset(poly, distance/4, jmiter, 0);

  // slow:
  // poly.addVertex(from);
  // poly.addVertex(to);
  // return Clipping::getOffset(poly, distance/2, jround, distance/2.);
}
示例#2
0
vector<Poly> thick_line(const Vector2d &from, const Vector2d &to, double width)
{
  vector<Poly> p;
  if (width < 0.001) return p;
  if (to.squared_distance(from) < 0.001) return p;
  Poly poly;
  Vector2d dir = (to-from); dir.normalize(); dir *= width/4.;
  Vector2d dirp(-dir.y(),dir.x());
  poly.addVertex(from-dir-dirp);
  poly.addVertex(from-dir+dirp);
  poly.addVertex(to+dir+dirp);
  poly.addVertex(to+dir-dirp);
  p.push_back(poly);
  return Clipping::getOffset(poly, width/4, jmiter, 0);

  // slow:
  // poly.addVertex(from);
  // poly.addVertex(to);
  // return Clipping::getOffset(poly, distance/2, jround, distance/2.);
}
示例#3
0
Poly* parse_poly(char* buffer)
{
    char* cvec;
    Poly* poly = new Poly();
    cvec =  strtok(buffer, ";");
    while (cvec!=NULL)
    {
        poly->addVertex(parse_vector(cvec));
        cvec =  strtok(NULL, ";");
    }
    return poly;
}
示例#4
0
// calc convex hull and Min and Max of layer
// Monotone chain algo
Poly convexHull2D(const vector<Poly> &polygons)
{
  Poly hullPolygon;
  vector<struct sortable_point> P;
  for (uint i = 0; i<polygons.size(); i++)
    for (uint j = 0; j<polygons[i].size(); j++) {
      struct sortable_point point;
      point.v = polygons[i].vertices[j];
      P.push_back(point);
    }

  int n = P.size();
  vector<Vector2d> H(2*n);

  if (n<2) return hullPolygon;
  if (n<4) {
    for (int i = 0; i < n; i++)
      hullPolygon.addVertex(P[i].v);
    return hullPolygon;
  }
  sort(P.begin(), P.end());

  // Build lower hull
  int k=0;
  for (int i = 0; i < n; i++) {
    while (k >= 2 && cross_2(H[k-2], H[k-1], P[i].v) <= 0) k--;
    H[k++] = P[i].v;
  }

  // Build upper hull
  for (int i = n-2, t = k+1; i >= 0; i--) {
    while (k >= t && cross_2(H[k-2], H[k-1], P[i].v) <= 0) k--;
    H[k++] = P[i].v;
  }
  H.resize(k);
  hullPolygon.vertices = H;
  hullPolygon.reverse();
  return hullPolygon;
}