diff options
-rw-r--r-- | libdimension-python/dimension.pxd | 1 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 13 | ||||
-rw-r--r-- | libdimension/cone.c | 3 | ||||
-rw-r--r-- | libdimension/csg.c | 7 | ||||
-rw-r--r-- | libdimension/dimension/csg.h | 2 | ||||
-rw-r--r-- | libdimension/tests/render.c | 12 |
6 files changed, 14 insertions, 24 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 6579c89..a7b8a53 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -54,6 +54,7 @@ cdef extern from "../libdimension/dimension.h": ctypedef struct dmnsn_array dmnsn_array *dmnsn_new_array(size_t objsize) + dmnsn_array *dmnsn_palloc_array(dmnsn_pool *pool, size_t objsize) void dmnsn_delete_array(dmnsn_array *array) size_t dmnsn_array_size(dmnsn_array *array) diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index d3f880c..0c4d665 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -1283,17 +1283,14 @@ cdef class Union(Object): if len(objects) < 1: raise TypeError("expected a list of one or more Objects") - cdef dmnsn_array *array = dmnsn_new_array(sizeof(dmnsn_object *)) + cdef dmnsn_array *array = dmnsn_palloc_array(_get_pool(), sizeof(dmnsn_object *)) cdef dmnsn_object *o - try: - for obj in objects: - o = (<Object?>obj)._object - dmnsn_array_push(array, &o) + for obj in objects: + o = (<Object?>obj)._object + dmnsn_array_push(array, &o) - self._object = dmnsn_new_csg_union(_get_pool(), array) - finally: - dmnsn_delete_array(array) + self._object = dmnsn_new_csg_union(_get_pool(), array) Object.__init__(self, *args, **kwargs) diff --git a/libdimension/cone.c b/libdimension/cone.c index ef3ad33..d17b2ae 100644 --- a/libdimension/cone.c +++ b/libdimension/cone.c @@ -171,12 +171,11 @@ dmnsn_new_cone(dmnsn_pool *pool, double r1, double r2, bool open) /* Flip the normal around for the top cap */ cap2->intrinsic_trans.n[1][1] = -1.0; - dmnsn_array *withcaps = DMNSN_NEW_ARRAY(dmnsn_object *); + dmnsn_array *withcaps = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); dmnsn_array_push(withcaps, &cone); dmnsn_array_push(withcaps, &cap1); dmnsn_array_push(withcaps, &cap2); dmnsn_object *cone_cap_union = dmnsn_new_csg_union(pool, withcaps); - dmnsn_delete_array(withcaps); return cone_cap_union; } diff --git a/libdimension/csg.c b/libdimension/csg.c index 5a7534b..375ac2c 100644 --- a/libdimension/csg.c +++ b/libdimension/csg.c @@ -75,7 +75,7 @@ dmnsn_csg_union_cleanup(void *ptr) /* Bulk-load a union */ dmnsn_object * -dmnsn_new_csg_union(dmnsn_pool *pool, const dmnsn_array *objects) +dmnsn_new_csg_union(dmnsn_pool *pool, dmnsn_array *objects) { dmnsn_csg_union *csg = DMNSN_PALLOC_TIDY(pool, dmnsn_csg_union, dmnsn_csg_union_cleanup); csg->bvh = NULL; @@ -83,10 +83,7 @@ dmnsn_new_csg_union(dmnsn_pool *pool, const dmnsn_array *objects) dmnsn_object *object = &csg->object; dmnsn_init_object(pool, object); - object->children = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); - DMNSN_ARRAY_FOREACH (dmnsn_object **, child, objects) { - dmnsn_array_push(object->children, child); - } + object->children = objects; object->split_children = true; object->intersection_fn = dmnsn_csg_union_intersection_fn; object->inside_fn = dmnsn_csg_union_inside_fn; diff --git a/libdimension/dimension/csg.h b/libdimension/dimension/csg.h index 9e29019..b2ce83f 100644 --- a/libdimension/dimension/csg.h +++ b/libdimension/dimension/csg.h @@ -29,7 +29,7 @@ * @param[in] objects The objects from which to compose the union. * @return A union of the objects in \p objects. */ -dmnsn_object *dmnsn_new_csg_union(dmnsn_pool *pool, const dmnsn_array *objects); +dmnsn_object *dmnsn_new_csg_union(dmnsn_pool *pool, dmnsn_array *objects); /** * CSG intersection. diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index bd0c8ca..9b830f6 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -153,7 +153,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene) static void dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) { - dmnsn_array *arrow_array = DMNSN_NEW_ARRAY(dmnsn_object *); + dmnsn_array *arrow_array = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); dmnsn_object *cylinder = dmnsn_new_cone(pool, 0.1, 0.1, false); cylinder->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0, 1.25, 1.0)); @@ -167,7 +167,6 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_array_push(arrow_array, &cone); dmnsn_object *arrow = dmnsn_new_csg_union(pool, arrow_array); - dmnsn_delete_array(arrow_array); dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(pool, dmnsn_y); dmnsn_map *gradient_pigment_map = dmnsn_new_pigment_map(pool); dmnsn_pigment_map_add_color(gradient_pigment_map, 0.0, dmnsn_red); @@ -188,7 +187,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_scale_matrix(dmnsn_new_vector(1.0, 2.75, 1.0)) ); - dmnsn_array *torus_array = DMNSN_NEW_ARRAY(dmnsn_object *); + dmnsn_array *torus_array = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); dmnsn_object *torus1 = dmnsn_new_torus(pool, 0.15, 0.05); torus1->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.0, 0.0)); @@ -202,16 +201,14 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) dmnsn_array_push(torus_array, &torus3); dmnsn_object *torii = dmnsn_new_csg_union(pool, torus_array); - dmnsn_delete_array(torus_array); torii->texture = dmnsn_new_texture(pool); torii->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_blue)); torii->texture->finish.ambient = dmnsn_new_ambient(pool, dmnsn_white); - dmnsn_array *spike_array = DMNSN_NEW_ARRAY(dmnsn_object *); + dmnsn_array *spike_array = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); dmnsn_array_push(spike_array, &arrow); dmnsn_array_push(spike_array, &torii); dmnsn_object *spike = dmnsn_new_csg_union(pool, spike_array); - dmnsn_delete_array(spike_array); spike->trans = dmnsn_rotation_matrix( dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) ); @@ -221,7 +218,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene) static void dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene) { - dmnsn_array *strip_array = DMNSN_NEW_ARRAY(dmnsn_object *); + dmnsn_array *strip_array = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *); dmnsn_vector vertices[] = { dmnsn_zero, dmnsn_new_vector(0.0, sqrt(3.0)/2.0, 0.5), @@ -246,7 +243,6 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene) } dmnsn_object *strip = dmnsn_new_csg_union(pool, strip_array); - dmnsn_delete_array(strip_array); strip->trans = dmnsn_translation_matrix(dmnsn_new_vector(5.0, -2.0, -4.0)); dmnsn_array_push(scene->objects, &strip); } |