summaryrefslogtreecommitdiffstats
path: root/libdimension/sphere.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-06-26 15:31:34 +0000
committerTavian Barnes <tavianator@gmail.com>2009-06-26 15:31:34 +0000
commit3ee98f3bac24fd1c70a9de3e0fbe774e762c25b3 (patch)
treeddc8d088662a88101670150c491012427c85b5bf /libdimension/sphere.c
parentd56d643d412e06ff1e5239f8ebbd96f716b416bd (diff)
downloaddimension-3ee98f3bac24fd1c70a9de3e0fbe774e762c25b3.tar.xz
Add lots of comments, and some code fixes discovered in the process.
Diffstat (limited to 'libdimension/sphere.c')
-rw-r--r--libdimension/sphere.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libdimension/sphere.c b/libdimension/sphere.c
index 5a4d1a9..f6950dc 100644
--- a/libdimension/sphere.c
+++ b/libdimension/sphere.c
@@ -22,11 +22,13 @@
#include <stdlib.h> /* For malloc */
#include <math.h> /* For sqrt */
+/* Sphere object callbacks */
static dmnsn_array *dmnsn_sphere_intersections_fn(const dmnsn_object *sphere,
dmnsn_line line);
static int dmnsn_sphere_inside_fn(const dmnsn_object *sphere,
dmnsn_vector point);
+/* Allocate a new sphere */
dmnsn_object *
dmnsn_new_sphere()
{
@@ -38,12 +40,14 @@ dmnsn_new_sphere()
return sphere;
}
+/* Free a sphere */
void
dmnsn_delete_sphere(dmnsn_object *sphere)
{
dmnsn_delete_object(sphere);
}
+/* Return a list of insersections of `line' with a sphere */
static dmnsn_array *
dmnsn_sphere_intersections_fn(const dmnsn_object *sphere, dmnsn_line line)
{
@@ -66,8 +70,9 @@ dmnsn_sphere_intersections_fn(const dmnsn_object *sphere, dmnsn_line line)
return array;
}
+/* Return whether a point is inside a sphere (x**2 + y**2 + z**2 < 1.0) */
static int
dmnsn_sphere_inside_fn(const dmnsn_object *sphere, dmnsn_vector point)
{
- return sqrt(point.x*point.x + point.y*point.y + point.z*point.z) < 1.0;
+ return point.x*point.x + point.y*point.y + point.z*point.z < 1.0;
}