/** * gts_segment_is_ok: * @s: a #GtsSegment. * * Returns: %TRUE if @s is not degenerate (i.e. @s->v1 != @s->v2) and not * duplicate, %FALSE otherwise. */ gboolean gts_segment_is_ok (GtsSegment * s) { g_return_val_if_fail (s != NULL, FALSE); g_return_val_if_fail (s->v1 != s->v2, FALSE); g_return_val_if_fail (!gts_segment_is_duplicate (s), FALSE); g_return_val_if_fail (GTS_OBJECT (s)->reserved == NULL, FALSE); return TRUE; }
static PyObject * new_(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *o; PygtsObject *obj; GtsSegment *tmp; GtsObject *segment=NULL; PyObject *v1_=NULL,*v2_=NULL; PygtsVertex *v1,*v2; guint alloc_gtsobj = TRUE; guint N; /* Parse the args */ if(kwds) { o = PyDict_GetItemString(kwds,"alloc_gtsobj"); if(o==Py_False) { alloc_gtsobj = FALSE; } if(o!=NULL) { PyDict_DelItemString(kwds, "alloc_gtsobj"); } } if(kwds) { Py_INCREF(Py_False); PyDict_SetItemString(kwds,"alloc_gtsobj", Py_False); } /* Allocate the gtsobj (if needed) */ if( alloc_gtsobj ) { /* Parse the args */ if( (N = PyTuple_Size(args)) < 2 ) { PyErr_SetString(PyExc_TypeError,"expected two Vertices"); return NULL; } v1_ = PyTuple_GET_ITEM(args,0); v2_ = PyTuple_GET_ITEM(args,1); /* Convert to PygtsObjects */ if(!pygts_vertex_check(v1_)) { PyErr_SetString(PyExc_TypeError,"expected two Vertices"); return NULL; } if(!pygts_vertex_check(v2_)) { PyErr_SetString(PyExc_TypeError,"expected two Vertices"); return NULL; } v1 = PYGTS_VERTEX(v1_); v2 = PYGTS_VERTEX(v2_); /* Error check */ if(PYGTS_OBJECT(v1)->gtsobj == PYGTS_OBJECT(v2)->gtsobj) { PyErr_SetString(PyExc_ValueError,"Vertices are identical"); return NULL; } /* Create the GtsSegment */ segment = GTS_OBJECT(gts_segment_new(gts_segment_class(), GTS_VERTEX(v1->gtsobj), GTS_VERTEX(v2->gtsobj))); if( segment == NULL ) { PyErr_SetString(PyExc_MemoryError, "could not create Segment"); return NULL; } /* Check for duplicate */ tmp = gts_segment_is_duplicate(GTS_SEGMENT(segment)); if( tmp != NULL ) { gts_object_destroy(segment); segment = GTS_OBJECT(tmp); } /* If corresponding PyObject found in object table, we are done */ if( (obj=(PygtsObject*)g_hash_table_lookup(obj_table,segment)) != NULL ) { Py_INCREF(obj); return (PyObject*)obj; } } /* Chain up */ obj = PYGTS_OBJECT(PygtsObjectType.tp_new(type,args,kwds)); if( alloc_gtsobj ) { obj->gtsobj = segment; pygts_object_register(PYGTS_OBJECT(obj)); } return (PyObject*)obj; }