summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/checker.c11
-rw-r--r--libdimension/dimension/pattern.h12
-rw-r--r--libdimension/dimension/refcount.h9
-rw-r--r--libdimension/pattern.c9
-rw-r--r--libdimension/pigment_map.c1
5 files changed, 16 insertions, 26 deletions
diff --git a/libdimension/checker.c b/libdimension/checker.c
index 84b13bd..aa663ed 100644
--- a/libdimension/checker.c
+++ b/libdimension/checker.c
@@ -51,10 +51,15 @@ dmnsn_checker_pattern_fn(const dmnsn_pattern *checker, dmnsn_vector v)
return (n%2 == 0) ? 0.0 : 1.0;
}
+/** The singleton instance. */
+static dmnsn_pattern dmnsn_checker_instance = {
+ .pattern_fn = dmnsn_checker_pattern_fn,
+ .refcount = 1,
+};
+
dmnsn_pattern *
dmnsn_new_checker_pattern(void)
{
- dmnsn_pattern *checker = dmnsn_new_pattern();
- checker->pattern_fn = dmnsn_checker_pattern_fn;
- return checker;
+ DMNSN_INCREF(&dmnsn_checker_instance);
+ return &dmnsn_checker_instance;
}
diff --git a/libdimension/dimension/pattern.h b/libdimension/dimension/pattern.h
index de37286..596ed35 100644
--- a/libdimension/dimension/pattern.h
+++ b/libdimension/dimension/pattern.h
@@ -40,9 +40,6 @@ struct dmnsn_pattern {
dmnsn_pattern_fn *pattern_fn; /**< The pattern callback. */
dmnsn_free_fn *free_fn; /**< The destructor callback. */
- dmnsn_matrix trans; /**< The transformation matrix of the pattern. */
- dmnsn_matrix trans_inv; /**< The inverse of the transformation matrix. */
-
void *ptr; /**< Generic pointer. */
dmnsn_refcount refcount; /**< @internal Reference count. */
@@ -61,15 +58,6 @@ dmnsn_pattern *dmnsn_new_pattern(void);
void dmnsn_delete_pattern(dmnsn_pattern *pattern);
/**
- * Initialize a pattern. This precomputes some values that are used during
- * ray-tracing; the pattern will not work until it has been initialized, but
- * should not be modified after it has been initialized. Patterns are generally
- * initialized for you.
- * @param[in,out] pattern The pattern to initialize.
- */
-void dmnsn_initialize_pattern(dmnsn_pattern *pattern);
-
-/**
* Invoke the pattern callback with the right transformation.
* @param[in] pattern The pattern to evaluate.
* @param[in] v The point to get the pattern value for.
diff --git a/libdimension/dimension/refcount.h b/libdimension/dimension/refcount.h
index 5ffde4c..a0f5b6e 100644
--- a/libdimension/dimension/refcount.h
+++ b/libdimension/dimension/refcount.h
@@ -32,7 +32,14 @@ typedef unsigned int dmnsn_refcount;
* Increment a reference count.
* @param[in,out] object The reference-counted object to acquire.
*/
-#define DMNSN_INCREF(object) ((void)((object) && ++(object)->refcount))
+#define DMNSN_INCREF(object) \
+ do { \
+ /* Suppress "address will always evaluate to true" warning */ \
+ void *testptr = (object); \
+ if (testptr) { \
+ ++(object)->refcount; \
+ } \
+ } while (0)
/**
* @internal
diff --git a/libdimension/pattern.c b/libdimension/pattern.c
index 368755a..1db2244 100644
--- a/libdimension/pattern.c
+++ b/libdimension/pattern.c
@@ -30,7 +30,6 @@ dmnsn_pattern *
dmnsn_new_pattern(void)
{
dmnsn_pattern *pattern = dmnsn_malloc(sizeof(dmnsn_pattern));
- pattern->trans = dmnsn_identity_matrix();
pattern->free_fn = NULL;
pattern->refcount = 1;
return pattern;
@@ -48,17 +47,9 @@ dmnsn_delete_pattern(dmnsn_pattern *pattern)
}
}
-/* Precompute the transformation matrix inverse */
-void
-dmnsn_initialize_pattern(dmnsn_pattern *pattern)
-{
- pattern->trans_inv = dmnsn_matrix_inverse(pattern->trans);
-}
-
/* Invoke the pattern callback with the right transformation */
double
dmnsn_pattern_value(const dmnsn_pattern *pattern, dmnsn_vector v)
{
- v = dmnsn_transform_vector(pattern->trans_inv, v);
return pattern->pattern_fn(pattern, v);
}
diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c
index 4ffb129..e87584e 100644
--- a/libdimension/pigment_map.c
+++ b/libdimension/pigment_map.c
@@ -102,7 +102,6 @@ static void
dmnsn_pigment_map_initialize_fn(dmnsn_pigment *pigment)
{
dmnsn_pigment_map_payload *payload = pigment->ptr;
- dmnsn_initialize_pattern(payload->pattern);
dmnsn_map_apply(payload->map, dmnsn_initialize_mapped_pigment);
}