vector class
[MicroTrace.git] / Vec3f.cxx
index c063913..8dfa3d7 100644 (file)
--- a/Vec3f.cxx
+++ b/Vec3f.cxx
 
 #include "Vec3f.hxx"
 
-Vec3f::Vec3f()
-{
+Vec3f::Vec3f() {
+}
 
+Vec3f::Vec3f(float x, float y, float z) {
+       m_values[0] = x;
+       m_values[0] = y;
+       m_values[0] = z;
 }
 
-Vec3f::Vec3f(float x, float y, float z)
-{
+Vec3f::~Vec3f() {
+}
 
+Vec3f::Vec3f(const Vec3f& o) {
+       for (size_t i = 0; i < DIM; i++) {
+               m_values[i] = o.m_values[i];
+       }
 }
 
-Vec3f::~Vec3f()
-{
+Vec3f& Vec3f::operator=(const Vec3f& o) {
+       for (size_t i = 0; i < DIM; i++) {
+               m_values[i] = o.m_values[i];
+       }
+       return *this;
 }
 
-Vec3f::Vec3f(const Vec3f& o)
-{
+float Vec3f::operator|(const Vec3f& o) {
 
+       return dot(o);
 }
 
-Vec3f& 
-Vec3f::operator=(const Vec3f& o)
-{
-  
-  return *this;
+float Vec3f::dot(const Vec3f& o) {
+       float prod = 0;
+       for (size_t i = 0; i < DIM; i++) {
+               prod += m_values[i] * o.m_values[i];
+       }
+       return prod;
 }
 
-float 
-Vec3f::operator|(const Vec3f& o)
-{
-  
-  return 0.0f;
+Vec3f Vec3f::operator%(const Vec3f& o) {
+       return cross(o);
 }
 
-float 
-Vec3f::dot(const Vec3f& o)
-{
-  
-  return 0.0f;
+Vec3f Vec3f::cross(const Vec3f& o) {
+       return Vec3f(m_values[1] * o.m_values[2] - m_values[2] * o.m_values[1],
+               m_values[2] * o.m_values[0] - m_values[0] * o.m_values[2], m_values[0]
+                       * o.m_values[1] - m_values[1] * o.m_values[0]);
 }
-  
-Vec3f 
-Vec3f::operator%(const Vec3f& o)
-{
 
-  return Vec3f();
-}
+void Vec3f::normalize() {
 
-Vec3f 
-Vec3f::cross(const Vec3f& o)
-{
-  
-  return Vec3f();
-}
-  
-void 
-Vec3f::normalize()
-{
-  
 }
 
-float 
-Vec3f::norm() const
-{
-  return 0.0f;
+float Vec3f::norm() const {
+       return sqrt(m_values[0] * m_values[0] + m_values[1] * m_values[1]
+               + m_values[2] * m_values[2]);
 }
 
-Vec3f 
-Vec3f::operator*(const float t) const
-{
-  return Vec3f();
+Vec3f Vec3f::operator*(const float t) const {
+       Vec3f v(*this);
+       return v *= t;
 }
 
-Vec3f& 
-Vec3f::operator*=(const float t)
-{
-  return *this;
+Vec3f& Vec3f::operator*=(const float t) {
+    for (unsigned int i = 0; i < 3; ++i) {
+        m_values[i] *= f;
+    }
+       return *this;
 }
 
-Vec3f 
-Vec3f::operator/(const float t) const
-{
-  return Vec3f();
+Vec3f Vec3f::operator/(const float t) const {
+       Vec3f v(*this);
+    return v /= f;
 }
 
-Vec3f& 
-Vec3f::operator/=(const float t)
-{
-  return *this;
+Vec3f& Vec3f::operator/=(const float t) {
+    for (unsigned int i = 0; i < 3; ++i) {
+        m_values[i] /= f;
+    }
+       return *this;
 }
 
 // example implementation of a standard operator
-Vec3f 
-Vec3f::operator+(const Vec3f& o) const
-{
-  Vec3f v(*this);
-  
-  return v += o;
+Vec3f Vec3f::operator+(const Vec3f& o) const {
+       Vec3f v(*this);
+       return v += o;
 }
 
 // example implementation of an in-place operator
-Vec3f& 
-Vec3f::operator+=(const Vec3f& o)
-{
-  for(unsigned int i = 0; i < 3; ++i)
-    {
-      m_values[i] += o.m_values[i];
-    }
-  
-  return *this;
+Vec3f& Vec3f::operator+=(const Vec3f& o) {
+       for (unsigned int i = 0; i < 3; ++i) {
+               m_values[i] += o.m_values[i];
+       }
+       return *this;
 }
-  
-Vec3f 
-Vec3f::operator-(const Vec3f& o) const
-{
-  return Vec3f();
+
+Vec3f Vec3f::operator-(const Vec3f& o) const {
+    Vec3f v(*this);
+    return v -= o;
 }
 
-Vec3f& 
-Vec3f::operator-=(const Vec3f& o)
-{
-  return *this;
+Vec3f& Vec3f::operator-=(const Vec3f& o) {
+    for (unsigned int i = 0; i < 3; ++i) {
+        m_values[i] -= o.m_values[i];
+    }
+       return *this;
 }
-  
-Vec3f 
-Vec3f::operator*(const Vec3f& o) const
-{
-  return Vec3f();
+
+Vec3f Vec3f::operator*(const Vec3f& o) const {
+    Vec3f v(*this);
+    return v *= o;
 }
 
-Vec3f& 
-Vec3f::operator*=(const Vec3f& o)
-{
-  return *this;
+Vec3f& Vec3f::operator*=(const Vec3f& o) {
+    for (unsigned int i = 0; i < 3; ++i) {
+        m_values[i] *= o.m_values[i];
+    }
+       return *this;
 }
 
-Vec3f 
-Vec3f::operator/(const Vec3f& o) const
-{
-  return Vec3f();
+Vec3f Vec3f::operator/(const Vec3f& o) const {
+    Vec3f v(*this);
+    return v /= o;
 }
 
-Vec3f& 
-Vec3f::operator/=(const Vec3f& o)
-{
-  return *this;
+Vec3f& Vec3f::operator/=(const Vec3f& o) {
+    for (unsigned int i = 0; i < 3; ++i) {
+        m_values[i] /= o.m_values[i];
+    }
+       return *this;
 }
 
-float 
-Vec3f::operator[](unsigned int i) const
-{
-  return 0.0f;
+float Vec3f::operator[](unsigned int i) const {
+       assert(i < DIM);
+       return m_values[i];
 }
 
-float& 
-Vec3f::operator[](unsigned int i)
-{
-  assert(i < 3);
-  return m_values[i];
+float& Vec3f::operator[](unsigned int i) {
+       assert(i < DIM);
+       return m_values[i];
 }
This page took 0.027546 seconds and 4 git commands to generate.