wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Toggle main menu visibility
Loading...
Searching...
No Matches
Absolute.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "wuzp/core/internal/AbsoluteImpl.hpp"
4
#include "
wuzp/core/traits.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
15
namespace
wuzp
{
16
17
using
Absolute
= internal::AbsoluteImpl<true>;
18
using
Relative
= internal::AbsoluteImpl<false>;
19
20
template
<
bool
ValueLhs_,
bool
ValueRhs_>
21
struct
Sum<internal::AbsoluteImpl<ValueLhs_>, internal::AbsoluteImpl<ValueRhs_>> {
22
static_assert
(!ValueLhs_ || !ValueRhs_,
"Two absolute objects cannot be summed."
);
23
using
type =
typename
IfThenElse<ValueLhs_ || ValueRhs_, Absolute, Relative>::type
;
24
};
25
26
template
<
bool
ValueLhs_,
bool
ValueRhs_>
27
struct
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
32
template
<
bool
Value_>
33
struct
Negation
<internal::AbsoluteImpl<Value_>> {
34
static_assert
(!Value_,
"An absolute object cannot be negated."
);
35
using
type =
Relative
;
36
};
37
39
template
<
bool
ValueLhs_,
bool
ValueRhs_>
40
struct
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
46
template
<
bool
ValueLhs_,
bool
ValueRhs_>
47
struct
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
52
template
<
bool
Value_,
typename
ExponentT_>
53
struct
Power
<internal::AbsoluteImpl<Value_>, ExponentT_> {
54
static_assert
(!Value_,
"An absolute object cannot be powered."
);
55
using
type =
Relative
;
56
};
57
59
template
<
bool
Value_>
60
struct
Inverse
<internal::AbsoluteImpl<Value_>> {
61
static_assert
(!Value_,
"An absolute object cannot be inverted."
);
62
using
type =
Relative
;
63
};
64
67
template
<
bool
Value_>
68
struct
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
73
template
<
bool
Value_>
74
struct
IsAbsolute
<internal::AbsoluteImpl<Value_>> {
75
static
constexpr
bool
value = Value_;
76
};
77
79
template
<
bool
Value_>
80
struct
MakeRelative
<internal::AbsoluteImpl<Value_>> {
81
static_assert
(Value_,
"The object is already relative."
);
82
using
type =
Relative
;
83
};
84
86
template
<
bool
Value_>
87
struct
MakeAbsolute
<internal::AbsoluteImpl<Value_>> {
88
static_assert
(!Value_,
"The object is already absolute."
);
89
using
type =
Absolute
;
90
};
91
92
}
// namespace wuzp
traits.hpp
wuzp
Definition
Absolute.hpp:15
wuzp::Absolute
internal::AbsoluteImpl< true > Absolute
Definition
Absolute.hpp:17
wuzp::Relative
internal::AbsoluteImpl< false > Relative
Definition
Absolute.hpp:18
wuzp::IfThenElse
Trait to select one type or another depending on a boolean. Note that both types must be defined even...
Definition
helpers.hpp:51
wuzp::Inverse
The inverse: the matrix inverse of a matrix, like Eigen's MatrixBase::inverse(), and the reciprocal o...
Definition
traits.hpp:188
wuzp::IsAbsolute
Definition
traits.hpp:268
wuzp::MakeAbsolute
Definition
traits.hpp:283
wuzp::MakeRelative
Definition
traits.hpp:273
wuzp::Negation
The negation is performed elementwise.
Definition
traits.hpp:101
wuzp::Norm
Definition
traits.hpp:172
wuzp::Power
Definition
traits.hpp:150
wuzp
include
wuzp
core
Absolute.hpp
Generated by
1.18.0