From 7b08644490cc1f897f4c327af839f0b2448351c0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 15:59:49 -0400 Subject: Don't use dynamic memory for dmnsn_intersection's. Drops us from ~400,000 allocs to ~1000. Oops ><. --- libdimension/sphere.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libdimension/sphere.c') diff --git a/libdimension/sphere.c b/libdimension/sphere.c index 77fd1d4..09b6767 100644 --- a/libdimension/sphere.c +++ b/libdimension/sphere.c @@ -27,9 +27,9 @@ /* Sphere object callbacks */ -static dmnsn_intersection * -dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line); - +static bool dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, + dmnsn_line line, + dmnsn_intersection *intersection); static bool dmnsn_sphere_inside_fn(const dmnsn_object *sphere, dmnsn_vector point); @@ -46,11 +46,11 @@ dmnsn_new_sphere() } /* Returns the closest intersection of `line' with `sphere' */ -static dmnsn_intersection * -dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line) +static bool +dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line, + dmnsn_intersection *intersection) { double a, b, c, t; - dmnsn_intersection *intersection = NULL; /* Solve (x0 + nx*t)^2 + (y0 + ny*t)^2 + (z0 + nz*t)^2 == 1 */ @@ -65,16 +65,16 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line) } if (t >= 0.0) { - intersection = dmnsn_new_intersection(); intersection->ray = line; intersection->t = t; intersection->normal = dmnsn_line_point(line, t); intersection->texture = sphere->texture; intersection->interior = sphere->interior; + return true; } } - return intersection; + return false; } /* Return whether a point is inside a sphere (x**2 + y**2 + z**2 < 1.0) */ -- cgit v1.2.3