diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-14 21:20:43 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-14 21:20:43 -0500 |
commit | 8fe33a340b8979a73fa84f201c15519a9b5d0266 (patch) | |
tree | 12cdbb1c1b9a48f533ab36980602785be1e1deeb /libdimension/torus.c | |
parent | 20a55aa78050d94b187d4edfaac91ea00efea505 (diff) | |
download | dimension-8fe33a340b8979a73fa84f201c15519a9b5d0266.tar.xz |
Document libdimension with Doxygen.
Diffstat (limited to 'libdimension/torus.c')
-rw-r--r-- | libdimension/torus.c | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/libdimension/torus.c b/libdimension/torus.c index 702404b..244f174 100644 --- a/libdimension/torus.c +++ b/libdimension/torus.c @@ -18,47 +18,19 @@ * <http://www.gnu.org/licenses/>. * *************************************************************************/ -#include "dimension.h" - -/* - * Torus - special case of a quartic +/** + * @file + * Torii. A special case of a quartic. */ -/* Torus object callbacks */ -static bool dmnsn_torus_intersection_fn(const dmnsn_object *torus, - dmnsn_line line, - dmnsn_intersection *intersection); -static bool dmnsn_torus_inside_fn(const dmnsn_object *torus, - dmnsn_vector point); +#include "dimension.h" -/* Payload type */ +/** Torus payload type. */ typedef struct dmnsn_torus_payload { double major, minor; } dmnsn_torus_payload; -/* Allocate a new torus */ -dmnsn_object * -dmnsn_new_torus(double major, double minor) -{ - dmnsn_object *torus = dmnsn_new_object(); - torus->intersection_fn = &dmnsn_torus_intersection_fn; - torus->inside_fn = &dmnsn_torus_inside_fn; - torus->bounding_box.min = dmnsn_new_vector(-(major + minor), - -minor, - -(major + minor)); - torus->bounding_box.max = dmnsn_new_vector(major + minor, - minor, - major + minor); - - dmnsn_torus_payload *payload = dmnsn_malloc(sizeof(dmnsn_torus_payload)); - payload->major = major; - payload->minor = minor; - torus->ptr = payload; - torus->free_fn = &dmnsn_free; - return torus; -} - -/* Bound the torus in a cylindrical shell */ +/** Bound the torus in a cylindrical shell. */ static inline bool dmnsn_torus_bound_intersection(const dmnsn_torus_payload *payload, dmnsn_line l) { @@ -103,7 +75,7 @@ dmnsn_torus_bound_intersection(const dmnsn_torus_payload *payload, dmnsn_line l) return true; } -/* Returns the closest intersection of `line' with `torus' */ +/** Torus intersection callback. */ static bool dmnsn_torus_intersection_fn(const dmnsn_object *torus, dmnsn_line l, dmnsn_intersection *intersection) @@ -159,7 +131,7 @@ dmnsn_torus_intersection_fn(const dmnsn_object *torus, dmnsn_line l, return true; } -/* Return whether a point is inside a torus */ +/** Torus inside callback. */ static bool dmnsn_torus_inside_fn(const dmnsn_object *torus, dmnsn_vector point) { @@ -167,3 +139,25 @@ dmnsn_torus_inside_fn(const dmnsn_object *torus, dmnsn_vector point) double dmajor = payload->major - sqrt(point.x*point.x + point.z*point.z); return dmajor*dmajor + point.y*point.y < payload->minor*payload->minor; } + +/* Allocate a new torus */ +dmnsn_object * +dmnsn_new_torus(double major, double minor) +{ + dmnsn_object *torus = dmnsn_new_object(); + torus->intersection_fn = &dmnsn_torus_intersection_fn; + torus->inside_fn = &dmnsn_torus_inside_fn; + torus->bounding_box.min = dmnsn_new_vector(-(major + minor), + -minor, + -(major + minor)); + torus->bounding_box.max = dmnsn_new_vector(major + minor, + minor, + major + minor); + + dmnsn_torus_payload *payload = dmnsn_malloc(sizeof(dmnsn_torus_payload)); + payload->major = major; + payload->minor = minor; + torus->ptr = payload; + torus->free_fn = &dmnsn_free; + return torus; +} |