summaryrefslogtreecommitdiffstats
path: root/libdimension/gradient.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension/gradient.c')
-rw-r--r--libdimension/gradient.c30
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;
}