Skip to content

Commit 4443993

Browse files
authored
Fix Revolve clipping (#1200)
fixed sign error
1 parent 2a4e9ba commit 4443993

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

include/manifold/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <chrono>
2121
#endif
2222

23-
#include "manifold/linalg.h"
23+
#include "linalg.h"
2424

2525
namespace manifold {
2626
/** @addtogroup Math

src/constructors.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "./csg_tree.h"
1616
#include "./impl.h"
1717
#include "./parallel.h"
18+
#include "manifold/manifold.h"
1819
#include "manifold/polygon.h"
1920

2021
namespace manifold {
@@ -315,7 +316,7 @@ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments,
315316
}
316317
const size_t next = i + 1 == poly.size() ? 0 : i + 1;
317318
if ((poly[next].x < 0) != (poly[i].x < 0)) {
318-
const double y = poly[next].y + poly[next].x *
319+
const double y = poly[next].y - poly[next].x *
319320
(poly[i].y - poly[next].y) /
320321
(poly[i].x - poly[next].x);
321322
polygons.back().push_back({0, y});
@@ -351,8 +352,8 @@ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments,
351352
const int nSlices = isFullRevolution ? nDivisions : nDivisions + 1;
352353

353354
for (const auto& poly : polygons) {
354-
std::size_t nPosVerts = 0;
355-
std::size_t nRevolveAxisVerts = 0;
355+
size_t nPosVerts = 0;
356+
size_t nRevolveAxisVerts = 0;
356357
for (auto& pt : poly) {
357358
if (pt.x > 0) {
358359
nPosVerts++;

test/manifold_test.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#ifdef MANIFOLD_CROSS_SECTION
2020
#include "manifold/cross_section.h"
2121
#endif
22-
#include "../src/tri_dist.h"
23-
#include "samples.h"
2422
#include "test.h"
2523

2624
namespace {
@@ -282,6 +280,16 @@ TEST(Manifold, Revolve3) {
282280
}
283281
#endif
284282

283+
TEST(Manifold, RevolveClip) {
284+
Polygons polys = {{{-5, -10}, {5, 0}, {-5, 10}}};
285+
Polygons clipped = {{{0, -5}, {5, 0}, {0, 5}}};
286+
Manifold first = Manifold::Revolve(polys, 48);
287+
Manifold second = Manifold::Revolve(clipped, 48);
288+
EXPECT_EQ(first.Genus(), second.Genus());
289+
EXPECT_EQ(first.Volume(), second.Volume());
290+
EXPECT_EQ(first.SurfaceArea(), second.SurfaceArea());
291+
}
292+
285293
TEST(Manifold, PartialRevolveOnYAxis) {
286294
Polygons polys = SquareHole(2.0);
287295
Polygons offsetPolys = SquareHole(10.0);

0 commit comments

Comments
 (0)