Skip to content

Commit

Permalink
feat(sourcepp): add method on vector for negation of magnitude
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Aug 3, 2024
1 parent 13588ff commit 3771ec2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/sourcepp/math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct Vec {
return this->operator[](index % S);
}

[[nodiscard]] constexpr Vec operator+() const {
return *this;
}

template<uint8_t SO, Arithmetic PO>
[[nodiscard]] constexpr Vec operator+(const Vec<SO, PO>& other) const {
auto out = *this;
Expand All @@ -62,6 +66,14 @@ struct Vec {
}
}

[[nodiscard]] constexpr Vec operator-() const {
auto out = *this;
for (uint8_t i = 0; i < S; i++) {
out[i] *= -1;
}
return out;
}

template<uint8_t SO, Arithmetic PO>
[[nodiscard]] constexpr Vec operator-(const Vec<SO, PO>& other) const {
auto out = *this;
Expand Down

0 comments on commit 3771ec2

Please sign in to comment.