static void smooth_vertex (GtsVertex * v, gpointer * data) { GtsSurface * s = data[0]; if (!gts_vertex_is_boundary (v, s)) { gdouble * lambda = data[1]; GSList * vertices = gts_vertex_neighbors (v, NULL, s); GSList * i; GtsVector U0 = { 0., 0., 0.}; guint n = 0; i = vertices; while (i) { GtsPoint * p = i->data; U0[0] += p->x; U0[1] += p->y; U0[2] += p->z; n++; i = i->next; } g_slist_free (vertices); if (n > 0) { GTS_POINT (v)->x += (*lambda)*(U0[0]/n - GTS_POINT (v)->x); GTS_POINT (v)->y += (*lambda)*(U0[1]/n - GTS_POINT (v)->y); GTS_POINT (v)->z += (*lambda)*(U0[2]/n - GTS_POINT (v)->z); } } }
static PyObject* neighbors(PygtsVertex* self, PyObject *args) { PyObject *s_=NULL; GtsSurface *s=NULL; GSList *vertices,*v; PygtsVertex *vertex; PyObject *tuple; guint n,N; SELF_CHECK /* Parse the args */ if(! PyArg_ParseTuple(args, "|O", &s_) ) { return NULL; } /* Convert */ if( s_ != NULL ) { if(!pygts_surface_check(s_)) { PyErr_SetString(PyExc_TypeError,"expected a Surface"); return NULL; } s = PYGTS_SURFACE_AS_GTS_SURFACE(s_); } /* Get the neighbors */ vertices = gts_vertex_neighbors(PYGTS_VERTEX_AS_GTS_VERTEX(self), NULL,s); N = g_slist_length(vertices); /* Create the tuple */ if( (tuple=PyTuple_New(N)) == NULL) { PyErr_SetString(PyExc_MemoryError,"could not create tuple"); return NULL; } /* Put PygtsVertex objects into the tuple */ v = vertices; for(n=0;n<N;n++) { /* Skip this vertex if it is a parent */ while( v!=NULL && PYGTS_IS_PARENT_VERTEX(GTS_VERTEX(v->data)) ) { v = g_slist_next(v); } if( v==NULL ) break; if( (vertex = pygts_vertex_new(GTS_VERTEX(v->data))) == NULL ) { Py_DECREF((PyObject*)tuple); return NULL; } PyTuple_SET_ITEM(tuple, n, (PyObject*)vertex); v = g_slist_next(v); } if(_PyTuple_Resize(&tuple,n)!=0) { Py_DECREF(tuple); return NULL; } return tuple; }