File indexing completed on 2025-01-18 09:10:45
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 Direction Negative() { return Direction{Value::Negative}; }
0031 static constexpr Direction Positive() { return Direction{Value::Positive}; }
0032
0033 static constexpr Direction Backward() { return Direction{Value::Negative}; }
0034 static constexpr Direction Forward() { return Direction{Value::Positive}; }
0035
0036 static constexpr Direction OppositeNormal() {
0037 return Direction{Value::Negative};
0038 }
0039 static constexpr Direction AlongNormal() {
0040 return Direction{Value::Positive};
0041 }
0042
0043
0044
0045
0046
0047
0048 static constexpr Direction fromScalar(double scalar) {
0049 assert(scalar != 0);
0050 return scalar >= 0 ? Positive() : Negative();
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060 static constexpr Direction fromScalarZeroAsPositive(double scalar) {
0061 return scalar >= 0 ? Positive() : Negative();
0062 }
0063
0064
0065
0066
0067
0068 static constexpr Direction fromIndex(std::size_t index) {
0069 return index == 0u ? Negative() : Positive();
0070 }
0071
0072
0073
0074
0075
0076 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 constexpr int sign() const { return static_cast<int>(m_value); }
0087
0088
0089
0090
0091 constexpr Direction invert() const {
0092 return *this == Positive() ? Negative() : Positive();
0093 }
0094
0095 std::string toString() const;
0096
0097 friend constexpr bool operator==(Direction lhs, Direction rhs) {
0098 return lhs.m_value == rhs.m_value;
0099 }
0100
0101 private:
0102 explicit constexpr Direction(Value value) : m_value(value) {}
0103
0104 Value m_value = Value::Positive;
0105 };
0106
0107 std::ostream& operator<<(std::ostream& os, Direction dir);
0108
0109
0110
0111 constexpr int operator*(Direction dir, int value) {
0112 return dir.sign() * value;
0113 }
0114
0115 constexpr float operator*(Direction dir, float value) {
0116 return dir.sign() * value;
0117 }
0118
0119 constexpr double operator*(Direction dir, double value) {
0120 return dir.sign() * value;
0121 }
0122
0123 inline Acts::Vector3 operator*(Direction dir, const Acts::Vector3& value) {
0124 return dir.sign() * value;
0125 }
0126
0127
0128
0129 constexpr int operator*(int value, Direction dir) {
0130 return value * dir.sign();
0131 }
0132
0133 constexpr float operator*(float value, Direction dir) {
0134 return value * dir.sign();
0135 }
0136
0137 constexpr double operator*(double value, Direction dir) {
0138 return value * dir.sign();
0139 }
0140
0141 inline Acts::Vector3 operator*(const Acts::Vector3& value, Direction dir) {
0142 return value * dir.sign();
0143 }
0144
0145
0146
0147 constexpr int operator*=(int& value, Direction dir) {
0148 value *= dir.sign();
0149 return value;
0150 }
0151
0152 constexpr float operator*=(float& value, Direction dir) {
0153 value *= dir.sign();
0154 return value;
0155 }
0156
0157 constexpr double operator*=(double& value, Direction dir) {
0158 value *= dir.sign();
0159 return value;
0160 }
0161
0162 inline Acts::Vector3& operator*=(Acts::Vector3& value, Direction dir) {
0163 value *= dir.sign();
0164 return value;
0165 }
0166
0167 }