diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-06-04 16:16:03 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-06-04 16:16:03 -0400 |
commit | 16ac456e590e11bc2028a697c586a6c7d00fc41a (patch) | |
tree | b961eca096657b5eec2a949e04b1f3fac34dab82 /libdimension | |
parent | 270a53ef8d4d009dd79605058b780dc6d1f2ed1a (diff) | |
download | dimension-16ac456e590e11bc2028a697c586a6c7d00fc41a.tar.xz |
csg: Avoid copying the child array for unions.
Diffstat (limited to 'libdimension')
-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 |
4 files changed, 8 insertions, 16 deletions
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); } |