Commit ae27ccec authored by ESTERIE Pierre's avatar ESTERIE Pierre
Browse files

operators templated for points

parent b521ceb4
...@@ -162,7 +162,7 @@ namespace scalfmm::container ...@@ -162,7 +162,7 @@ namespace scalfmm::container
using arithmetic_type = Arithmetic; using arithmetic_type = Arithmetic;
using value_type = std::decay_t<Arithmetic>; using value_type = std::decay_t<Arithmetic>;
using point_proxy_type = point_proxy<std::remove_reference_t<arithmetic_type>, dimension>; using point_proxy_type = point_proxy<std::remove_reference_t<arithmetic_type>, dimension>;
using point_impl_type = point_impl<arithmetic_type, dimension>; using point_impl_type = point_impl<std::remove_reference_t<arithmetic_type>, dimension>;
using base_type = using base_type =
std::conditional_t<std::is_reference_v<Arithmetic>, point_proxy_type, std::conditional_t<std::is_reference_v<Arithmetic>, point_proxy_type,
point_impl_type>; point_impl_type>;
...@@ -179,7 +179,8 @@ namespace scalfmm::container ...@@ -179,7 +179,8 @@ namespace scalfmm::container
} }
// Addition assignment operator // Addition assignment operator
inline auto operator+=(point const& other) -> point& template<typename PointOrProxyOrArray>
inline auto operator+=(PointOrProxyOrArray const& other) -> point&
{ {
for(std::size_t i = 0; i < dimension; ++i) for(std::size_t i = 0; i < dimension; ++i)
{ {
...@@ -189,7 +190,8 @@ namespace scalfmm::container ...@@ -189,7 +190,8 @@ namespace scalfmm::container
} }
// Soustraction assignment operator // Soustraction assignment operator
inline auto operator-=(point const& other) -> point& template<typename PointOrProxyOrArray>
inline auto operator-=(point_proxy_type const& other) -> point&
{ {
for(std::size_t i = 0; i < dimension; ++i) for(std::size_t i = 0; i < dimension; ++i)
{ {
...@@ -199,7 +201,8 @@ namespace scalfmm::container ...@@ -199,7 +201,8 @@ namespace scalfmm::container
} }
// Data to data multiplication assignment // Data to data multiplication assignment
inline auto operator*=(point const& other) -> point& template<typename PointOrProxyOrArray>
inline auto operator*=(point_proxy_type const& other) -> point&
{ {
for(std::size_t i = 0; i < dimension; ++i) for(std::size_t i = 0; i < dimension; ++i)
{ {
...@@ -209,7 +212,8 @@ namespace scalfmm::container ...@@ -209,7 +212,8 @@ namespace scalfmm::container
} }
// Data to data division assignment // Data to data division assignment
inline auto operator/=(point const& other) -> point& template<typename PointOrProxyOrArray>
inline auto operator/=(point_proxy_type const& other) -> point&
{ {
for(std::size_t i = 0; i < dimension; ++i) for(std::size_t i = 0; i < dimension; ++i)
{ {
...@@ -298,7 +302,7 @@ namespace scalfmm::container ...@@ -298,7 +302,7 @@ namespace scalfmm::container
/// \brief norm compute the L2 norm of the point_impl. /// \brief norm compute the L2 norm of the point_impl.
/// \return the L2 norm of the point_impl. /// \return the L2 norm of the point_impl.
/// ///
inline auto norm() -> value_type inline auto norm() const -> value_type
{ {
value_type square_sum{0}; value_type square_sum{0};
for(auto a: *this) for(auto a: *this)
...@@ -307,6 +311,18 @@ namespace scalfmm::container ...@@ -307,6 +311,18 @@ namespace scalfmm::container
} }
return std::sqrt(square_sum); return std::sqrt(square_sum);
} }
template<typename PointOrProxyOrArray>
inline auto distance(PointOrProxyOrArray const& p) const -> value_type
{
value_type square_sum{0};
for(std::size_t i{0}; i<dimension; ++i)
{
auto tmp = (*this)[i] - p.at(i);
square_sum += tmp*tmp;
}
return std::sqrt(square_sum);
}
}; };
template<typename Arithmetic, std::size_t Dim> template<typename Arithmetic, std::size_t Dim>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment