From d03b807e8084446bf7f205f717b2af0e0626eeab Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Wed, 27 Jan 2016 13:26:26 -0600 Subject: [PATCH] fixed all the bugs and issue in the plane, rect, and circle classes. Fully functional, but needs cleanup --- stim/math/plane.h | 39 +++++++++++++++++++++++---------------- stim/math/rect.h | 23 +++++++++++++++-------- stim/math/vector.h | 5 +++-- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/stim/math/plane.h b/stim/math/plane.h index 1b41f45..baa4683 100644 --- a/stim/math/plane.h +++ b/stim/math/plane.h @@ -6,11 +6,22 @@ #include #include + namespace stim { -template class plane +template class plane; +} + +template +CUDA_CALLABLE stim::plane operator-(stim::plane v); + +namespace stim +{ + +template +class plane { - private: + protected: stim::vec P; stim::vec N; stim::vec U; @@ -31,17 +42,11 @@ template class plane init(); } - CUDA_CALLABLE plane(vec p) - { - init(); - P = p; - } - CUDA_CALLABLE plane(vec n, vec p = vec(0, 0, 0)) { init(); P = p; - rotate(N, n.norm()); + rotate(n.norm()); } CUDA_CALLABLE plane(T z_pos) @@ -60,13 +65,15 @@ template class plane { if(n.len() != 0) { - rotate(N, n.norm()); + rotate(n.norm()); + } else { + throw 42; } } - catch - { + catch(int i) + { std::cerr << "No plane can be creates as all points a,b,c lie on a straight line" << std::endl; - } + } } template< typename U > @@ -77,7 +84,7 @@ template class plane } - CUDA_CALLABLE vec norm() + CUDA_CALLABLE vec n() { return N; } @@ -160,7 +167,7 @@ template class plane CUDA_CALLABLE stim::plane operator-() { - rts::plane p = *this; + stim::plane p = *this; //negate the normal vector p.N = -p.N; @@ -172,7 +179,7 @@ template class plane std::stringstream ss; ss<<"P: "< #include @@ -9,12 +10,13 @@ #include #include #include +#include namespace stim{ //template for a rectangle class in ND space template -class rect : public plane +class rect : plane { /* ^ O @@ -40,6 +42,12 @@ private: public: + using stim::plane::n; + using stim::plane::P; + using stim::plane::N; + using stim::plane::U; + using stim::plane::rotate; + ///base constructor. CUDA_CALLABLE rect() : plane() @@ -84,7 +92,7 @@ public: ///@param directionX: u,v,w direction of the X vector. ///@param directionY: u,v,w direction of the Y vector. CUDA_CALLABLE rect(vec center, vec directionX, vec directionY ) - : plane(p) + : plane((directionX.cross(directionY)).norm(),center) { X = directionX; Y = directionY; @@ -96,7 +104,7 @@ public: ///@param directionX: u,v,w direction of the X vector. ///@param directionY: u,v,w direction of the Y vector. CUDA_CALLABLE rect(T size, vec center, vec directionX, vec directionY ) - : plane(p) + : plane((directionX.cross(directionY)).norm(),center) { X = directionX; Y = directionY; @@ -108,8 +116,8 @@ public: ///@param center: x,y,z location of the center. ///@param directionX: u,v,w direction of the X vector. ///@param directionY: u,v,w direction of the Y vector. - CUDA_CALLABLE rect(vec size, vec center, vec directionX, vec directionY ) - : plane(p) + CUDA_CALLABLE rect(vec size, vec center, vec directionX, vec directionY) + : plane((directionX.cross(directionY)).norm(), center) { X = directionX; Y = directionY; @@ -136,7 +144,6 @@ public: ///general init method that sets a general rectangle. CUDA_CALLABLE void init() { - P = vec(0, 0, 0); X = vec(1, 0, 0); Y = vec(0, 1, 0); } @@ -156,7 +163,7 @@ public: { stim::vec result; //given the two parameters a, b = [0 1], returns the position in world space - vec A = P - X * (T)0.5 - Y * (T)0.5; + vec A = this->P - X * (T)0.5 - Y * (T)0.5; result = A + X * a + Y * b; return result; @@ -217,7 +224,7 @@ public: CUDA_CALLABLE T center(vec p) { - C = p; + this->P = p; } ///Returns the maximum distance of the rectangle from a point p to the sides of the rectangle. diff --git a/stim/math/vector.h b/stim/math/vector.h index 5034cc1..34d3329 100644 --- a/stim/math/vector.h +++ b/stim/math/vector.h @@ -71,8 +71,9 @@ struct vec : public std::vector vec( const vec& other){ unsigned int N = other.size(); resize(N); //resize the current vector to match the copy - for(unsigned int i=0; i