#include <cmath>
#include <iostream>
+
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
-#define max(a,b) MAX(a,b)
-#define min(a,b) MIN(a,b)
#define Epsilon 1E-4
#define Infinity HUGE_VAL
-// dimension
-#define DIM 3
-
//! Standard operators and useful methods for 3d vectors
//! Fill in the missing parts in Vec3f.cxx
-class Vec3f {
+class Vec3f
+{
public:
- Vec3f();
- Vec3f(float x, float y, float z);
-
- ~Vec3f();
-
- Vec3f(const Vec3f& o);
- Vec3f& operator=(const Vec3f& o);
-
- //! dot product
- float operator|(const Vec3f& o);
- float dot(const Vec3f& o);
-
- //! cross product
- Vec3f operator%(const Vec3f& o);
- Vec3f cross(const Vec3f& o);
-
- //! normalize vector
- void normalize();
- //! length of a vector
- float norm() const;
-
- //! (self-)multiply with scalar
- Vec3f operator*(const float t) const;
- Vec3f& operator*=(const float t);
-
- //! (self-)division by scalar
- Vec3f operator/(const float t) const;
- Vec3f& operator/=(const float t);
-
- //! vector (self-)addition
- Vec3f operator+(const Vec3f& o) const;
- Vec3f& operator+=(const Vec3f& o);
-
- //! vector (self-)subtraction
- Vec3f operator-(const Vec3f& o) const;
- Vec3f& operator-=(const Vec3f& o);
-
- //! component-wise multiplication of two vectors
- Vec3f operator*(const Vec3f& o) const;
- Vec3f& operator*=(const Vec3f& o);
-
- //! component-wise division of two vectors
- Vec3f operator/(const Vec3f& o) const;
- Vec3f& operator/=(const Vec3f& o);
-
- //! element access functions ( read-only and read-write )
- float operator[](unsigned int i) const;
- float& operator[](unsigned int i);
-
+ Vec3f();
+ Vec3f(float x, float y, float z);
+
+ ~Vec3f();
+
+ Vec3f(const Vec3f& o);
+ Vec3f& operator=(const Vec3f& o);
+
+ //! dot product
+ float operator|(const Vec3f& o) const;
+ float dot(const Vec3f& o) const;
+
+ //! cross product
+ Vec3f operator%(const Vec3f& o) const;
+ Vec3f cross(const Vec3f& o) const;
+
+ //! normalize vector
+ void normalize();
+ //! length of a vector
+ float norm() const;
+
+ //! (self-)multiply with scalar
+ Vec3f operator*(const float t) const;
+ Vec3f& operator*=(const float t);
+
+ //! (self-)division by scalar
+ Vec3f operator/(const float t) const;
+ Vec3f& operator/=(const float t);
+
+ //! vector (self-)addition
+ Vec3f operator+(const Vec3f& o) const;
+ Vec3f& operator+=(const Vec3f& o);
+
+ //! vector (self-)subtraction
+ Vec3f operator-(const Vec3f& o) const;
+ Vec3f& operator-=(const Vec3f& o);
+
+ //! component-wise multiplication of two vectors
+ Vec3f operator*(const Vec3f& o) const;
+ Vec3f& operator*=(const Vec3f& o);
+
+ //! component-wise division of two vectors
+ Vec3f operator/(const Vec3f& o) const;
+ Vec3f& operator/=(const Vec3f& o);
+
+ //! element access functions ( read-only and read-write )
+ float operator[](unsigned int i) const;
+ float& operator[](unsigned int i);
+
private:
- float m_values[3];
+ float m_values[3];
};
-inline std::ostream& operator<<(std::ostream& o, const Vec3f& v) {
- o << "(" << v[0] << "," << v[1] << "," << v[2] << ")";
- return o;
+inline std::ostream& operator<<(std::ostream& o, const Vec3f& v)
+{
+ o << "(" << v[0] << "," << v[1] << "," << v[2] << ")";
+ return o;
}
#endif
+