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

Incorrect empty offset result #703

Closed
LarsSkiba opened this issue Oct 31, 2023 · 2 comments
Closed

Incorrect empty offset result #703

LarsSkiba opened this issue Oct 31, 2023 · 2 comments

Comments

@LarsSkiba
Copy link
Contributor

LarsSkiba commented Oct 31, 2023

Hello,

we have encountered a problem with the ClipperOffset. This example provides a minimized input to reproduce the issue. The output is empty, even there is a CCW contour clearly greater then the offset.

This input is the result of a previous Simplify call using the same scaling. Another internal algorithm marks one of the contours as incorrect oriented given the nesting.
It is hard to judge whether this is correct or not, since they are such tiny artifacts and a visualization with floats is not conclusive. Playing around with different input scaling, we found that the problem depends a lot on the scaling value.

Nevertheless in my opinion the output should never be empty independent of the orientation of the tiny contour.

The 2nd contour is not needed to reproduce the example, but is maybe interesting to further evaluate, ifthe output of the Simplify is correct or not.

#include "clipper2/clipper.h"
int main()
{
	const double offset = -1e-3;
	const double scaling = 16777216;
	const double miterLimit = 1e4;
	const auto joinType = Clipper2Lib::JoinType::Miter;
	const auto endType = Clipper2Lib::EndType::Polygon;

	Clipper2Lib::ClipperOffset offsetter(miterLimit);
	Clipper2Lib::Paths64 paths(
		{Clipper2Lib::Path64(
			 {Clipper2Lib::Point64(-144099049, 612029194),
			  Clipper2Lib::Point64(-143880659, 612022343),
			  Clipper2Lib::Point64(-143476543, 612009666),
			  Clipper2Lib::Point64(-143399347, 612007244)}),
		 Clipper2Lib::Path64(
			 {Clipper2Lib::Point64(-143476543, 612009666),
			  Clipper2Lib::Point64(-143669378, 612015715),
			  Clipper2Lib::Point64(-143384594, 612006781)}),
		 Clipper2Lib::Path64(
			 {Clipper2Lib::Point64(-303982567, -352887774),
			  Clipper2Lib::Point64(450248930, -352887774),
			  Clipper2Lib::Point64(450248930, 609421831),
			  Clipper2Lib::Point64(-303982567, 609421831),
			  Clipper2Lib::Point64(-303982567, -352887774)})});

	offsetter.AddPaths(paths, joinType, endType);

	Clipper2Lib::Paths64 resultPaths;
	offsetter.Execute(offset * scaling, resultPaths);
}

Would be great if you could have a look into it.
Thanks, Lars

@LarsSkiba LarsSkiba changed the title Incorrect empty result of offset Incorrect empty offset result Oct 31, 2023
@AngusJohnson
Copy link
Owner

Hi Lars.
Thanks for the feedback.
I can see, and am now addressing this and a number of other problems I've found in ClipperOffset.
Stay tuned 😁.

@AngusJohnson
Copy link
Owner

Hopefully fixed 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