8000 Fix Cross Section Mirror and add Test by michael-j-faulkner · Pull Request #1206 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Cross Section Mirror and add Test #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cross_section/cross_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ CrossSection CrossSection::Scale(const vec2 scale) const {
}

/**
* Mirror this CrossSection over the arbitrary axis described by the unit form
* of the given vector. If the length of the vector is zero, an empty
* CrossSection is returned. This operation can be chained. Transforms are
* Mirror this CrossSection over the arbitrary axis whose normal is described by
* the unit form of the given vector. If the length of the vector is zero, an
* empty CrossSection is returned. This operation can be chained. Transforms are
* combined and applied lazily.
*
* @param ax the axis to be mirrored over
Expand All @@ -530,7 +530,7 @@ CrossSection CrossSection::Mirror(const vec2 ax) const {
if (la::length(ax) == 0.) {
return CrossSection();
}
auto n = la::normalize(la::abs(ax));
auto n = la::normalize(ax);
auto m = mat2x3(mat2(la::identity) - 2.0 * la::outerprod(n, n), vec2(0.0));
return Transform(m);
}
Expand Down
20 changes: 20 additions & 0 deletions test/cross_section_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ TEST(CrossSection, MirrorUnion) {
EXPECT_TRUE(a.Mirror(vec2(0.0)).IsEmpty());
}

TEST(CrossSection, MirrorCheckAxis) {
auto tri = CrossSection({{0., 0.}, {5., 5.}, {0., 10.}});

auto a = tri.Mirror({1., 1.}).Bounds();
auto a_expected = CrossSection({{0., 0.}, {-10., 0.}, {-5., -5.}}).Bounds();

EXPECT_NEAR(a.min.x, a_expected.min.x, 0.001);
EXPECT_NEAR(a.min.y, a_expected.min.y, 0.001);
EXPECT_NEAR(a.max.x, a_expected.max.x, 0.001);
EXPECT_NEAR(a.max.y, a_expected.max.y, 0.001);

auto b = tri.Mirror({-1., 1.}).Bounds();
auto b_expected = CrossSection({{0., 0.}, {10., 0.}, {5., 5.}}).Bounds();

EXPECT_NEAR(b.min.x, b_expected.min.x, 0.001);
EXPECT_NEAR(b.min.y, b_expected.min.y, 0.001);
EXPECT_NEAR(b.max.x, b_expected.max.x, 0.001);
EXPECT_NEAR(b.max.y, b_expected.max.y, 0.001);
}

TEST(CrossSection, RoundOffset) {
auto a = CrossSection::Square({20., 20.}, true);
int segments = 20;
Expand Down
Loading
0