andriyDev / polygon_clipping_rs

A Rust crate to compute boolean operations on polygons.
MIT License
12 stars 0 forks source link

Panic while clipping two polygons #11

Open jblestang opened 1 year ago

jblestang commented 1 year ago

I'm trying to merge two polygons that have the same shape but a slight offset (0.05, 0.05) so they are overlapping. This generates a panic in the union algorithm :

Vec2(0.0, 1.0) Vec2(0.70710677, 0.70710677) Vec2(1.0, -4.371139e-8) Vec2(0.70710677, -0.70710677) Vec2(-8.742278e-8, -1.0) Vec2(-0.7071067, -0.7071068) Vec2(-1.0, 1.1924881e-8) Vec2(-0.7071069, 0.70710665) with Vec2(0.05, 1.05) Vec2(0.7571068, 0.7571068) Vec2(1.05, 0.049999956) Vec2(0.7571068, -0.65710676) Vec2(0.049999915, -0.95) Vec2(-0.6571067, -0.6571068) Vec2(-0.95, 0.050000012) Vec2(-0.6571069, 0.75710666) It ends with the following error : thread 'main' panicked at polygon_clipping_rs/src/lib.rs:924:10: this is a right event, so the left event must have already been inserted.: 2

This is using d719ecb (HEAD -> main, origin/main, origin/HEAD) HEAD@{0}: clone: from https://github.com/andriyDev/polygon_clipping_rs.git

jblestang commented 1 year ago

I can give an easier reproducer :

Subject : [Vec2(-0.5, 0.5), Vec2(0.4999999, -0.5), Vec2(1.5, 0.49999997), Vec2(0.5, 1.5)]

Clipped with : [Vec2(-1.0, 1.1924881e-8), Vec2(-8.742278e-8, -1.0), Vec2(1.0, -4.371139e-8), Vec2(0.0, 1.0)]

jblestang commented 1 year ago

Might also be the same problem as reported in #10

jblestang commented 9 months ago

I tried the newest branch « new-impl » and it gives me far better results! Well done!