Skip to content

Commit

Permalink
define blade addition and subtraction
Browse files Browse the repository at this point in the history
Change-Id: If09659eab51b67a15e0c2ccac795ef9c3aea9074
  • Loading branch information
oliverlee committed Jan 12, 2024
1 parent 5499ef0 commit b94454f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions geometry/src/algebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ struct algebra
return blade{-x.coefficient};
}

/// addition
///
[[nodiscard]]
friend constexpr auto
operator+(blade x, blade y) -> blade
{
return blade{x.coefficient + y.coefficient};
}

/// subtraction
///
[[nodiscard]]
friend constexpr auto
operator-(blade x, blade y) -> blade
{
return blade{x.coefficient - y.coefficient};
}

/// scalar multiplication
///
/// @{
Expand Down
6 changes: 6 additions & 0 deletions test/algebra_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ auto main() -> int
ge(ei, 0 * ei));
};

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

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

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

0 comments on commit b94454f

Please sign in to comment.