summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension-python')
-rw-r--r--libdimension-python/dimension.pxd10
-rw-r--r--libdimension-python/dimension.pyx27
2 files changed, 37 insertions, 0 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd
index a7b8a53..0c62df6 100644
--- a/libdimension-python/dimension.pxd
+++ b/libdimension-python/dimension.pxd
@@ -37,6 +37,15 @@ cdef extern from "../libdimension/dimension.h":
double dmnsn_epsilon
+ ##########
+ # Malloc #
+ ##########
+
+ void *dmnsn_malloc(size_t size)
+ void *dmnsn_realloc(void *ptr, size_t size)
+ char *dmnsn_strdup(const char *s)
+ void dmnsn_free(void *ptr)
+
#########
# Pools #
#########
@@ -321,6 +330,7 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_object *dmnsn_new_triangle(dmnsn_pool *pool, dmnsn_vector vertices[3])
dmnsn_object *dmnsn_new_smooth_triangle(dmnsn_pool *pool, dmnsn_vector vertices[3], dmnsn_vector normals[3])
+ dmnsn_object *dmnsn_new_triangle_fan(dmnsn_pool *pool, dmnsn_vector *vertices, size_t nvertices)
dmnsn_object *dmnsn_new_plane(dmnsn_pool *pool, dmnsn_vector normal)
dmnsn_object *dmnsn_new_sphere(dmnsn_pool *pool)
dmnsn_object *dmnsn_new_cube(dmnsn_pool *pool)
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 0c4d665..1ad6d0b 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -1143,6 +1143,33 @@ cdef class Triangle(Object):
self._object = dmnsn_new_smooth_triangle(_get_pool(), vertices, normals)
Object.__init__(self, *args, **kwargs)
+cdef class TriangleFan(Object):
+ """A triangle."""
+ def __init__(self, vertices, *args, **kwargs):
+ """
+ Create a TriangleFan.
+
+ Keyword arguments:
+ vertices -- the vertices of the fan, starting in the center
+
+ Additionally, TriangleFan() accepts any arguments that Object() accepts.
+ """
+ cdef size_t nvertices = len(vertices)
+ if nvertices < 3:
+ raise TypeError("expected at least 3 vertices")
+
+ cdef dmnsn_vector *varray
+ try:
+ varray = <dmnsn_vector *>dmnsn_malloc(nvertices*sizeof(dmnsn_vector))
+ for i in range(nvertices):
+ varray[i] = Vector(vertices[i])._v
+
+ self._object = dmnsn_new_triangle_fan(_get_pool(), varray, nvertices)
+ finally:
+ dmnsn_free(varray)
+
+ Object.__init__(self, *args, **kwargs)
+
cdef class Plane(Object):
"""A plane."""
def __init__(self, normal, double distance, *args, **kwargs):