wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
ActiveTranslation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4#include <type_traits>
5#include <utility>
6
12#include "wuzp/core/helpers.hpp"
13#include "wuzp/core/traits.hpp"
15#include "wuzp/trafo/internal/translate.hpp"
16#include "wuzp/trafo/traits.hpp"
17
18namespace wuzp {
19
26template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, AnyCoordinateSystem CoordinateSystemT_,
27 typename... UnitsT_>
29class ActiveTranslation : public ActiveTransformation<ActiveTranslation<ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_...>> {
30 public:
31 using ValueT = ValueT_;
32 using ValuesT = ValuesT_<ValueT_, DimensionV_, 1>;
33 using UnitsT = TypeMatrix<DimensionV_, 1, UnitsT_...>;
35 using CoordinateSystemT = CoordinateSystemT_;
37
38 // Copies and moves are left to the implicit constructors, see CopiesOrMoves.
39 template <typename... Args>
40 requires(!CopiesOrMoves<ActiveTranslation, Args...>)
41 explicit ActiveTranslation(Args&&... args) : tensor_{std::forward<Args>(args)...} {}
42
43 const TensorT& getTensor() const { return tensor_; }
45 const QuantitiesT& getQuantities() const { return tensor_.getQuantities(); }
46
48 ActiveTranslation inverse() const { return ActiveTranslation{-tensor_}; }
49
52 template <template <typename, int, int> typename ValuesOtherT_, int DimensionOtherV_, typename ValueOtherT_,
53 typename CoordinateSystemOtherT_, typename... UnitsOtherT_>
55 const ValueT precision = Precision<ValueT>::value()) const {
56 return tensor_.isApprox(other.getTensor(), precision);
57 }
58
59 private:
61 TensorT tensor_;
62};
63
64template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename CoordinateSystemT_,
65 typename... UnitsT_>
66struct GetCoordinateSystem<ActiveTranslation<ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_...>> {
67 using type = CoordinateSystemT_;
68};
69
70// An active translation moves points, leaves vectors, covectors and tensors with two upper indices unchanged, and rejects the
71// other tensors (see internal::translate()). It takes the object by a forwarding reference, so that a temporary vector is moved
72// rather than copied.
73template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename CoordinateSystemT_,
74 typename... UnitsT_, typename IndicesOtherT_, typename QuantitiesOtherT_, typename CoordinateSystemOtherT_,
75 typename AbsoluteOtherT_>
76struct TransformationTraits<ActiveTranslation<ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_...>,
77 Tensor<IndicesOtherT_, QuantitiesOtherT_, CoordinateSystemOtherT_, AbsoluteOtherT_>> {
79 template <typename ObjectT_>
80 requires std::is_same_v<std::remove_cvref_t<ObjectT_>, ObjectT>
82 ObjectT_&& object) {
83 static_assert(std::is_same_v<CoordinateSystemT_, CoordinateSystemOtherT_>, "Coordinate systems do not match.");
84 return internal::translate<CoordinateSystemT_>(std::forward<ObjectT_>(object), transformation.getQuantities());
85 }
86};
87
88// The conjugation T_t T_s T_-t of a translation by a translation is the translation itself: translations commute.
89template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename CoordinateSystemT_,
90 typename... UnitsT_, template <typename, int, int> typename ValuesOtherT_, int DimensionOtherV_, typename ValueOtherT_,
91 typename CoordinateSystemOtherT_, typename... UnitsOtherT_>
92struct TransformationTraits<ActiveTranslation<ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_...>,
93 ActiveTranslation<ValuesOtherT_, DimensionOtherV_, ValueOtherT_, CoordinateSystemOtherT_, UnitsOtherT_...>> {
94 static auto transform(
97 return ActiveTranslation<ValuesOtherT_, DimensionOtherV_, ValueOtherT_, CoordinateSystemOtherT_, UnitsOtherT_...>(
98 transformation.transform(object.getTensor()));
99 }
100};
101
102// The composition of two translations is the translation by the sum of their vectors, t_lhs + t_rhs.
103template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename CoordinateSystemLhsT_,
104 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
105 typename CoordinateSystemRhsT_, typename... UnitsRhsT_>
106struct CompositionTraits<ActiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, CoordinateSystemLhsT_, UnitsLhsT_...>,
107 ActiveTranslation<ValuesRhsT_, DimensionRhsV_, ValueRhsT_, CoordinateSystemRhsT_, UnitsRhsT_...>> {
110 return ActiveTranslation<ValuesLhsT_, DimensionLhsV_, ValueLhsT_, CoordinateSystemLhsT_, UnitsLhsT_...>{lhs.getTensor() +
111 rhs.getTensor()};
112 }
113};
114
115template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename CoordinateSystemLhsT_,
116 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
117 typename CoordinateSystemRhsT_, typename... UnitsRhsT_>
122
123template <template <typename, int, int> typename ValuesLhsT_, int DimensionLhsV_, typename ValueLhsT_, typename CoordinateSystemLhsT_,
124 typename... UnitsLhsT_, template <typename, int, int> typename ValuesRhsT_, int DimensionRhsV_, typename ValueRhsT_,
125 typename CoordinateSystemRhsT_, typename... UnitsRhsT_>
130
131template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename CoordinateSystemT_,
132 typename... UnitsT_>
134 lhs << rhs.getTensor();
135 return lhs;
136}
137
138template <template <typename, int, int> typename ValuesT_, int DimensionV_, typename ValueT_, typename CoordinateSystemT_>
141template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename CoordinateSystemT_>
143template <template <typename, int, int> typename ValuesT_, typename ValueT_, typename CoordinateSystemT_>
145
146} // namespace wuzp
An active transformation, which moves objects within its coordinate system (see Transformation).
auto transform(ObjectT_ &&object) const
The transformed object. A temporary is passed on as one, like with PassiveTransformation::transform()...
An active translation, which moves points by a vector t, p' = p + t, and leaves vectors,...
const QuantitiesT & getQuantities() const
The components of the translation, like getQuantities() of the linear transformations.
const TensorT & getTensor() const
ActiveTranslation inverse() const
The inverse translation, by -t.
ActiveTranslation(Args &&... args)
bool isApprox(const ActiveTranslation< ValuesOtherT_, DimensionOtherV_, ValueOtherT_, CoordinateSystemOtherT_, UnitsOtherT_... > &other, const ValueT precision=Precision< ValueT >::value()) const
Whether both translations, which must be expressed in the same coordinate system, are approximately e...
Container to store quantities.
A tensor of rank 0, 1 or 2, whose components are quantities, expressed in a coordinate system,...
Definition Tensor.hpp:99
Any coordinate system: a specialization of CoordinateSystem, including the intermediate ones of trans...
Definition concepts.hpp:30
The alias template ValueMatrix<ValueT_, RowsV_, ColsV_> of any value matrix backend,...
Definition concepts.hpp:89
Whether constructing a Class from the arguments copies or moves it, i.e. whether they are a single Cl...
Definition helpers.hpp:69
bool operator!=(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
std::ostream & operator<<(std::ostream &lhs, const Quantities< ValuesT_, UnitsT_ > &rhs)
ActiveTranslation< ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, typename AccessUnits< AccessImplementation< ValueT_ > >::Length > ActiveSpatialTranslation
internal::AbsoluteImpl< false > Relative
Definition Absolute.hpp:18
bool operator==(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
typename CreateTypeMatrix< RowsV_, ColsV_, Types... >::type TypeMatrix
A matrix storing types at compile-time.
ActiveSpatialTranslation< ValuesT_, 3, ValueT_, CoordinateSystemT_ > ActiveSpatialTranslation3
ActiveSpatialTranslation< ValuesT_, 2, ValueT_, CoordinateSystemT_ > ActiveSpatialTranslation2
static auto compose(const ActiveTranslation< ValuesLhsT_, DimensionLhsV_, ValueLhsT_, CoordinateSystemLhsT_, UnitsLhsT_... > &lhs, const ActiveTranslation< ValuesRhsT_, DimensionRhsV_, ValueRhsT_, CoordinateSystemRhsT_, UnitsRhsT_... > &rhs)
The composition lhs * rhs of two transformations, which applies rhs first, then lhs: (lhs * rhs)....
Definition traits.hpp:39
static constexpr ValueT_ value()
Definition traits.hpp:356
static auto transform(const ActiveTranslation< ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_... > &transformation, const ActiveTranslation< ValuesOtherT_, DimensionOtherV_, ValueOtherT_, CoordinateSystemOtherT_, UnitsOtherT_... > &object)
static auto transform(const ActiveTranslation< ValuesT_, DimensionV_, ValueT_, CoordinateSystemT_, UnitsT_... > &transformation, ObjectT_ &&object)
How a transformation transforms an object: static auto transform(const TransformationT_&,...
Definition traits.hpp:19