diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-22 01:20:29 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-22 01:20:29 -0400 |
commit | dd2c47db3512658858685c83dd772603203aaab1 (patch) | |
tree | e029032fb62317237482844af9f1bbd3b5545c45 /lib | |
parent | e74305e932e45c0d2e69fd1c0a7313662fc47375 (diff) | |
download | c++-dd2c47db3512658858685c83dd772603203aaab1.tar.gz c++-dd2c47db3512658858685c83dd772603203aaab1.tar.bz2 c++-dd2c47db3512658858685c83dd772603203aaab1.zip |
potts now fully functional
Diffstat (limited to 'lib')
-rw-r--r-- | lib/colors.h | 34 | ||||
-rw-r--r-- | lib/potts.h | 22 | ||||
-rw-r--r-- | lib/symmetric.h | 5 |
3 files changed, 47 insertions, 14 deletions
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 <q> s) { // do nothing! } -template <q_t q> -void free_spin(typename potts_t<q>::M_t s) { +void free_spin(int *s) { free(s); } -template <q_t q> -void free_spin(typename potts_t<q>::F_t s) { +void free_spin(double *s) { free(s); } @@ -60,13 +58,13 @@ potts_t <q> copy(potts_t <q> s) { } template <q_t q> -void add(typename potts_t<q>::M_t s1, int a, potts_t <q> s2) { - s1[s2.x] += a; +void add(typename potts_t<q>::M_t *s1, int a, potts_t <q> s2) { + (*s1)[s2.x] += a; } template <q_t q> -void add(typename potts_t<q>::F_t s1, double a, potts_t <q> s2) { - s1[s2.x] += a; +void add(typename potts_t<q>::F_t *s1, double a, potts_t <q> s2) { + (*s1)[s2.x] += a; } template <q_t q> @@ -78,13 +76,13 @@ typename potts_t<q>::M_t scalar_multiple(int factor, potts_t <q> s) { template <q_t q> typename potts_t<q>::F_t scalar_multiple(double factor, potts_t <q> 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 <q_t q> -double norm_squared(typename potts<q>::F_t s) { +double norm_squared(typename potts_t<q>::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<q> *p) { template <q_t q> void free_spin(symmetric_t<q> p) { - free(p->perm); + free(p.perm); } template <q_t q> -symmetric_t<q_t> copy(symmetric_t<q_t> x) { +symmetric_t<q> copy(symmetric_t<q> x) { symmetric_t<q> x2; x2.perm = (q_t *)malloc(q * sizeof(q_t)); |