Beispiel #1
0
GCList *gts_surface_add_polygon(GtsSurface *s, GtsEdgePool *pool, GCList *polygon, GtsVector orientation) 
{
	GtsVertex *v1, *v2, *v3; 
	g_assert(GTS_IS_SURFACE(s));
	g_assert(GTS_IS_EDGE_POOL(pool)); 

	guint loop = 0; 
	gint poly_size = g_clist_length(polygon);
	g_debug("triangulate a  polygon with %d vertices", poly_size);
	
	// no triangles -> no 
	if (poly_size < 3) 
		return polygon;
	

	if (gts_vector_norm(orientation) == 0.0)
		gts_polygon_orientation(polygon, orientation); 
		
	
	while (poly_size > 3) {
		if (loop > 2) {// that is essentially rape
			polygon = g_clist_reverse(polygon); 
			g_warning("reversed the polygon!"); 
		}
			
		GCList *p_i = g_clist_next(polygon);
		while (p_i != polygon && poly_size > 3) {
			if (add_ear(s, pool, p_i, polygon, orientation)) {
				GCList *p_i_old = p_i;
				p_i = p_i->prev != polygon ? p_i->prev : p_i->next;
				polygon = g_clist_delete_link(polygon, p_i_old);
				--poly_size;
			}else
				p_i = g_clist_next(p_i); 
	
		}
		++loop; 
	}
	v1 = GTS_VERTEX(polygon->prev->data); 
	v2 = GTS_VERTEX(polygon->data); 
	v3 = GTS_VERTEX(polygon->next->data); 
	
	add_face_from_polygon_corner(s, pool, v1, v2, v3);
	return polygon; 
}
Beispiel #2
0
gboolean 
pygts_face_is_ok(PygtsFace *f)
{
  GSList *parent;
  PygtsObject *obj;

  obj = PYGTS_OBJECT(f);

  if(!pygts_triangle_is_ok(PYGTS_TRIANGLE(f))) return FALSE;

  /* Check for a valid parent */
  g_return_val_if_fail(obj->gtsobj_parent!=NULL,FALSE);
  g_return_val_if_fail(GTS_IS_SURFACE(obj->gtsobj_parent),FALSE);
  parent = g_slist_find(GTS_FACE(obj->gtsobj)->surfaces,
			obj->gtsobj_parent);
  g_return_val_if_fail(parent!=NULL,FALSE);

  return TRUE;
}