summaryrefslogtreecommitdiffstats
path: root/libdimensionxx/dimensionxx/geometry.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libdimensionxx/dimensionxx/geometry.hpp')
-rw-r--r--libdimensionxx/dimensionxx/geometry.hpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/libdimensionxx/dimensionxx/geometry.hpp b/libdimensionxx/dimensionxx/geometry.hpp
index 2ed576b..647bf24 100644
--- a/libdimensionxx/dimensionxx/geometry.hpp
+++ b/libdimensionxx/dimensionxx/geometry.hpp
@@ -21,8 +21,116 @@
#ifndef DIMENSIONXX_GEOMETRY_HPP
#define DIMENSIONXX_GEOMETRY_HPP
+#include <dimension.h>
+
namespace dimension
{
+ typedef dmnsn_scalar scalar;
+
+ class vector
+ {
+ public:
+ vector() { }
+ vector(scalar x, scalar y, scalar z)
+ : m_vector(dmnsn_vector_construct(x, y, z)) { }
+ explicit vector(dmnsn_vector v) : m_vector(v) { }
+ // vector(const vector& v);
+ // ~vector();
+
+ scalar x() const { return m_vector.x; }
+ scalar y() const { return m_vector.y; }
+ scalar z() const { return m_vector.z; }
+
+ // vector& operator=(const vector& rhs);
+ vector& operator+=(const vector& rhs)
+ { m_vector = dmnsn_vector_add(m_vector, rhs.m_vector); return *this; }
+ vector& operator-=(const vector& rhs)
+ { m_vector = dmnsn_vector_sub(m_vector, rhs.m_vector); return *this; }
+ vector& operator*=(scalar rhs)
+ { m_vector = dmnsn_vector_mul(rhs, m_vector); return *this; }
+ vector& operator/=(scalar rhs)
+ { m_vector = dmnsn_vector_div(m_vector, rhs); return *this; }
+
+ dmnsn_vector dmnsn() const { return m_vector; }
+
+ private:
+ dmnsn_vector m_vector;
+ };
+
+ class line
+ {
+ public:
+ line() { }
+ line(const vector& x0, const vector& n)
+ { m_line.x0 = x0.dmnsn(); m_line.n = n.dmnsn(); }
+ // line(const line& l);
+ // ~line();
+
+ vector x0() const { return vector(m_line.x0); }
+ vector n() const { return vector(m_line.n); }
+
+ // line& operator=(const line& l);
+ vector operator()(scalar t) { return vector(dmnsn_line_point(m_line, t)); }
+
+ dmnsn_line dmnsn() const { return m_line; }
+
+ private:
+ dmnsn_line m_line;
+ };
+
+ // Vector operators
+
+ inline vector
+ operator+(const vector& lhs, const vector& rhs)
+ {
+ vector r = lhs;
+ r += rhs;
+ return r;
+ }
+
+ inline vector
+ operator-(const vector& lhs, const vector& rhs)
+ {
+ vector r = lhs;
+ r -= rhs;
+ return r;
+ }
+
+ inline vector
+ operator*(const vector& lhs, scalar rhs)
+ {
+ vector r = lhs;
+ r *= rhs;
+ return r;
+ }
+
+ inline vector
+ operator*(scalar lhs, const vector& rhs)
+ {
+ vector r = rhs;
+ r *= lhs;
+ return r;
+ }
+
+ inline vector
+ operator/(const vector& lhs, scalar rhs)
+ {
+ vector r = lhs;
+ r /= rhs;
+ return r;
+ }
+
+ inline scalar
+ dot(const vector& lhs, const vector& rhs)
+ {
+ return dmnsn_vector_dot(lhs.dmnsn(), rhs.dmnsn());
+ }
+
+ inline vector
+ cross(const vector& lhs, const vector& rhs)
+ {
+ return vector(dmnsn_vector_cross(lhs.dmnsn(), rhs.dmnsn()));
+ }
}
#endif /* DIMENSIONXX_GEOMETRY_HPP */