Menu

#12 Union of polygons with colinear edges (2)

1.0
closed
BUG (2)
2017-09-03
2016-06-20
Anonymous
No

Hi Timo,

Thank you for your response at the ticket 11. I tried to continue there the discussion without succeding so I'm opening a new ticket.

I tried the new release you sent me and I noticed that you solved the problem I reported you. However, a new problem that did not occoured before your fix, it occours now.

Consider this code:

test = [[{"X":393750,"Y":1134375},{"X":403125,"Y":1134375},{"X":403125,"Y":1143750},{"X":393750,"Y":1143750}],[{"X":393750,"Y":1143750},{"X":412500,"Y":1143750},{"X":412500,"Y":1162500},{"X":393750,"Y":1162500}],[{"X":375000,"Y":1143750},{"X":393750,"Y":1143750},{"X":393750,"Y":1162500},{"X":375000,"Y":1162500}],[{"X":375000,"Y":1162500},{"X":412500,"Y":1162500},{"X":412500,"Y":1200000},{"X":375000,"Y":1200000}],[{"X":412500,"Y":1162500},{"X":450000,"Y":1162500},{"X":450000,"Y":1200000},{"X":412500,"Y":1200000}],[{"X":412500,"Y":1125000},{"X":450000,"Y":1125000},{"X":450000,"Y":1162500},{"X":412500,"Y":1162500}],[{"X":412500,"Y":1087500},{"X":450000,"Y":1087500},{"X":450000,"Y":1125000},{"X":412500,"Y":1125000}],[{"X":375000,"Y":1087500},{"X":412500,"Y":1087500},{"X":412500,"Y":1125000},{"X":375000,"Y":1125000}],[{"X":375000,"Y":1050000},{"X":412500,"Y":1050000},{"X":412500,"Y":1087500},{"X":375000,"Y":1087500}],[{"X":412500,"Y":1050000},{"X":431250,"Y":1050000},{"X":431250,"Y":1068750},{"X":412500,"Y":1068750}]]

cpr = new ClipperLib.Clipper()
paths = new ClipperLib.Paths()
clipper_union = new ClipperLib.Paths()

cpr.AddPaths(test, ClipperLib.PolyType.ptSubject, true)
succeeded = cpr.Execute(ClipperLib.ClipType.ctUnion, clipper_union)

console.log clipper_union

You can find it here.

Thank you for your help!
Fabio

Discussion

  • Timo Kähkönen

    Timo Kähkönen - 2016-06-20

    This has to be some bug in original C# Clipper. I tested in the last stable C# Clipper version 6.2.1 and the solution was the same as in JS Clipper 6.2.1.0:

    C# Console Demo, solution.txt:
    ------------------------------
    2
    4
    403125, 1143750
    393750, 1143750
    393750, 1134375
    403125, 1134375
    12
    450000, 1087500
    450000, 1200000
    375000, 1200000
    375000, 1143750
    412500, 1143750
    412500, 1125000
    375000, 1125000
    375000, 1050000
    431250, 1050000
    431250, 1068750
    412500, 1068750
    412500, 1087500
    
    The mysubj.txt was:
    -------------------
    10
    4
    393750,1134375,
    403125,1134375,
    403125,1143750,
    393750,1143750
    4
    393750,1143750,
    412500,1143750,
    412500,1162500,
    393750,1162500
    4
    375000,1143750,
    393750,1143750,
    393750,1162500,
    375000,1162500
    4
    375000,1162500,
    412500,1162500,
    412500,1200000,
    375000,1200000
    4
    412500,1162500,
    450000,1162500,
    450000,1200000,
    412500,1200000
    4
    412500,1125000,
    450000,1125000,
    450000,1162500,
    412500,1162500
    4
    412500,1087500,
    450000,1087500,
    450000,1125000,
    412500,1125000
    4
    375000,1087500,
    412500,1087500,
    412500,1125000,
    375000,1125000
    4
    375000,1050000,
    412500,1050000,
    412500,1087500,
    375000,1087500
    4
    412500,1050000,
    431250,1050000,
    431250,1068750,
    412500,1068750
    
    The command was:
    ConsoleDemo.exe UNION mysubj.txt mysubj.txt 0 0
    
     
  • Timo Kähkönen

    Timo Kähkönen - 2016-06-21

    Because current stable C# Clipper is not perfect in common line joining, you can use an offset trick. The idea is to "bolden" every polygon a bit before UNION operation. Polygons can be boldened using Clipper's Offsetting feature. The offset delta (offset amount) is so small, that it does not affect to the final coordinates.

    This like case is trivial, but think about a case where you rotate the polygonal shape (using double coordinates) and make then an UNION operation. Without boldening trick it is sure that all common lines are not joined (while some will be). The boldening ensures that you get an expected result in all cases (all cases = I presume so).

    The downside is performance decrease, but if you must be sure, then there are not much choices.

    Please check this little demo about the offsetting trick:

    http://output.jsbin.com/sowiju

     

    Last edit: Timo Kähkönen 2016-07-19
  • Timo Kähkönen

    Timo Kähkönen - 2017-09-03
    • status: open --> closed
     
  • Timo Kähkönen

    Timo Kähkönen - 2017-09-03

    This is fixed in upcoming 6.4.2.1.

     

Log in to post a comment.