2011-06-23 22:04:51 +10:00
|
|
|
/*
|
|
|
|
* This file is part of libgim.
|
|
|
|
*
|
|
|
|
* libgim is free software: you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
2012-05-30 20:20:19 +10:00
|
|
|
*
|
2011-06-23 22:04:51 +10:00
|
|
|
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
2012-05-30 20:20:19 +10:00
|
|
|
*
|
2011-06-23 22:04:51 +10:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "point.hpp"
|
|
|
|
|
2011-10-18 21:45:55 +11:00
|
|
|
#include "debug.hpp"
|
2014-12-15 20:10:56 +11:00
|
|
|
#include "maths.hpp"
|
2011-10-18 21:45:55 +11:00
|
|
|
|
2011-06-23 22:04:51 +10:00
|
|
|
#include <cmath>
|
2014-12-15 20:10:56 +11:00
|
|
|
#include <cstdlib>
|
2011-06-23 22:04:51 +10:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2011-10-18 21:45:55 +11:00
|
|
|
|
2012-05-26 18:02:11 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-12-15 20:10:56 +11:00
|
|
|
template <size_t S, typename T>
|
|
|
|
util::vector<S,T>
|
|
|
|
util::point<S,T>::to (const point<S,T> &rhs) const {
|
|
|
|
util::vector<S,T> out;
|
2012-05-18 17:56:24 +10:00
|
|
|
|
|
|
|
for (size_t i = 0; i < S; ++i)
|
|
|
|
out.data[i] = rhs.data[i] - this->data[i];
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-26 18:02:11 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-12-15 20:10:56 +11:00
|
|
|
template <size_t S, typename T>
|
2011-10-18 21:45:55 +11:00
|
|
|
void
|
2014-12-15 20:10:56 +11:00
|
|
|
util::point<S,T>::sanity (void) const {
|
2015-01-28 14:49:34 +11:00
|
|
|
CHECK (std::all_of (begin (this->data),
|
|
|
|
end (this->data),
|
|
|
|
[] (double i) { return !std::isnan (i); }));
|
2011-10-18 21:45:55 +11:00
|
|
|
}
|
2011-09-13 16:49:10 +10:00
|
|
|
|
|
|
|
|
2015-01-05 18:08:20 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <size_t S, typename T>
|
|
|
|
const util::point<S,T> util::point<S,T>::ORIGIN (T {0});
|
|
|
|
|
2015-01-21 23:36:22 +11:00
|
|
|
|
2012-05-26 18:02:11 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2014-12-15 20:10:56 +11:00
|
|
|
template <size_t S, typename T>
|
2011-09-13 15:12:30 +10:00
|
|
|
std::ostream&
|
2014-12-15 20:10:56 +11:00
|
|
|
util::operator<< (std::ostream &os, const util::point<S,T> &p) {
|
2012-05-18 17:56:24 +10:00
|
|
|
os << "point" << S << "(";
|
|
|
|
os << p.data[0];
|
|
|
|
|
|
|
|
for (size_t i = 1; i < S; ++i)
|
|
|
|
os << ", " << p.data[i];
|
|
|
|
|
|
|
|
os << ")";
|
2011-09-13 15:12:30 +10:00
|
|
|
return os;
|
|
|
|
}
|
2012-05-18 17:56:24 +10:00
|
|
|
|
|
|
|
|
2015-01-21 23:36:22 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#define INSTANTIATE_S_T(S,T) \
|
|
|
|
template struct util::point<S,T>; \
|
|
|
|
template std::ostream& util::operator<< (std::ostream &os, const util::point<S,T>&); \
|
|
|
|
|
|
|
|
#define INSTANTIATE(T) \
|
|
|
|
INSTANTIATE_S_T(1,T) \
|
|
|
|
INSTANTIATE_S_T(2,T) \
|
|
|
|
INSTANTIATE_S_T(3,T) \
|
|
|
|
INSTANTIATE_S_T(4,T)
|
2012-06-08 16:45:39 +10:00
|
|
|
|
|
|
|
|
2014-12-15 20:10:56 +11:00
|
|
|
INSTANTIATE(int32_t)
|
|
|
|
INSTANTIATE(uint32_t)
|
|
|
|
INSTANTIATE(int64_t)
|
|
|
|
INSTANTIATE(uint64_t)
|
|
|
|
INSTANTIATE(float)
|
|
|
|
INSTANTIATE(double)
|