Menu

ClipperLib2 : offsetting difference compared to ClipperLib1

2022-02-26
2022-02-27
  • Phil Stopford

    Phil Stopford - 2022-02-26

    I tried to send this through with an attachment, but it never made it to the discussion forum. I'm seeing a major difference in offsetting between Clipper 1 and Clipper 2.

    Comparison tests for Clipper 1 and Clipper 2
    Clipper1 Test1
    Out count: 2
    Clipper2 Test1
    Out count: 4

    I expected 2.

    For Clipper1Test:

    using ClipperLib1;
    
    namespace ClipperLib1Test;
    
    using Path = List<IntPoint>;
    using Paths = List<List<IntPoint>>;
    
    public static class Clipper1Test
    {
    const double keyhole_sizing = 500;
    public static void test1()
    {
    Console.WriteLine("Clipper1 Test1");
    Path outer = new()
    {
    new IntPoint(-200000, -200000),
    new IntPoint(200000, -200000),
    new IntPoint(200000, 200000),
    new IntPoint(-200000, 200000),
    new IntPoint(-200000, -200000)
    };
    
    Path inner1 = new()
    {
    new IntPoint(-100000, -100000),
    new IntPoint(-100000, 100000),
    new IntPoint(100000, 100000),
    new IntPoint(100000, -100000),
    new IntPoint(-100000, -100000)
    };
    Paths kHSource = new()
    {
    outer,
    inner1
    };
    
    ClipperOffset co = new();
    co.AddPaths(kHSource, JoinType.jtMiter, EndType.etClosedPolygon);
    Paths out_ = new ();
    co.Execute(ref out_, keyhole_sizing);
    
    Console.WriteLine("Out count: " + out_.Count);
    
    }
    }
    

    and Clipper2Test:

    using ClipperLib2;
    
    namespace ClipperLib2Test;
    
    using Path = List<Point64>;
    using Paths = List<List<Point64>>;
    
    public static class Clipper2Test
    {
    const double keyhole_sizing = 500;
    public static void test1()
    {
    Console.WriteLine("Clipper2 Test1");
    Path outer = new()
    {
    new Point64(-200000, -200000),
    new Point64(200000, -200000),
    new Point64(200000, 200000),
    new Point64(-200000, 200000),
    new Point64(-200000, -200000)
    };
    
    Path inner1 = new()
    {
    new Point64(-100000, -100000),
    new Point64(-100000, 100000),
    new Point64(100000, 100000),
    new Point64(100000, -100000),
    new Point64(-100000, -100000)
    };
    
    Paths kHSource = new()
    {
    outer,
    inner1
    };
    
    ClipperOffset co = new();
    co.AddPaths(kHSource, JoinType.Miter, EndType.Closed);
    Paths out_ = ClipperFunc.PathsFromPathsD(co.Execute(keyhole_sizing));
    
    Console.WriteLine("Out count: " + out_.Count);
    
    }
    }
    
     

    Last edit: Phil Stopford 2022-02-26
  • Angus Johnson

    Angus Johnson - 2022-02-27

    Hi again Phil.
    The answer would've been more obvious if your keyhole_sizing variable had been 50000.
    Anyhow, EndType.Closed (which is about to be renamed EndType.Joined as it currently is in the Delphi code) corresponds to EndType.etClosedLine in Clipper1. This is very different to EndType.Polygon that corresponds to EndType.etClosedPolygon in Clipper1.

    You've most likely just been confused by another name change, but to clarify for others (in the absense of any Clipper2 documentation) ...
    offsetting polygons is unidimensional in that positive offsets extend away from every edge's left side. On the other hand, offsetting open paths (polylines) is bidimensional in that it offsets away from both sides of edges.

     

    Last edit: Angus Johnson 2022-02-27
MongoDB Logo MongoDB