wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
Absolute.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "wuzp/core/internal/AbsoluteImpl.hpp"
5
6// Absolute objects are points, relative objects are vectors. Their operations follow the rules of affine spaces, like CGAL's
7// points and vectors (https://doc.cgal.org/latest/Kernel_23/index.html) and mp-units' quantity points
8// (https://mpusz.github.io/mp-units/latest/users_guide/framework_basics/the_affine_space/): p - q is a vector, p + v, v + p and
9// p - v are points. Every other operation on a point depends on the origin of its coordinate system, e.g. the product with a
10// scalar, the negation or the inverse, so it is rejected: in the terms of Atkey, Johann and Kennedy, "Abstraction and invariance
11// for algebraically indexed types" (POPL 2013, https://doi.org/10.1145/2429069.2429082), it is not invariant under translations.
12// Affine combinations are written p + (q - p) * t. The traits of this file check the absoluteness of the operands and compute
13// that of the result, like the traits of Indices.hpp do for indices; Tensor.hpp combines them.
14
15namespace wuzp {
16
17using Absolute = internal::AbsoluteImpl<true>;
18using Relative = internal::AbsoluteImpl<false>;
19
20template <bool ValueLhs_, bool ValueRhs_>
21struct Sum<internal::AbsoluteImpl<ValueLhs_>, internal::AbsoluteImpl<ValueRhs_>> {
22 static_assert(!ValueLhs_ || !ValueRhs_, "Two absolute objects cannot be summed.");
24};
25
26template <bool ValueLhs_, bool ValueRhs_>
27struct Difference<internal::AbsoluteImpl<ValueLhs_>, internal::AbsoluteImpl<ValueRhs_>> {
28 static_assert(ValueLhs_ || !ValueRhs_, "An absolute object cannot be subtracted from a relative object.");
29 using type = typename IfThenElse<ValueLhs_, typename IfThenElse<ValueRhs_, Relative, Absolute>::type, Relative>::type;
30};
31
32template <bool Value_>
33struct Negation<internal::AbsoluteImpl<Value_>> {
34 static_assert(!Value_, "An absolute object cannot be negated.");
35 using type = Relative;
36};
37
39template <bool ValueLhs_, bool ValueRhs_>
40struct Product<internal::AbsoluteImpl<ValueLhs_>, internal::AbsoluteImpl<ValueRhs_>> {
41 static_assert(!ValueLhs_ && !ValueRhs_, "An absolute object cannot appear in a multiplication.");
42 using type = Relative;
43};
44
46template <bool ValueLhs_, bool ValueRhs_>
47struct Division<internal::AbsoluteImpl<ValueLhs_>, internal::AbsoluteImpl<ValueRhs_>> {
48 static_assert(!ValueLhs_ && !ValueRhs_, "An absolute object cannot appear in a division.");
49 using type = Relative;
50};
51
52template <bool Value_, typename ExponentT_>
53struct Power<internal::AbsoluteImpl<Value_>, ExponentT_> {
54 static_assert(!Value_, "An absolute object cannot be powered.");
55 using type = Relative;
56};
57
59template <bool Value_>
60struct Inverse<internal::AbsoluteImpl<Value_>> {
61 static_assert(!Value_, "An absolute object cannot be inverted.");
62 using type = Relative;
63};
64
67template <bool Value_>
68struct Norm<internal::AbsoluteImpl<Value_>> {
69 static_assert(!Value_, "The norm of a point depends on the origin. Use the norm of a difference of points, e.g. (p - q).norm().");
70 using type = Relative;
71};
72
73template <bool Value_>
74struct IsAbsolute<internal::AbsoluteImpl<Value_>> {
75 static constexpr bool value = Value_;
76};
77
79template <bool Value_>
80struct MakeRelative<internal::AbsoluteImpl<Value_>> {
81 static_assert(Value_, "The object is already relative.");
82 using type = Relative;
83};
84
86template <bool Value_>
87struct MakeAbsolute<internal::AbsoluteImpl<Value_>> {
88 static_assert(!Value_, "The object is already absolute.");
89 using type = Absolute;
90};
91
92} // namespace wuzp
internal::AbsoluteImpl< true > Absolute
Definition Absolute.hpp:17
internal::AbsoluteImpl< false > Relative
Definition Absolute.hpp:18
Trait to select one type or another depending on a boolean. Note that both types must be defined even...
Definition helpers.hpp:51
The inverse: the matrix inverse of a matrix, like Eigen's MatrixBase::inverse(), and the reciprocal o...
Definition traits.hpp:188
The negation is performed elementwise.
Definition traits.hpp:101