wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
PassiveTransformation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <utility>
5
11#include "wuzp/trafo/traits.hpp"
12
13namespace wuzp {
14
22template <typename DerivedT_, AnyCoordinateSystem FromT_, AnyCoordinateSystem ToT_>
23class PassiveTransformation : public internal::Crtp<DerivedT_, Transformation<DerivedT_>> {
24 public:
25 using From = FromT_;
26 using To = ToT_;
27
30 template <typename ObjectT_>
31 auto transform(ObjectT_&& object) const {
32 using ObjectT = std::remove_cvref_t<ObjectT_>;
33 // Checked before the coordinate system: passive transformations have none, which would fail with a message about a trait.
34 static_assert(!AnyTransformation<ObjectT>,
35 "A passive transformation transforms tensors, not transformations. Compose transformations with operator*.");
36 static_assert(std::is_same<typename GetCoordinateSystem<ObjectT>::type, From>::value, "Coordinate systems do not match.");
37 return TransformationTraits<DerivedT_, ObjectT>::transform(this->derived(), std::forward<ObjectT_>(object));
38 }
39};
40
48template <typename LhsT_, typename FromLhsT_, typename ToLhsT_, typename RhsT_, typename FromRhsT_, typename ToRhsT_>
50 static_assert(std::is_same_v<FromLhsT_, ToRhsT_>, "Adjacent frames do not match.");
51 return CompositionTraits<LhsT_, RhsT_>::compose(static_cast<const LhsT_&>(lhs), static_cast<const RhsT_&>(rhs));
52}
53
54// An active and a passive transformation cannot be composed: CompositionTraits rejects them with a message.
55template <typename LhsT_, typename RhsT_, typename FromRhsT_, typename ToRhsT_>
57 return CompositionTraits<LhsT_, RhsT_>::compose(static_cast<const LhsT_&>(lhs), static_cast<const RhsT_&>(rhs));
58}
59template <typename LhsT_, typename FromLhsT_, typename ToLhsT_, typename RhsT_>
61 return CompositionTraits<LhsT_, RhsT_>::compose(static_cast<const LhsT_&>(lhs), static_cast<const RhsT_&>(rhs));
62}
63
64namespace internal {
65
69template <typename LhsT_, typename RhsT_>
70struct SameFrames {
71 static_assert(std::is_same_v<typename LhsT_::From, typename RhsT_::From>, "'From' coordinate systems do not match.");
72 static_assert(std::is_same_v<typename LhsT_::To, typename RhsT_::To>, "'To' coordinate systems do not match.");
73 static constexpr bool value = true;
74};
75
78template <typename PassiveT_, typename NewFromT_, typename NewToT_>
79struct WithFrames;
80
81} // namespace internal
82
83} // namespace wuzp
An active transformation, which moves objects within its coordinate system (see Transformation).
A passive transformation, which expresses the objects of the coordinate system From in the coordinate...
auto transform(ObjectT_ &&object) const
The object in To.
A transformation of wuzp, i.e. a type that derives from Transformation, also through a class that der...
auto operator*(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const ValueRhsT_ rhs)
The composition lhs * rhs of two transformations, which applies rhs first, then lhs: (lhs * rhs)....
Definition traits.hpp:39
How a transformation transforms an object: static auto transform(const TransformationT_&,...
Definition traits.hpp:19