Пример #1
0
static GLenum
verify_edge_vertex_intersections(GLUtriangulatorObj * tobj)
{
   tess_polygon *polygon = tobj->current_polygon;
   tess_vertex *vertex1, *last_vertex, *vertex2;
   GLenum test;

   last_vertex = polygon->last_vertex;
   vertex1 = last_vertex;
   for (vertex2 = vertex1->next->next;
	vertex2->next != last_vertex; vertex2 = vertex2->next) {
      test = edge_edge_intersect(vertex1, vertex1->next, vertex2,
				 vertex2->next);
      if (test != GLU_NO_ERROR) {
	 tess_call_user_error(tobj, test);
	 return GLU_ERROR;
      }
   }
   for (vertex1 = polygon->vertices;
	vertex1->next->next != last_vertex; vertex1 = vertex1->next) {
      for (vertex2 = vertex1->next->next;
	   vertex2 != last_vertex; vertex2 = vertex2->next) {
	 test = edge_edge_intersect(vertex1, vertex1->next, vertex2,
				    vertex2->next);
	 if (test != GLU_NO_ERROR) {
	    tess_call_user_error(tobj, test);
	    return GLU_ERROR;
	 }
      }
   }
   return GLU_NO_ERROR;
}
Пример #2
0
// TODO: pass vectors
bool Circle::edge_polygon_intersect(Vector2 e1, Vector2 e2)
{
    for (size_t i = 0; i < num_points; i++)
    {
        Vector2 p = pts[i];
        Vector2 q = pts[(i + 1) % num_points];
        if (edge_edge_intersect(e1.x, e1.y, e2.x, e2.y, p.x, p.y, q.x, p.y))
        {
            return true;
        }
    }

    return false;
}
Пример #3
0
static GLenum
contours_overlap(tess_contour * contour, tess_polygon * polygon)
{
   tess_vertex *vertex1, *vertex2;
   GLuint vertex1_cnt, vertex2_cnt, i, j;
   GLenum test;

   vertex1 = contour->vertices;
   vertex2 = polygon->vertices;
   vertex1_cnt = contour->vertex_cnt;
   vertex2_cnt = polygon->vertex_cnt;
   for (i = 0; i < vertex1_cnt; vertex1 = vertex1->next, i++) {
      for (j = 0; j < vertex2_cnt; vertex2 = vertex2->next, j++)
	 if ((test = edge_edge_intersect(vertex1, vertex1->next, vertex2,
					 vertex2->next)) != GLU_NO_ERROR)
	    return test;
   }
   return GLU_NO_ERROR;
}
Пример #4
0
static GLenum
cut_out_hole(GLUtriangulatorObj * tobj,
	     tess_contour * contour, tess_contour * hole)
{
   tess_contour *tmp_hole;
   tess_vertex *v1, *v2, *tmp_vertex;
   GLuint vertex1_cnt, vertex2_cnt, tmp_vertex_cnt;
   GLuint i, j, k;
   GLenum test = 0;

   /* find an edge connecting contour and hole not intersecting any other */
   /* edge belonging to either the contour or any of the other holes */
   for (v1 = contour->vertices, vertex1_cnt = contour->vertex_cnt, i = 0;
	i < vertex1_cnt; i++, v1 = v1->next) {
      for (v2 = hole->vertices, vertex2_cnt = hole->vertex_cnt, j = 0;
	   j < vertex2_cnt; j++, v2 = v2->next) {
	 /* does edge (v1,v2) intersect any edge of contour */
	 for (tmp_vertex = contour->vertices, tmp_vertex_cnt =
	      contour->vertex_cnt, k = 0; k < tmp_vertex_cnt;
	      tmp_vertex = tmp_vertex->next, k++) {
	    /* skip edge tests for edges directly connected */
	    if (v1 == tmp_vertex || v1 == tmp_vertex->next)
	       continue;
	    test = edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next);
	    if (test != GLU_NO_ERROR)
	       break;
	 }
	 if (test == GLU_NO_ERROR) {
	    /* does edge (v1,v2) intersect any edge of hole */
	    for (tmp_vertex = hole->vertices,
		 tmp_vertex_cnt = hole->vertex_cnt, k = 0;
		 k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) {
	       /* skip edge tests for edges directly connected */
	       if (v2 == tmp_vertex || v2 == tmp_vertex->next)
		  continue;
	       test =
		  edge_edge_intersect(v1, v2, tmp_vertex, tmp_vertex->next);
	       if (test != GLU_NO_ERROR)
		  break;
	    }
	    if (test == GLU_NO_ERROR) {
	       /* does edge (v1,v2) intersect any other hole? */
	       for (tmp_hole = hole->next;
		    tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR;
		    tmp_hole = tmp_hole->next) {
		  /* does edge (v1,v2) intersect any edge of hole */
		  for (tmp_vertex = tmp_hole->vertices,
		       tmp_vertex_cnt = tmp_hole->vertex_cnt, k = 0;
		       k < tmp_vertex_cnt; tmp_vertex = tmp_vertex->next, k++) {
		     test = edge_edge_intersect(v1, v2, tmp_vertex,
						tmp_vertex->next);
		     if (test != GLU_NO_ERROR)
			break;
		  }
		  if (test != GLU_NO_ERROR)
		     break;
	       }
	    }
	 }
	 if (test == GLU_NO_ERROR) {
	    /* edge (v1,v2) is good for eliminating the hole */
	    if (merge_hole_with_contour(tobj, contour, hole, v1, v2)
		== GLU_NO_ERROR)
	       return GLU_NO_ERROR;
	    else
	       return GLU_ERROR;
	 }
      }
   }
   /* other holes are blocking all possible connections of hole */
   /* with contour, we shift this hole as the last hole and retry */
   for (tmp_hole = hole;
	tmp_hole != NULL && tmp_hole->type == GLU_INTERIOR;
	tmp_hole = tmp_hole->next);
   contour->next = hole->next;
   hole->next->previous = contour;
   if (tmp_hole == NULL) {
      /* last EXTERIOR contour, shift hole as last contour */
      hole->next = NULL;
      hole->previous = tobj->last_contour;
      tobj->last_contour->next = hole;
      tobj->last_contour = hole;
   }
   else {
      tmp_hole->previous->next = hole;
      hole->previous = tmp_hole->previous;
      tmp_hole->previous = hole;
      hole->next = tmp_hole;
   }
   hole = contour->next;
   /* try once again - recurse */
   return cut_out_hole(tobj, contour, hole);
}