From fa16f24845e43a009a488d1dbc5136c4d44cd406 Mon Sep 17 00:00:00 2001
From: Philip Trettner <Philip.Trettner@rwth-aachen.de>
Date: Mon, 11 May 2020 11:10:47 +0200
Subject: [PATCH] after long discussion, added pos + pos = pos

---
 .../detail/operators/ops_pos.hh               | 14 +++----
 src/typed-geometry/detail/sum_of_pos.hh       | 40 -------------------
 2 files changed, 5 insertions(+), 49 deletions(-)
 delete mode 100644 src/typed-geometry/detail/sum_of_pos.hh

diff --git a/src/typed-geometry/detail/operators/ops_pos.hh b/src/typed-geometry/detail/operators/ops_pos.hh
index 1ffc10e9..940266ce 100644
--- a/src/typed-geometry/detail/operators/ops_pos.hh
+++ b/src/typed-geometry/detail/operators/ops_pos.hh
@@ -2,7 +2,6 @@
 
 #include <typed-geometry/detail/macros.hh>
 #include <typed-geometry/detail/scalar_traits.hh>
-#include <typed-geometry/detail/sum_of_pos.hh>
 #include <typed-geometry/types/dir.hh>
 #include <typed-geometry/types/pos.hh>
 #include <typed-geometry/types/size.hh>
@@ -36,13 +35,10 @@ TG_IMPL_DEFINE_BINARY_OP_SCALAR(pos, +);
 TG_IMPL_DEFINE_BINARY_OP_SCALAR(pos, *);
 TG_IMPL_DEFINE_BINARY_OP_SCALAR_DIV(pos);
 
-// special pos+pos handling
-template <int D, class ScalarT>
-[[nodiscard]] constexpr sum_of_pos<D, ScalarT> operator+(pos<D, ScalarT> const& a, pos<D, ScalarT> const& b)
-{
-    return sum_of_pos(a) + b;
-}
-
-// deprecated / not supported operations
+// pos + pos results in a pos
+// NOTE: this should only be used if the result is still a proper position
+//       e.g. for weighted sums, such as "pos * 0.3 + pos * 0.7"
+//            or as a shortcut for "tanslation(pos) * pos"
+TG_IMPL_DEFINE_BINARY_OP(pos, pos, pos, +);
 
 } // namespace tg
diff --git a/src/typed-geometry/detail/sum_of_pos.hh b/src/typed-geometry/detail/sum_of_pos.hh
deleted file mode 100644
index c4fa3227..00000000
--- a/src/typed-geometry/detail/sum_of_pos.hh
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-
-#include <typed-geometry/types/pos.hh>
-#include <typed-geometry/types/vec.hh>
-
-namespace tg
-{
-/*
- * sum_of_pos is a helper struct for guaranteeing syntactic soundness when dealing with sums of positions
- * it is the result of operator+(pos, pos)
- * it can only be added onto other sum_of_pos
- * to get back to a pos one needs to use operator/(sum_of_pos, ScalarT)
- */
-template <int D, class ScalarT>
-struct sum_of_pos
-{
-    using scalar_t = ScalarT;
-    using div_t = decltype(ScalarT() / 0.0f);
-    using pos_t = pos<D, ScalarT>;
-
-    constexpr sum_of_pos() = default;
-    /* implicit */ constexpr sum_of_pos(pos_t const& p) : accum(p) {}
-    constexpr auto operator/(div_t const& rhs) const
-    {
-        using T = std::common_type_t<ScalarT, div_t>;
-        return pos<D, T>(accum) / T(rhs);
-    }
-    constexpr auto operator*(div_t const& rhs) const
-    {
-        using T = std::common_type_t<ScalarT, div_t>;
-        return pos<D, T>(accum) * T(rhs);
-    }
-
-    constexpr sum_of_pos operator+(sum_of_pos const& rhs) const { return accum + vec(rhs); }
-    constexpr sum_of_pos operator+(pos_t const& rhs) const { return accum + vec(rhs); }
-
-private:
-    pos_t accum;
-};
-}
-- 
GitLab