point: add from function

This commit is contained in:
Danny Robson 2015-03-07 03:20:07 +11:00
parent a2055b30bf
commit 8a0eee50e3
2 changed files with 16 additions and 2 deletions

View File

@ -28,10 +28,11 @@
using namespace std;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
util::vector<S,T>
util::point<S,T>::to (const point<S,T> &rhs) const {
util::point<S,T>::to (const point<S,T> &rhs) const
{
util::vector<S,T> out;
for (size_t i = 0; i < S; ++i)
@ -42,6 +43,18 @@ util::point<S,T>::to (const point<S,T> &rhs) const {
//-----------------------------------------------------------------------------
template <size_t S, typename T>
util::vector<S,T>
util::point<S,T>::from (const point<S,T> &rhs) const
{
util::vector<S,T> out;
for (size_t i = 0; i < S; ++i)
out.data[i] = this->data[i] - rhs.data[i];
return out;
}
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
void
util::point<S,T>::sanity (void) const {
CHECK (std::all_of (begin (this->data),

View File

@ -42,6 +42,7 @@ namespace util {
template <typename U> typename std::common_type<T,U>::type manhattan (const point<S,U> &) const;
vector<S,T> to (const point&) const;
vector<S,T> from (const point&) const;
template <size_t D> point<D,T> redim (void) const;
template <size_t D> point<D,T> redim (const util::point<D,T> &fill) const;