diff --git a/stim/math/constants.h b/stim/math/constants.h index a4bcdb9..211375b 100644 --- a/stim/math/constants.h +++ b/stim/math/constants.h @@ -4,7 +4,6 @@ #define STIM_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862 #define STIM_TAU 2 * STIM_PI -#include "stim/cuda/cudatools/callable.h" namespace stim{ const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862; const double TAU = 2 * stim::PI; diff --git a/stim/math/spharmonics.h b/stim/math/spharmonics.h index 3182faa..defb374 100644 --- a/stim/math/spharmonics.h +++ b/stim/math/spharmonics.h @@ -5,7 +5,6 @@ #include #include -#define PI 3.14159 #define WIRE_SCALE 1.001 namespace stim{ @@ -32,6 +31,12 @@ protected: public: + spharmonics() { + mcN = 0; + } + spharmonics(size_t c) : spharmonics() { + resize(c); + } void push(double c){ C.push_back(c); @@ -163,6 +168,38 @@ public: return fx; } + //overload arithmetic operations + spharmonics operator*(T rhs) const { + spharmonics result(C.size()); //create a new spherical harmonics object + for (size_t c = 0; c < C.size(); c++) //for each coefficient + result.C[c] = C[c] * rhs; //calculate the factor and store the result in the new spharmonics object + return result; + } + + spharmonics operator+(spharmonics rhs) { + size_t low = std::min(C.size(), rhs.C.size()); //store the number of coefficients in the lowest object + size_t high = std::max(C.size(), rhs.C.size()); //store the number of coefficients in the result + bool rhs_lowest = false; //true if rhs has the lowest number of coefficients + if (rhs.C.size() < C.size()) rhs_lowest = true; //if rhs has a lower number of coefficients, set the flag + + spharmonics result(high); //create a new object + size_t c; + for (c = 0; c < low; c++) //perform the first batch of additions + result.C[c] = C[c] + rhs.C[c]; //perform the addition + + for (c = low; c < high; c++) { + if (rhs_lowest) + result.C[c] = C[c]; + else + result.C[c] = rhs.C[c]; + } + return result; + } + + spharmonics operator-(spharmonics rhs) { + return (*this) + (rhs * (T)(-1)); + } + }; //end class sph_harmonics diff --git a/stim/visualization/gl_spharmonics.h b/stim/visualization/gl_spharmonics.h index 1ff0395..37b9a2e 100644 --- a/stim/visualization/gl_spharmonics.h +++ b/stim/visualization/gl_spharmonics.h @@ -163,6 +163,19 @@ protected: } public: + gl_spharmonics() { + + } + + gl_spharmonics(const spharmonics copy) : gl_spharmonics() { + C = copy.C; + } + + gl_spharmonics& operator=(const spharmonics rhs) { + gl_spharmonics result(rhs.C.size()); + result.C = spharmonics::rhs.C; + return result; + } void glRender(){ //set all OpenGL parameters required for drawing @@ -177,7 +190,6 @@ public: gen_function(); } - }; //end gl_spharmonics -- libgit2 0.21.4