Skip to content
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

Offset produces incorrect result #715

Closed
olologin opened this issue Nov 18, 2023 · 3 comments
Closed

Offset produces incorrect result #715

olologin opened this issue Nov 18, 2023 · 3 comments

Comments

@olologin
Copy link

olologin commented Nov 18, 2023

Hi, I was trying to update Clipper2 version from revision f9a40f0 to the current head and I see a regression in closed curve offset.
Somehow it misses this small circle in the new result, while it was producing correct result at the revision f9a40f0

Testcase (Please add this to your testcases if you fix this problem):
Two curves in the input, it is one body with hole. With negative offset outer body should become smaller, its hole should become bigger. The issue is that its hole completely disappears now.

TEST(Clipper2Tests, TestOffsets7)
{
    Paths64 subjects = {
        {{508685336, -435806096},
         {509492982, -434729201},
         {509615525, -434003092},
         {509615525, 493372891},
         {509206033, 494655198},
         {508129138, 495462844},
         {507403029, 495585387},
         {-545800889, 495585387},
         {-547083196, 495175895},
         {-547890842, 494099000},
         {-548013385, 493372891},
         {-548013385, -434003092},
         {-547603893, -435285399},
         {-546526998, -436093045},
         {-545800889, -436215588},
         {507403029, -436215588}},
        {{106954765, -62914568},
         {106795129, -63717113},
         {106340524, -64397478},
         {105660159, -64852084},
         {104857613, -65011720},
         {104055068, -64852084},
         {103374703, -64397478},
         {102920097, -63717113},
         {102760461, -62914568},
         {102920097, -62112022},
         {103374703, -61431657},
         {104055068, -60977052},
         {104857613, -60817416},
         {105660159, -60977052},
         {106340524, -61431657},
         {106795129, -62112022}} };

    Clipper2Lib::ClipperOffset offseter(2, 104857.61318750000);
    Clipper2Lib::Paths64 tmpSubject;

    offseter.AddPaths(subjects, Clipper2Lib::JoinType::Round, Clipper2Lib::EndType::Polygon);
    Clipper2Lib::Paths64 paths;
    offseter.Execute(-2212495.6382562499, paths);

    EXPECT_EQ(paths.size(), 2); // Only one curve is in the output at the current trunk, it is wrong.
}

image

@AngusJohnson
Copy link
Owner

AngusJohnson commented Nov 18, 2023

Replace -

// when shrinking, then make sure the path can shrink that far (#593)
if (group_delta_ < 0 &&
std::min(path_rect.Width(), path_rect.Height()) < -group_delta_ * 2)
continue;

with -

// when shrinking, make sure the path can shrink that far (#593)
// but also make sure this isn't a hole which will be expanding (#715)
if ((group_delta_ < 0) &&
  (std::min(path_rect.Width(), path_rect.Height()) < -group_delta_ * 2) &&
    ((Area(path_in) < 0) == group.is_reversed))
      continue;

@olologin
Copy link
Author

@AngusJohnson yes, that helps. Thank you!

@AngusJohnson
Copy link
Owner

It's still not quite right (ie it still needs tweaking), but this shouldn't be problematic as it is now.

AngusJohnson added a commit that referenced this issue Nov 26, 2023
  Changes since ver 1.2.3 include:
  1. Important: Offsetting open path behaviour has changed.
     The delta now behaves as it did in Clipper1 (See Issue #707)
  2. Important: Data structures of exported values in clipper.export.h have changed.
  3. Minor bugfixes to PolyTree nesting (#679, #687)
  4. Numerous minor bugfixes to polygon offsetting (#703, #715, #724)
  5. Fixed an obscure bug in polygon clipping caused by horizontal spikes (#720)
  6. Significantly improved documentation.
jiajuncccc added a commit to jiajuncccc/Clipper2 that referenced this issue Dec 15, 2023
* remotes/origin/main:
  Minor code tidy
  Added CLIPPER2_HI_PRECISION option in CMakeLists.txt
  Additional minor tweaks to cpp/benchmark tests
  Make googletest not be a git submodule, and instead clone it separately in the CI script (AngusJohnson#745)
  fix compiler warning of -Wunused-but-set-parameter with -fno-exceptions (AngusJohnson#744)
  Additional tweaks to GetIntersectPtBenchmark.cpp
  Additional GetIntersectPtBenchmark tweaks
  Fixed incorrect code comment
  Added new GetIntersectPoint benchmark test Updated other benchmark tests.
  Code formatting only (removed trailing spaces)
  Fixed minor typecasting issues (AngusJohnson#727)
  More tweaks to PointInPolygon benchmarking.
  Allow using external gtest with GTest:: qualified names (AngusJohnson#737)
  Fixed a significant (though uncommon) bug in polygon clipping (AngusJohnson#736) Fixed bugs in PointInPolygon benchmark testing.
  Minor tweaks to PointInPolygon benchmark testing.
  Fixed a minor syntax error tripping some C++ compilers
  Version 1.3.0 1. Fixed a significant offsetting bug introduced in previous update (AngusJohnson#733) 2. Fixed a C++ compile error when 32bit compiling (AngusJohnson#727) 3. Minor tweak to CMakeLists.txt (C++) (AngusJohnson#728) 4. Will now offset 'flat' polygons (Disc.AngusJohnson#725) 5. Reminder: recent change in open path offsetting behaviour (AngusJohnson#707) 6. Reminder: recent changes to clipper.export.h data structures.
  Fixed a typo and tweaked documentation
  Version 1.2.4   Changes since ver 1.2.3 include:   1. Important: Offsetting open path behaviour has changed.      The delta now behaves as it did in Clipper1 (See Issue AngusJohnson#707)   2. Important: Data structures of exported values in clipper.export.h have changed.   3. Minor bugfixes to PolyTree nesting (AngusJohnson#679, AngusJohnson#687)   4. Numerous minor bugfixes to polygon offsetting (AngusJohnson#703, AngusJohnson#715, AngusJohnson#724)   5. Fixed an obscure bug in polygon clipping caused by horizontal spikes (AngusJohnson#720)   6. Significantly improved documentation.
  Additional minor bugfix to ClipperOffset (AngusJohnson#724 & Disc.AngusJohnson#726)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants