Skip to content

Commit

Permalink
define blade addition/subtraction assignment
Browse files Browse the repository at this point in the history
Change-Id: Ia8f87a7a3a4a0bac948a13ce2555ace45cde746e
  • Loading branch information
oliverlee committed Jan 12, 2024
1 parent e1c9127 commit 340b69a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions geometry/src/algebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ struct algebra
return multivector<blade, blade<Js...>>{x, y};
}
}
friend constexpr auto& operator+=(blade& x, blade y) { return x = x + y; }
/// @}

/// subtraction
Expand All @@ -236,6 +237,7 @@ struct algebra
{
return x + -y;
}
friend constexpr auto& operator-=(blade& x, blade y) { return x = x - y; }
/// @}

/// scalar multiplication
Expand Down
12 changes: 12 additions & 0 deletions test/algebra_blade_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ auto main() -> int
"blade subtraction"_ctest * param_ref<unit_blades> = //
[](auto ei) { return expect(eq(ei, 3 * ei - 2 * ei)); };

"blade addition assignment"_ctest * param_ref<unit_blades> = //
[](auto ei) {
auto x = ei;
return expect(eq(3 * ei, x += 2 * ei));
};

"blade subtraction assignment"_ctest * param_ref<unit_blades> = //
[](auto ei) {
auto x = ei;
return expect(eq(-ei, x -= 2 * ei));
};

"blade uses canonical dimensions"_ctest = [] {
return expect(
eq(-e<1, 0>, e<0, 1>) and //
Expand Down

0 comments on commit 340b69a

Please sign in to comment.