From 8a0eee50e37de52c7b8ae4d68088e213190a45b2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 7 Mar 2015 03:20:07 +1100 Subject: [PATCH] point: add from function --- point.cpp | 17 +++++++++++++++-- point.hpp | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/point.cpp b/point.cpp index 104e55fc..56c56e8f 100644 --- a/point.cpp +++ b/point.cpp @@ -28,10 +28,11 @@ using namespace std; -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// template util::vector -util::point::to (const point &rhs) const { +util::point::to (const point &rhs) const +{ util::vector out; for (size_t i = 0; i < S; ++i) @@ -42,6 +43,18 @@ util::point::to (const point &rhs) const { //----------------------------------------------------------------------------- template +util::vector +util::point::from (const point &rhs) const +{ + util::vector out; + for (size_t i = 0; i < S; ++i) + out.data[i] = this->data[i] - rhs.data[i]; + return out; +} + + +/////////////////////////////////////////////////////////////////////////////// +template void util::point::sanity (void) const { CHECK (std::all_of (begin (this->data), diff --git a/point.hpp b/point.hpp index 7c3b68b1..87ab14e2 100644 --- a/point.hpp +++ b/point.hpp @@ -42,6 +42,7 @@ namespace util { template typename std::common_type::type manhattan (const point &) const; vector to (const point&) const; + vector from (const point&) const; template point redim (void) const; template point redim (const util::point &fill) const;