point: don't directly iterate over data

This commit is contained in:
Danny Robson 2018-04-16 15:54:08 +10:00
parent 2eb0b429ef
commit e7a76081e0
2 changed files with 4 additions and 28 deletions

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011-2016 Danny Robson <danny@nerdcruft.net>
* Copyright 2011-2018 Danny Robson <danny@nerdcruft.net>
*/
#include "point.hpp"
@ -23,30 +23,6 @@
using util::point;
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
util::vector<S,T>
util::point<S,T>::to (point<S,T> rhs) const
{
util::vector<S,T> out;
for (size_t i = 0; i < S; ++i)
out.data[i] = rhs.data[i] - this->data[i];
return out;
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
util::vector<S,T>
util::point<S,T>::from (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;
}
///////////////////////////////////////////////////////////////////////////////
namespace util::debug {
template <size_t S, typename T>

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011-2016 Danny Robson <danny@nerdcruft.net>
* Copyright 2011-2018 Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_UTIL_POINT_HPP
@ -34,8 +34,8 @@ namespace util {
{
using coord::base<S,T,point<S,T>>::base;
vector<S,T> to (point) const;
vector<S,T> from (point) const;
vector<S,T> to (point dst) const { return dst - *this; }
vector<S,T> from (point src) const { return *this - src; }
/// expand point to use homogenous coordinates of a higher dimension.
/// ie, fill with (0,..,0,1)