Warning, file /include/Acts/Definitions/Direction.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012
0013 #include <cassert>
0014 #include <cstddef>
0015 #include <iosfwd>
0016 #include <string>
0017
0018 namespace Acts {
0019
0020
0021
0022 class Direction final {
0023 private:
0024 enum class Value : int {
0025 Negative = -1,
0026 Positive = 1,
0027 };
0028
0029 public:
0030 static constexpr auto Negative = Value::Negative;
0031 static constexpr auto Positive = Value::Positive;
0032
0033 static constexpr auto Backward = Value::Negative;
0034 static constexpr auto Forward = Value::Positive;
0035
0036 static constexpr auto OppositeNormal = Value::Negative;
0037 static constexpr auto AlongNormal = Value::Positive;
0038
0039
0040
0041
0042
0043
0044 static inline constexpr Direction fromScalar(ActsScalar scalar) {
0045 assert(scalar != 0);
0046 return scalar >= 0 ? Value::Positive : Value::Negative;
0047 }
0048
0049
0050
0051
0052
0053
0054
0055
0056 static inline constexpr Direction fromScalarZeroAsPositive(
0057 ActsScalar scalar) {
0058 return scalar >= 0 ? Value::Positive : Value::Negative;
0059 }
0060
0061
0062
0063
0064
0065 static inline constexpr Direction fromIndex(std::size_t index) {
0066 if (index == 0u) {
0067 return Value::Negative;
0068 }
0069 return Value::Positive;
0070 }
0071
0072
0073
0074
0075
0076 inline constexpr std::size_t index() const {
0077 if (m_value == Value::Negative) {
0078 return 0u;
0079 }
0080 return 1u;
0081 }
0082
0083
0084
0085
0086 inline constexpr int sign() const { return static_cast<int>(m_value); }
0087
0088
0089
0090
0091 inline constexpr Direction invert() const {
0092 return (m_value == Value::Positive) ? Value::Negative : Value::Positive;
0093 }
0094
0095 std::string toString() const;
0096
0097 inline constexpr Direction() = default;
0098 inline constexpr Direction(Value value) : m_value(value) {}
0099
0100 inline constexpr bool operator==(Direction other) const {
0101 return m_value == other.m_value;
0102 }
0103
0104 inline constexpr bool operator!=(Direction other) const {
0105 return m_value != other.m_value;
0106 }
0107
0108 private:
0109 Value m_value = Value::Positive;
0110 };
0111
0112 std::ostream& operator<<(std::ostream& os, Direction dir);
0113
0114
0115
0116 inline constexpr int operator*(Direction dir, int value) {
0117 return dir.sign() * value;
0118 }
0119
0120 inline constexpr float operator*(Direction dir, float value) {
0121 return dir.sign() * value;
0122 }
0123
0124 inline constexpr double operator*(Direction dir, double value) {
0125 return dir.sign() * value;
0126 }
0127
0128 inline Acts::Vector3 operator*(Direction dir, const Acts::Vector3& value) {
0129 return dir.sign() * value;
0130 }
0131
0132
0133
0134 inline constexpr int operator*(int value, Direction dir) {
0135 return value * dir.sign();
0136 }
0137
0138 inline constexpr float operator*(float value, Direction dir) {
0139 return value * dir.sign();
0140 }
0141
0142 inline constexpr double operator*(double value, Direction dir) {
0143 return value * dir.sign();
0144 }
0145
0146 inline Acts::Vector3 operator*(const Acts::Vector3& value, Direction dir) {
0147 return value * dir.sign();
0148 }
0149
0150
0151
0152 inline constexpr int operator*=(int& value, Direction dir) {
0153 value *= dir.sign();
0154 return value;
0155 }
0156
0157 inline constexpr float operator*=(float& value, Direction dir) {
0158 value *= dir.sign();
0159 return value;
0160 }
0161
0162 inline constexpr double operator*=(double& value, Direction dir) {
0163 value *= dir.sign();
0164 return value;
0165 }
0166
0167 inline Acts::Vector3& operator*=(Acts::Vector3& value, Direction dir) {
0168 value *= dir.sign();
0169 return value;
0170 }
0171
0172 }