Skip to content

Union with PolyPaths64 treats 45° collinear lines differently from 0° #1008

@sethhillbrand

Description

@sethhillbrand

Let's say that we start with the following two polygons:

Image

Both are single-outline polygons. The one on the left has collinear lines at 0° on the bottom of the structure. The one on the right has collinear lines at 45° on the bottom right of the structure.

We run the following code:

#include <clipper2/clipper.h>
#include <Utils/clipper.svg.h>
#include <Utils/clipper.svg.utils.h>

using namespace Clipper2Lib;

int main(int argc, char * argv[])
{
  Paths64 subject, solution;
  SvgWriter svg;
  Clipper64 c;
  PolyTree64 pt_solution;

  Clipper64 c2;
  Paths64 solution2;
  PolyTree64 pt_solution2;
  SvgWriter svg2;

  subject.push_back(MakePath({7600000, 9000000, 6600000, 9000000, 6600000, 8750000, 7000000, 8750000, 7000000, 9000000, 7250000, 9000000, 7250000, 8500000, 7000000, 8500000, 7000000, 8750000, 6600000, 8750000, 6600000, 8000000, 7600000, 8000000, 7600000, 9000000}));
  c.AddSubject(subject);
  c.Execute(ClipType::Union, FillRule::NonZero, solution);
  c.Execute(ClipType::Union, FillRule::NonZero, pt_solution);

  Paths64 subject2;
  subject2.push_back(MakePath({9912310, 8325057, 9288816, 8948550, 8000000, 8567586, 9428364, 8547698, 9585009, 8652365, 9613140, 8624234, 9471719, 8482813, 9428364, 8547698, 8000000, 8567586, 9912310, 8325057}));
  c2.AddSubject(subject2);
  c2.Execute(ClipType::Union, FillRule::NonZero, solution2);
  c2.Execute(ClipType::Union, FillRule::NonZero, pt_solution2);

  std::cout << pt_solution << std::endl;
  std::cout << pt_solution2 << std::endl;

  SvgAddSolution( svg, solution, FillRule::NonZero, false );
  SvgSaveToFile( svg, "good_union.svg", 8000, 8000 );

  SvgAddSolution( svg2, solution2, FillRule::NonZero, false );
  SvgSaveToFile( svg2, "bad_union2.svg", 8000, 8000 );

}

The expected output here is that the PolyTree64 will say "Polytree with 1 polygon". Instead, we get:

Polytree with 1 polygon.


Polytree with 2 polygons.

Only the one on the left correctly merges the interior and exterior. The output looks like this:

Image

The one on the right has output with two overlapping polygons:

Image

I think that both polygons should behave the same way. Ideally, I think that the one on the left is the correct output but I'd love to have them synchronized either way

edit: I should have noted that this is testing using current master f1d4916

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions