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

InflatePath creates unwanted additional vertices #393

Closed
AngusJohnson opened this issue Feb 2, 2023 Discussed in #392 · 4 comments
Closed

InflatePath creates unwanted additional vertices #393

AngusJohnson opened this issue Feb 2, 2023 Discussed in #392 · 4 comments

Comments

@AngusJohnson
Copy link
Owner

Discussed in #392

Originally posted by ccoustet February 3, 2023
Hi everyone,
I stumbled on the following polygon, that when inflated, has new vertices that I cannot understand.

PathsD polyline, solution;
PointD coords[] = {
  {1427.13, 1415.78},
  {1423.51, 1416.30},
  {1419.52, 1416.89},
  {1402.45, 1419.34},
  {1403.26, 1429.07},
  {1403.63, 1433.62},
  {1421.66, 1430.96},
  {1422.90, 1430.86},
  {1423.08, 1430.76},
  {1423.88, 1438.85},
  {1429.36, 1438.44},
  {1429.45, 1438.95},
  {1441.12, 1437.52},
  {1439.33, 1414.04}
};
polyline.push_back(PathD(std::begin(coords), std::end(coords)));
std::cout << polyline[0].size() << std::endl;
std::cout << polyline[0];
std::cout << "----" << std::endl;
// offset polyline
solution = InflatePaths(polyline, -0.2, JoinType::Miter, EndType::Polygon, 2 , 6);
std::cout << solution[0].size() << std::endl;
std::cout << solution[0];
std::cout << "----" << std::endl;

14
1427.13,1415.78 , 1423.51,1416.3 , 1419.52,1416.89 , 1402.45,1419.34 , 1403.26,1429.07 , 1403.63,1433.62 , 1421.66,1430.96 , 1422.9,1430.86 , 1423.08,1430.76 , 1423.88,1438.85 , 1429.36,1438.44 , 1429.45,1438.95 , 1441.12,1437.52 , 1439.33,1414.04 
----
17
1439.15,1414.27 , 1427.16,1415.98 , 1427.16,1415.98 , 1423.54,1416.5 , 1419.55,1417.09 , 1419.55,1417.09 , 1402.66,1419.51 , 1403.46,1429.05 , 1403.46,1429.05 , 1403.81,1433.39 , 1421.64,1430.76 , 1422.84,1430.66 , 1423.25,1430.44 , 1424.06,1438.64 , 1429.53,1438.23 , 1429.61,1438.73 , 1440.91,1437.34 

With precision=2 the resulting polygon has 14 vertices, though.

AngusJohnson added a commit that referenced this issue Feb 6, 2023
Fixed InflatePaths to return unchanged paths when delta == 0 (#389)
Minor tweak to detecting "touching" solution polygons
Fixed minor bug in ClipperOffset (#392,#393)
Tidied up error handling in C++
Added error_code param to ScalePath function (C++)
Tweaks to C# CI testing (#388)
Major rewrite of RectClip function (Delphi only so far) (#383)
@AngusJohnson
Copy link
Owner Author

Hopefully fixed now 🤞🙏.

@zhyifei
Copy link

zhyifei commented Feb 6, 2023

PathD: {357.50,1.90} {441.50,260.30} {713.20,260.30} {493.40,420.10 } {577.40,678.40} {357.50,518.80} {137.70,678.40} {221.70,420.10 } {1.80,260.30} {273.50,260.30} {357.50,1.90}
Clipper.InflatePaths(paths, 4, JoinType.Round, EndType.Round); //will cause an infinite loop
Language: C#

@AngusJohnson
Copy link
Owner Author

I can't duplicate this problem. Are you using code from the latest commit?

      PathsD subject = new PathsD(), solution;
      subject.Add(Clipper.MakePath(new double [] {357.50,1.90, 441.50,260.30,
        713.20,260.30, 493.40,420.10, 577.40,678.40, 357.50,518.80,
        137.70,678.40, 221.70,420.10, 1.80,260.30, 273.50,260.30,
        357.50,1.90 }));
      solution = Clipper.InflatePaths(subject, 4, JoinType.Round, EndType.Round);

      SvgWriter svg = new();
      //SvgUtils.AddSubject(svg, subject, false);
      SvgUtils.AddSolution( svg, solution, false);
      SvgUtils.SaveToFile(svg, "../../../test.svg", FillRule.EvenOdd, 400, 400, 20);
      ClipperFileIO.OpenFileWithDefaultApp("../../../test.svg");

test

@zhyifei
Copy link

zhyifei commented Feb 7, 2023

Thanks, I'll try it with the latest code

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