diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-04-10 20:53:27 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-04-10 20:53:27 +0000 |
commit | c29bc5a684107737b60be1474e8bd6470ce4eae9 (patch) | |
tree | dbc3340453947e1d2f208861eb850fb1871d2b5d /libdimensionxx | |
parent | 3d9ca12a6a9e1e584c81557d0c267cb4a99e6c82 (diff) | |
download | dimension-c29bc5a684107737b60be1474e8bd6470ce4eae9.tar.xz |
Wrote C++ geometry wrapper header.
Diffstat (limited to 'libdimensionxx')
-rw-r--r-- | libdimensionxx/Makefile.am | 2 | ||||
-rw-r--r-- | libdimensionxx/dimensionxx/geometry.hpp | 108 |
2 files changed, 110 insertions, 0 deletions
diff --git a/libdimensionxx/Makefile.am b/libdimensionxx/Makefile.am index 60608e4..39687fe 100644 --- a/libdimensionxx/Makefile.am +++ b/libdimensionxx/Makefile.am @@ -19,6 +19,8 @@ nobase_include_HEADERS = dimensionxx.hpp dimensionxx/geometry.hpp dimensionxx/color.hpp dimensionxx/canvas.hpp +INCLUDES = -I../libdimension -I../libdimension-png + lib_LTLIBRARIES = libdimensionxx.la libdimensionxx_la_SOURCES = dimensionxx.hpp dimensionxx/geometry.hpp dimensionxx/color.hpp dimensionxx/canvas.hpp canvas.cpp color.cpp geometry.cpp 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 */ |