Union of polygons with colinear edges (2)
Boolean operations and offsetting library in Javascript
Brought to you by:
timo23414
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
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:
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
This is fixed in upcoming 6.4.2.1.