8000 Fix Revolve clipping by elalish · Pull Request #1200 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Revolve clipping #1200

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 1 commit into from
Mar 27, 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
2 changes: 1 addition & 1 deletion include/manifold/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <chrono>
#endif

#include "manifold/linalg.h"
#include "linalg.h"

namespace manifold {
/** @addtogroup Math
Expand Down
7 changes: 4 additions & 3 deletions src/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "./csg_tree.h"
#include "./impl.h"
#include "./parallel.h"
#include "manifold/manifold.h"
#include "manifold/polygon.h"

namespace manifold {
Expand Down Expand Up @@ -315,7 +316,7 @@ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments,
}
const size_t next = i + 1 == poly.size() ? 0 : i + 1;
if ((poly[next].x < 0) != (poly[i].x < 0)) {
const double y = poly[next].y + poly[next].x *
const double y = poly[next].y - poly[next].x *
(poly[i].y - poly[next].y) /
(poly[i].x - poly[next].x);
polygons.back().push_back({0, y});
Expand Down Expand Up @@ -351,8 +352,8 @@ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments,
const int nSlices = isFullRevolution ? nDivisions : nDivisions + 1;

for (const auto& poly : polygons) {
std::size_t nPosVerts = 0;
std::size_t nRevolveAxisVerts = 0;
size_t nPosVerts = 0;
size_t nRevolveAxisVerts = 0;
for (auto& pt : poly) {
if (pt.x > 0) {
nPosVerts++;
Expand Down
12 changes: 10 additions & 2 deletions test/manifold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "../src/tri_dist.h"
#include "samples.h"
#include "test.h"

namespace {
Expand Down Expand Up @@ -282,6 +280,16 @@ TEST(Manifold, Revolve3) {
}
#endif

TEST(Manifold, RevolveClip) {
Polygons polys = {{{-5, -10}, {5, 0}, {-5, 10}}};
Polygons clipped = {{{0, -5}, {5, 0}, {0, 5}}};
Manifold first = Manifold::Revolve(polys, 48);
Manifold second = Manifold::Revolve(clipped, 48);
EXPECT_EQ(first.Genus(), second.Genus());
EXPECT_EQ(first.Volume(), second.Volume());
EXPECT_EQ(first.SurfaceArea(), second.SurfaceArea());
}

TEST(Manifold, PartialRevolveOnYAxis) {
Polygons polys = SquareHole(2.0);
Polygons offsetPolys = SquareHole(10.0);
Expand Down
0