Add point::redim implementation

This commit is contained in:
Danny Robson 2014-02-18 15:28:28 +11:00
parent db62693535
commit 9cc47a05bd
5 changed files with 51 additions and 3 deletions

View File

@ -101,6 +101,7 @@ UTIL_FILES = \
platform.hpp \
point.cpp \
point.hpp \
point.ipp \
pool.cpp \
pool.hpp \
pool.ipp \

View File

@ -14,7 +14,7 @@
* 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>
* Copyright 2011-14 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_POINT_HPP
@ -53,7 +53,7 @@ namespace util {
util::vector<S> to (const point<S>&) const;
template <size_t D> point<D> redim (void);
template <size_t D> point<D> redim (void) const;
void sanity (void) const;
};
@ -68,6 +68,6 @@ namespace util {
std::ostream& operator<< (std::ostream&, const util::point<S>&);
}
#include "point.ipp"
#endif // __UTIL_POINT_HPP

30
point.ipp Normal file
View File

@ -0,0 +1,30 @@
/*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Danny Robson <danny@nerdcruft.net>
*/
#include <algorithm>
namespace util {
template<size_t S>
template<size_t D>
point<D> point<S>::redim (void) const {
point<D> out;
std::copy (std::begin (this->data), std::begin (this->data) + D, std::begin (out.data));
return out;
}
}

View File

@ -15,6 +15,7 @@ TEST_BIN = \
md4 \
md5 \
options \
point \
pool \
rand \
range \

16
test/point.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "point.hpp"
#include "debug.hpp"
#include "types.hpp"
using namespace util;
int
main (int, char**) {
const point<3> p(0.0, 1.0, 2.0);
const point<2> q = p.redim<2> ();
CHECK_EQ (q.data[0], p.data[0]);
CHECK_EQ (q.data[1], p.data[1]);
}