diff --git a/point.cpp b/point.cpp index bc186792..e2630171 100644 --- a/point.cpp +++ b/point.cpp @@ -22,16 +22,15 @@ #include #include -using namespace std; +using util::point; /////////////////////////////////////////////////////////////////////////////// template util::vector -util::point::to (const point &rhs) const +util::point::to (point rhs) const { util::vector out; - for (size_t i = 0; i < S; ++i) out.data[i] = rhs.data[i] - this->data[i]; return out; @@ -41,7 +40,7 @@ util::point::to (const point &rhs) const //----------------------------------------------------------------------------- template util::vector -util::point::from (const point &rhs) const +util::point::from (point rhs) const { util::vector out; for (size_t i = 0; i < S; ++i) @@ -53,10 +52,11 @@ util::point::from (const point &rhs) const /////////////////////////////////////////////////////////////////////////////// template void -util::point::sanity (void) const { - CHECK (std::all_of (begin (this->data), - end (this->data), - [] (double i) { return !std::isnan (i); })); +util::point::sanity (void) const +{ + CHECK (std::all_of (this->begin (), + this->end (), + [] (auto i) { return !std::isnan (i); })); } @@ -68,7 +68,7 @@ const util::point util::point::ORIGIN (T {0}); //----------------------------------------------------------------------------- template std::ostream& -util::operator<< (std::ostream &os, const util::point &p) { +util::operator<< (std::ostream &os, util::point p) { os << "point" << S << "("; os << p.data[0]; @@ -81,9 +81,9 @@ util::operator<< (std::ostream &os, const util::point &p) { //----------------------------------------------------------------------------- -#define INSTANTIATE_S_T(S,T) \ -template struct util::point; \ -template std::ostream& util::operator<< (std::ostream &os, const util::point&); \ +#define INSTANTIATE_S_T(S,T) \ +template struct util::point; \ +template std::ostream& util::operator<< (std::ostream &os, util::point); \ #define INSTANTIATE(T) \ INSTANTIATE_S_T(1,T) \ diff --git a/point.hpp b/point.hpp index f93912e4..bc40e09a 100644 --- a/point.hpp +++ b/point.hpp @@ -34,12 +34,12 @@ namespace util { using coord::base::base; // point operators - template typename std::common_type::type distance (const point &) const; - template typename std::common_type::type distance2 (const point &) const; - template typename std::common_type::type manhattan (const point &) const; + template typename std::common_type::type distance (point) const; + template typename std::common_type::type distance2 (point) const; + template typename std::common_type::type manhattan (point) const; - vector to (const point&) const; - vector from (const point&) const; + vector to (point) const; + vector from (point) const; template point homog (void) const; @@ -50,7 +50,7 @@ namespace util { // iostream operators template - std::ostream& operator<< (std::ostream&, const point&); + std::ostream& operator<< (std::ostream&, point); // Convenience typedefs typedef point<2,float> point2f; @@ -69,7 +69,7 @@ namespace util { namespace std { template struct hash> { - size_t operator() (const util::point &p) const { + size_t operator() (util::point p) const { std::hash h; size_t k = 0; diff --git a/point.ipp b/point.ipp index a31720b4..dba6dadd 100644 --- a/point.ipp +++ b/point.ipp @@ -23,7 +23,8 @@ namespace util { template template typename std::common_type::type - util::point::distance (const point &rhs) const { + util::point::distance (point rhs) const + { return std::sqrt (distance2 (rhs)); } @@ -32,7 +33,8 @@ namespace util { template template typename std::common_type::type - util::point::distance2 (const point &rhs) const { + util::point::distance2 (point rhs) const + { typedef typename std::common_type::type result_t; result_t sum { 0 }; @@ -48,7 +50,8 @@ namespace util { template template typename std::common_type::type - util::point::manhattan (const point &rhs) const { + util::point::manhattan (point rhs) const + { typedef typename std::common_type::type result_t; result_t sum { 0 };