From bd88832df3f1b7f0b65ca0ded2fb759b4273dbec Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 9 Apr 2015 17:58:47 +1000 Subject: [PATCH] coord: move cast/redim operations to coord --- Makefile.am | 1 - coord/base.hpp | 62 ++++++++++++++++++++++++++++++++++ extent.hpp | 3 -- extent.ipp | 11 ------ point.hpp | 6 ---- point.ipp | 62 ---------------------------------- test/point.cpp | 8 +++++ vector.hpp | 9 ----- vector.ipp | 91 -------------------------------------------------- 9 files changed, 70 insertions(+), 183 deletions(-) delete mode 100644 vector.ipp diff --git a/Makefile.am b/Makefile.am index b3b5fc2f..069d533e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -183,7 +183,6 @@ UTIL_FILES = \ uri.cpp \ vector.cpp \ vector.hpp \ - vector.ipp \ version.cpp \ version.hpp \ view.cpp \ diff --git a/coord/base.hpp b/coord/base.hpp index 13bd1f93..8a72cdff 100644 --- a/coord/base.hpp +++ b/coord/base.hpp @@ -21,6 +21,7 @@ #define __UTIL_COORD_BASE_HPP #include "init.hpp" +#include "../maths.hpp" #include #include @@ -66,6 +67,67 @@ namespace util { namespace coord { std::copy (begin (), end (), k.begin ()); return k; } + + //--------------------------------------------------------------------- + template + KLASS + cast (void) const + { + KLASS out; + std::copy (std::begin (this->data), + std::end (this->data), + std::begin (out.data)); + return out; + } + + /////////////////////////////////////////////////////////////////////// + // redimension + template + KLASS + redim (void) const + { + KLASS out; + std::copy_n (std::begin (this->data), + min (S, D), + std::begin (out.data)); + return out; + } + + + //--------------------------------------------------------------------- + template + KLASS + redim (const KLASS fill) const + { + KLASS out; + + static constexpr auto L1 = min (S, D); + static constexpr auto L2 = D - L1; + + std::copy_n (std::begin (this->data), + L1, + std::begin (out.data)); + + std::copy_n (fill.data + L1, + L2, + out.data + L1); + return out; + } + + //--------------------------------------------------------------------- + template + KLASS + redim (T fill) const + { + KLASS out; + + auto cursor = std::copy_n (std::begin (this->data), + min (S, D), + std::begin (out.data)); + std::fill (cursor, std::end (out.data), fill); + + return out; + } }; } } diff --git a/extent.hpp b/extent.hpp index ef559b47..ffa8c3fa 100644 --- a/extent.hpp +++ b/extent.hpp @@ -50,9 +50,6 @@ namespace util { bool empty (void) const; - template - extent cast (void) const; - static const extent MAX; static const extent MIN; }; diff --git a/extent.ipp b/extent.ipp index 17c1d07a..57989183 100644 --- a/extent.ipp +++ b/extent.ipp @@ -26,17 +26,6 @@ #include -//----------------------------------------------------------------------------- -template -template -util::extent -util::extent::cast (void) const -{ - util::extent out; - std::copy (std::begin (this->data), std::end (this->data), std::begin (out.data)); - return out; -} - //----------------------------------------------------------------------------- template diff --git a/point.hpp b/point.hpp index dc674395..e3df987c 100644 --- a/point.hpp +++ b/point.hpp @@ -44,16 +44,10 @@ namespace util { vector to (const point&) const; vector from (const point&) const; - template point redim (void) const; - template point redim (const util::point &fill) const; - template point redim (T fill) const; - template point homog (void) const; static const point ORIGIN; - template point cast (void) const; - void sanity (void) const; }; diff --git a/point.ipp b/point.ipp index 5c2abf0c..a74b5550 100644 --- a/point.ipp +++ b/point.ipp @@ -63,54 +63,6 @@ namespace util { } - //------------------------------------------------------------------------- - template - template - point point::redim (void) const { - point out; - std::copy_n (std::begin (this->data), - min (S, D), - std::begin (out.data)); - return out; - } - - - //------------------------------------------------------------------------- - template - template - point point::redim (const point &fill) const { - point out; - - static constexpr auto L1 = min (S, D); - static constexpr auto L2 = D - L1; - - std::copy_n (std::begin (this->data), - L1, - std::begin (out.data)); - - std::copy_n (fill.data + L1, - L2, - out.data + L1); - return out; - } - - - //------------------------------------------------------------------------- - template - template - point point::redim (T fill) const - { - point out; - - auto cursor = std::copy_n (std::begin (this->data), - min (S, D), - std::begin (out.data)); - std::fill (cursor, std::end (out.data), fill); - - return out; - } - - ///------------------------------------------------------------------------ /// expand point to use homogenous coordinates of a higher dimension. /// ie, fill with (0,..,0,1) @@ -136,18 +88,4 @@ namespace util { return out; } - - - //------------------------------------------------------------------------- - template - template - point - point::cast (void) const - { - point out; - std::copy (std::begin (this->data), - std::end (this->data), - std::begin (out.data)); - return out; - } } diff --git a/test/point.cpp b/test/point.cpp index b46ac108..128e3ba8 100644 --- a/test/point.cpp +++ b/test/point.cpp @@ -38,6 +38,14 @@ main (int, char**) { CHECK_EQ (q.data[3], FILL.data[3]); } + // Simple linking check for coord type casting. Relies on truncation. + { + const point2f pf (0.5f, 0.2f); + const point2u pu (0, 0); + + CHECK_EQ (pf.template cast (), pu); + } + { const point2f p (3, 4); const point4f q = p.homog<4> (); diff --git a/vector.hpp b/vector.hpp index 891583f8..91269f93 100644 --- a/vector.hpp +++ b/vector.hpp @@ -45,16 +45,9 @@ namespace util { vector& normalise (void); vector normalised [[gnu::warn_unused_result]] (void) const; - // size operations - template vector redim (void) const; - template vector redim (const util::vector &fill) const; - template vector redim (T fill) const; - // constants static const vector ZERO; - template vector cast (void) const; - void sanity (void) const; }; @@ -85,7 +78,5 @@ namespace util { typedef vector<3,double> vector4d; } -#include "vector.ipp" - #endif diff --git a/vector.ipp b/vector.ipp deleted file mode 100644 index e437734d..00000000 --- a/vector.ipp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 . - * - * Copyright 2014 Danny Robson - */ - -#ifdef __UTIL_VECTOR_IPP -#error "twice included ipp" -#endif - -#define __UTIL_VECTOR_IPP - -#include "maths.hpp" - -namespace util { - //------------------------------------------------------------------------- - template - template - vector vector::redim (void) const - { - vector out; - std::copy_n (std::begin (this->data), - min (S, D), - std::begin (out.data)); - return out; - } - - - //------------------------------------------------------------------------- - template - template - vector vector::redim (const vector &fill) const - { - vector out; - - static constexpr auto L1 = min (S, D); - static constexpr auto L2 = D - L1; - - std::copy_n (std::begin (this->data), - L1, - std::begin (out.data)); - - std::copy_n (fill.data + L1, - L2, - out.data + L1); - return out; - } - - - //------------------------------------------------------------------------- - template - template - vector vector::redim (T fill) const - { - vector out; - - auto cursor = std::copy_n (std::begin (this->data), - min (S, D), - std::begin (out.data)); - std::fill (cursor, std::end (out.data), fill); - - return out; - } - - - //------------------------------------------------------------------------- - template - template - vector - vector::cast (void) const - { - vector out; - std::copy (std::begin (this->data), - std::end (this->data), - std::begin (out.data)); - return out; - } -}