From dd2c47db3512658858685c83dd772603203aaab1 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 22 Jul 2018 01:20:29 -0400 Subject: potts now fully functional --- lib/colors.h | 34 ++++++++++++++++++++++++++++++++++ lib/potts.h | 22 ++++++++++------------ lib/symmetric.h | 5 +++-- 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 lib/colors.h (limited to 'lib') diff --git a/lib/colors.h b/lib/colors.h new file mode 100644 index 0000000..04d39a8 --- /dev/null +++ b/lib/colors.h @@ -0,0 +1,34 @@ +#pragma once + +#include "types.h" + +double hue_to_R(double theta) { + if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) { + return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0); + } else if (((0 <= theta) && (theta < M_PI / 3)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) { + return 1.0; + } else { + return 0.0; + } +} + +double hue_to_G(double theta) { + if (((0 <= theta) && (theta < M_PI / 3)) || ((M_PI <= theta) && (theta < 4 * M_PI / 3))) { + return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0); + } else if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((2 * M_PI / 3 <= theta) && (theta < M_PI))) { + return 1.0; + } else { + return 0.0; + } +} + +double hue_to_B(double theta) { + if (((2 * M_PI / 3 <= theta) && (theta < M_PI)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) { + return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0); + } else if (((M_PI <= theta) && (theta < 4 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) { + return 1.0; + } else { + return 0.0; + } +} + diff --git a/lib/potts.h b/lib/potts.h index e7f0899..e411ddb 100644 --- a/lib/potts.h +++ b/lib/potts.h @@ -44,13 +44,11 @@ void free_spin(potts_t s) { // do nothing! } -template -void free_spin(typename potts_t::M_t s) { +void free_spin(int *s) { free(s); } -template -void free_spin(typename potts_t::F_t s) { +void free_spin(double *s) { free(s); } @@ -60,13 +58,13 @@ potts_t copy(potts_t s) { } template -void add(typename potts_t::M_t s1, int a, potts_t s2) { - s1[s2.x] += a; +void add(typename potts_t::M_t *s1, int a, potts_t s2) { + (*s1)[s2.x] += a; } template -void add(typename potts_t::F_t s1, double a, potts_t s2) { - s1[s2.x] += a; +void add(typename potts_t::F_t *s1, double a, potts_t s2) { + (*s1)[s2.x] += a; } template @@ -78,13 +76,13 @@ typename potts_t::M_t scalar_multiple(int factor, potts_t s) { template typename potts_t::F_t scalar_multiple(double factor, potts_t s) { - int *F = (double *)calloc(q, sizeof(double)); - M[s.x] += factor; - return M; + double *F = (double *)calloc(q, sizeof(double)); + F[s.x] += factor; + return F; } template -double norm_squared(typename potts::F_t s) { +double norm_squared(typename potts_t::F_t s) { double total = 0; for (q_t i = 0; i < q; i++) { total += pow(s[i], 2); diff --git a/lib/symmetric.h b/lib/symmetric.h index 0b292a6..a73b403 100644 --- a/lib/symmetric.h +++ b/lib/symmetric.h @@ -6,6 +6,7 @@ #include "types.h" #ifdef __cplusplus +#include "potts.h" extern "C" { #endif @@ -39,11 +40,11 @@ void init(symmetric_t *p) { template void free_spin(symmetric_t p) { - free(p->perm); + free(p.perm); } template -symmetric_t copy(symmetric_t x) { +symmetric_t copy(symmetric_t x) { symmetric_t x2; x2.perm = (q_t *)malloc(q * sizeof(q_t)); -- cgit v1.2.3-70-g09d2