Ejemplo n.º 1
0
/* gets (cached) boundingbox or calculates and caches */
static void Polygon_getBoundingBox(Polygon *p, double *x0, double *x1, double *y0, double *y1) {
    if (p->bbValid) {
        *x0 = p->boundingBox[0];
        *x1 = p->boundingBox[1];
        *y0 = p->boundingBox[2];
        *y1 = p->boundingBox[3];
    } else {
        poly_p_boundingbox(p->p, x0, x1, y0, y1);
        p->boundingBox[0] = *x0;
        p->boundingBox[1] = *x1;
        p->boundingBox[2] = *y0;
        p->boundingBox[3] = *y1;
        p->bbValid = 1;
    }
}
Ejemplo n.º 2
0
void poly_p_warpToBox(gpc_polygon *p, double x0, double x1, 
                 double y0, double y1, double *bb) {
  int i, j;
  gpc_vertex_list *vl;
  double xscale, yscale, bx0, bx1, by0, by1;
  if (bb) {
      bx0 = bb[0];
      bx1 = bb[1];
      by0 = bb[2];
      by1 = bb[3];
  } else
      poly_p_boundingbox(p, &bx0, &bx1, &by0, &by1);
  xscale = ((bx1 > bx0) ? (x1-x0)/(bx1-bx0) : 1.0); 
  yscale = ((by1 > by0) ? (y1-y0)/(by1-by0) : 1.0);
  for (i=0; i < p->num_contours; i++) {
    vl = p->contour+i;
    for (j=0; j < vl->num_vertices; j++) {
      vl->vertex[j].x = x0 + xscale*(vl->vertex[j].x - bx0);
      vl->vertex[j].y = y0 + yscale*(vl->vertex[j].y - by0);
    }
  }
}