diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-05-27 14:01:20 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-05-27 14:01:20 -0400 |
commit | b70fa29511471e8a85f9b8c3e8947dbb3c21dedb (patch) | |
tree | 9d2e066dc2ad11d918ca12a1e073c163d4d4d79d /libdimension/gradient.c | |
parent | df33e223baa85b600863fc1b38850a5c37680632 (diff) | |
download | dimension-b70fa29511471e8a85f9b8c3e8947dbb3c21dedb.tar.xz |
pattern: Kill ->ptr field.
Diffstat (limited to 'libdimension/gradient.c')
-rw-r--r-- | libdimension/gradient.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/libdimension/gradient.c b/libdimension/gradient.c index 38b460b..bdd6e86 100644 --- a/libdimension/gradient.c +++ b/libdimension/gradient.c @@ -25,28 +25,32 @@ #include "dimension.h" +/** Gradient pattern type. */ +typedef struct dmnns_gradient { + dmnsn_pattern pattern; + dmnsn_vector orientation; +} dmnsn_gradient; + /** Gradient pattern callback. */ static double -dmnsn_gradient_pattern_fn(const dmnsn_pattern *gradient, dmnsn_vector v) +dmnsn_gradient_pattern_fn(const dmnsn_pattern *pattern, dmnsn_vector v) { - dmnsn_vector *orientation = gradient->ptr; - double n = fmod(dmnsn_vector_dot(*orientation, v), 1.0); - if (n < -dmnsn_epsilon) + const dmnsn_gradient *gradient = (const dmnsn_gradient *)pattern; + double n = fmod(dmnsn_vector_dot(gradient->orientation, v), 1.0); + if (n < -dmnsn_epsilon) { n += 1.0; + } return n; } dmnsn_pattern * dmnsn_new_gradient_pattern(dmnsn_vector orientation) { - dmnsn_pattern *gradient = dmnsn_new_pattern(); - - dmnsn_vector *payload = DMNSN_MALLOC(dmnsn_vector); - *payload = dmnsn_vector_normalized(orientation); - - gradient->pattern_fn = dmnsn_gradient_pattern_fn; - gradient->free_fn = dmnsn_free; - gradient->ptr = payload; + dmnsn_gradient *gradient = DMNSN_MALLOC(dmnsn_gradient); + gradient->orientation = dmnsn_vector_normalized(orientation); - return gradient; + dmnsn_pattern *pattern = &gradient->pattern; + dmnsn_init_pattern(pattern); + pattern->pattern_fn = dmnsn_gradient_pattern_fn; + return pattern; } |