-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I86dc9c296ef465eebc42b91a1c9a437086b9a5cd
- Loading branch information
Showing
7 changed files
with
160 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
#pragma once | ||
|
||
namespace geometry { | ||
|
||
constexpr auto dummy_function() | ||
{ | ||
return 0; | ||
} | ||
|
||
} // namespace geometry | ||
#include "geometry/src/algebra.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
|
||
namespace geometry { | ||
|
||
template <class S, std::size_t N> | ||
struct algebra | ||
{ | ||
using scalar_type = S; | ||
|
||
template <std::size_t... Is> | ||
struct blade | ||
{ | ||
static_assert(sizeof...(Is) <= N + 1, "number of `Is` exceeds rank"); | ||
static_assert(((Is <= N) and ...), "`Is` exceeds rank"); | ||
// TODO check Is.. values are unique | ||
|
||
using algebra_type = algebra; | ||
using scalar_type = typename algebra::scalar_type; | ||
|
||
static constexpr auto grade = sizeof...(Is); | ||
|
||
scalar_type coefficient{}; | ||
|
||
blade() = default; | ||
|
||
template <std::size_t M = grade, std::enable_if_t<M == 0, bool> = true> | ||
constexpr blade(scalar_type a) : coefficient{a} | ||
{} | ||
template <std::size_t M = grade, std::enable_if_t<M != 0, bool> = true> | ||
constexpr explicit blade(scalar_type a) : coefficient{a} | ||
{} | ||
|
||
[[nodiscard]] | ||
friend constexpr auto | ||
operator==(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient == y.coefficient; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator!=(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient != y.coefficient; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator<(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient < y.coefficient; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator>(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient > y.coefficient; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator<=(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient <= y.coefficient; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator>=(blade x, blade y) noexcept -> bool | ||
{ | ||
return x.coefficient >= y.coefficient; | ||
} | ||
|
||
[[nodiscard]] | ||
friend constexpr auto | ||
operator-(blade x) -> blade | ||
{ | ||
return blade{-x.coefficient}; | ||
} | ||
|
||
[[nodiscard]] | ||
friend constexpr auto | ||
operator*(scalar_type a, blade x) -> blade | ||
{ | ||
return blade{a * x.coefficient}; | ||
} | ||
[[nodiscard]] | ||
friend constexpr auto | ||
operator*(blade x, scalar_type a) -> blade | ||
{ | ||
return a * x; | ||
} | ||
}; | ||
|
||
template <std::size_t... Is> | ||
static constexpr auto e = blade<Is...>{scalar_type{1}}; | ||
}; | ||
|
||
} // namespace geometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "geometry/geometry.hpp" | ||
#include "skytest/skytest.hpp" | ||
|
||
#include <cstddef> | ||
#include <tuple> | ||
#include <type_traits> | ||
|
||
template <std::size_t... Is> | ||
constexpr auto e = ::geometry::algebra<double, 2>::e<Is...>; | ||
|
||
constexpr auto unit_blades = std::tuple{ | ||
::geometry::algebra<double, 2>::e<>, | ||
::geometry::algebra<double, 2>::e<0>, | ||
::geometry::algebra<double, 2>::e<1>, | ||
::geometry::algebra<double, 2>::e<2>, | ||
::geometry::algebra<double, 2>::e<0, 1>, | ||
::geometry::algebra<double, 2>::e<0, 2>, | ||
::geometry::algebra<double, 2>::e<1, 2>, | ||
::geometry::algebra<double, 2>::e<0, 1, 2>}; | ||
|
||
auto main() -> int | ||
{ | ||
using namespace ::skytest::literals; | ||
using ::skytest::eq; | ||
using ::skytest::expect; | ||
using ::skytest::param_ref; | ||
|
||
"0-blade implicitly constructible"_ctest = [] { | ||
return expect( | ||
eq(e<>, e<>) and // | ||
eq(0, 0 * e<>) and // | ||
eq(1, 1 * e<>) and // | ||
eq(-1, -e<>)); | ||
}; | ||
|
||
"grade 1+ blade explicitly constructible"_ctest * param_ref<unit_blades> = // | ||
[](auto ei) { | ||
return expect( | ||
ei.grade == 0 or // | ||
not std::is_convertible_v<double, decltype(ei)>); | ||
}; | ||
|
||
"grade 0+ blades comparable"_ctest * param_ref<unit_blades> = // | ||
[](auto ei) { | ||
using namespace ::skytest; | ||
|
||
return expect( | ||
eq(ei, ei) and // | ||
ne(0 * ei, ei) and // | ||
lt(0 * ei, ei) and // | ||
le(0 * ei, ei) and // | ||
gt(ei, 0 * ei) and // | ||
ge(ei, 0 * ei)); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters