Skip to content

Commit 5402b47

Browse files
committed
wip interior product
Change-Id: I672378174643d5bbf580375b61bc9552ed0d62cf
1 parent 3c08e22 commit 5402b47

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

geometry/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ cc_library(
5959
"src/exterior_product.hpp",
6060
"src/geometric_product.hpp",
6161
"src/get.hpp",
62+
"src/interior_product.hpp",
6263
"src/multivector_for.hpp",
6364
"src/regressive_product.hpp",
6465
"src/sum.hpp",

geometry/geometry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "geometry/src/exterior_product.hpp"
99
#include "geometry/src/geometric_product.hpp"
1010
#include "geometry/src/get.hpp"
11+
#include "geometry/src/interior_product.hpp"
1112
#include "geometry/src/multivector_for.hpp"
1213
#include "geometry/src/regressive_product.hpp"
1314
#include "geometry/src/sum.hpp"

geometry/src/exterior_product.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ inline constexpr class
2020
class D1 = std::decay_t<typename T1::eval_type>,
2121
class D2 = std::decay_t<typename T2::eval_type>,
2222
class Algebra = common_algebra_type_t<D1, D2>,
23-
class L = detail::pending_dimensions_list_t<D1, D2>>
23+
class L = detail::pending_dimensions_list_t<D1, D2>,
24+
class R =
25+
typename tmp::convert_to_sequence_t<L, Algebra::template reified_blade>::type>
2426
constexpr auto
2527
operator()(expression_template::op<expression_template::multiplies, T1, T2>)
26-
const -> std::bool_constant<(
27-
tmp::convert_to_sequence_t<L, Algebra::template reified_blade>::type::
28-
grade < D1::grade + D2::grade)>
28+
const -> std::bool_constant<R::grade != D1::grade + D2::grade>
2929
{
3030
return {};
3131
}

geometry/src/interior_product.hpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
3+
#include "geometry/expression_template.hpp"
4+
#include "geometry/src/common_algebra_type.hpp"
5+
#include "geometry/src/detail/multivector_product.hpp"
6+
#include "geometry/src/detail/pending_dimensions_list.hpp"
7+
#include "geometry/type_metaprogramming.hpp"
8+
9+
#include <type_traits>
10+
11+
namespace geometry {
12+
namespace detail {
13+
14+
inline constexpr class
15+
{
16+
public:
17+
template <
18+
class T1,
19+
class T2,
20+
class D1 = std::decay_t<typename T1::eval_type>,
21+
class D2 = std::decay_t<typename T2::eval_type>,
22+
class Algebra = common_algebra_type_t<D1, D2>,
23+
class L = detail::pending_dimensions_list_t<D1, D2>,
24+
class R =
25+
typename tmp::convert_to_sequence_t<L, Algebra::template reified_blade>::type,
26+
int k = tmp::convert_to_sequence_t<
27+
L,
28+
Algebra::template reified_blade_coefficient>::value>
29+
constexpr auto
30+
operator()(expression_template::op<expression_template::multiplies, T1, T2>)
31+
const -> std::bool_constant<
32+
(R::grade !=
33+
std::max(D1::grade, D2::grade) - std::min(D1::grade, D2::grade)) or
34+
(k == 0)>
35+
{
36+
return {};
37+
}
38+
} non_grade_contracting{};
39+
40+
} // namespace detail
41+
42+
/// interior product
43+
///
44+
/// @{
45+
46+
inline constexpr auto interior_product = //
47+
detail::multivector_product_with( //
48+
detail::non_grade_contracting,
49+
[](auto algebra) {
50+
return typename decltype(algebra)::template blade<>{};
51+
});
52+
53+
template <class T1, class T2, class A = common_algebra_type_t<T1, T2>>
54+
[[nodiscard]]
55+
constexpr auto
56+
operator|(const T1& x, const T2& y)
57+
{
58+
return interior_product(x, y);
59+
}
60+
61+
/// @}
62+
63+
} // namespace geometry

test/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ cc_test(
7979
"@skytest",
8080
],
8181
)
82+
83+
cc_test(
84+
name = "algebra_interior_product_test",
85+
size = "small",
86+
srcs = ["algebra_interior_product_test.cpp"],
87+
deps = [
88+
":test_same",
89+
"//:geometry",
90+
"@skytest",
91+
],
92+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "geometry/geometry.hpp"
2+
#include "skytest/skytest.hpp"
3+
4+
#include "test/test_same.hpp"
5+
6+
#include <cstddef>
7+
#include <tuple>
8+
#include <utility>
9+
10+
auto main() -> int
11+
{
12+
using namespace ::skytest::literals;
13+
using ::geometry::get;
14+
using ::geometry::test::same;
15+
using ::skytest::eq;
16+
using ::skytest::expect;
17+
using ::skytest::ne;
18+
19+
"line orthogonal to point (2D)"_ctest = [] {
20+
using algebra = ::geometry::algebra<double, 2>;
21+
22+
// https://bivector.net/PROJECTIVE_GEOMETRIC_ALGEBRA.pdf
23+
// section 7.1
24+
25+
constexpr auto x_hat = algebra::e<2, 0>;
26+
constexpr auto y_hat = algebra::e<0, 1>;
27+
constexpr auto E0 = algebra::e<1, 2>;
28+
29+
const auto P = 0 * x_hat + 0 * y_hat + E0;
30+
31+
// a line of the form
32+
// a * x + b * y + c = 0
33+
// is represented as
34+
// a * e1 + b * e2 + c * e0 = 0
35+
36+
//using e0 = algebra::blade<0>;
37+
constexpr auto x = algebra::e<1>;
38+
constexpr auto y = algebra::e<2>;
39+
40+
return expect(eq(x, y | P) and
41+
eq(y, x | P));
42+
};
43+
44+
}

0 commit comments

Comments
 (0)