Skip to content

Commit

Permalink
define multivector negation
Browse files Browse the repository at this point in the history
Change-Id: Ia277a4e73b42baac8295cd1dfc74061a6a150b97
  • Loading branch information
oliverlee committed Jan 12, 2024
1 parent 8f806d6 commit e1c9127
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion geometry/src/algebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct algebra

/// construct a multivector from blades
///
constexpr multivector(Bs... bs) : Bs{bs}... {}
constexpr explicit multivector(Bs... bs) : Bs{bs}... {}

/// equality comparison
///
Expand All @@ -302,6 +302,15 @@ struct algebra
return not(x == y);
}
/// @}

/// unary negation
///
[[nodiscard]]
friend constexpr auto
operator-(const multivector& x) -> multivector
{
return multivector{-static_cast<Bs>(x)...};
}
};
};

Expand Down
7 changes: 7 additions & 0 deletions test/algebra_multivector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ auto main() -> int
eq(multivector(2 * e<0>, 3 * e<1>), 3 * e<1> + 2 * e<0>) and
eq(multivector(-2 * e<0>, 3 * e<1>), 3 * e<1> - 2 * e<0>));
};

"multivector negation"_ctest = //
[] {
return expect(
eq(e<0> + e<1>, -(-e<0> - e<1>)) and
eq(e<0, 1> + e<1, 2>, -(-e<0, 1> - e<1, 2>)));
};
}

0 comments on commit e1c9127

Please sign in to comment.