terra-draw icon indicating copy to clipboard operation
terra-draw copied to clipboard

[Potential Bug] Unexpected result of polygon editing

Open risusinf opened this issue 1 year ago • 2 comments
trafficstars

Not sure if that's a bug, but i'll report it.

I'm using turf.difference to track edits i make to polygons, and noticed unusual geometries that i receive under certain circumstances. Here is a picture, in question is bottom right red polygon outline.

Screenshot_20240527_233405

Here is the same polygons over initial geometries.

Screenshot_20240527_233457

The edit was that i added more vertices by clicking midpoints (red circled) and then pulled central vertice up.

Screenshot_20240527_233550

I expected result to look like other polygons in the first picture, but it seems like adding more vertices slightly changed geometry of the bottom part of the polygon.

risusinf avatar May 27 '24 17:05 risusinf

Hey @risusinf, apologies about the delayed response. I always appreciate people raising what they think might be bugs with Terra Draw, so that you for that. I've read through your issue, but in honesty am struggling to fully understand the issue you are describing. Would you kindly be able to simplify this down to a single geometry/image so I can follow it a little more easily?

The other thing to say, without obviously being able to say with strict confidence, is that this could also be a bug with @turf/difference.

Look forward to hearing from you.

JamesLMilner avatar Jun 02 '24 12:06 JamesLMilner

Case 1.

Left to right:

  • initial polygon (first pane),
  • i add more vertices by clicking midpoints on it's two sides (second pane),
  • then i pull central vertices on each side outwards (third pane)
  • turf.difference output (fourth pane)

This is the result i expected, clean triangles representing changes i made.

1

============ Case 2.

  • same procedure with the same polygon (first and second panes),
  • but this time i drag same vertices inwards (third pane)
  • turf.difference output in the fourth pane is different

There is now a ghost line in place where the edited sides were.

2

============ Case 3.

Doing the same thing as before now on every side of the initial polygon, moving central vertices inward or outwards. Outcome is inconsistent. Sometimes it's just a triangle, sometimes a triangle with a "ghost line".

3

I'm just trying to understand what are those artifacts and where are they come from. If you say the culprit is turf.difference i believe you, but i'm not feeling like bringing it over there honestly.

PS. It is probably turf, because when i run pane 1 and 2 from case 1 through it -- the result (it is written to database) is not empty, but the map doesn't show anything. Going to close this after your follow up.

risusinf avatar Jun 07 '24 14:06 risusinf

Hey @risusinf sorry about taking so long to respond here - appreciate your detailed reply. I saw that you concluded this is probably turf, which look at your screenshots leads me to think the same. It may be some spurious floating point precision issue where it doesn't consider some of those coordinates to be identical?

I'm going to close this just in the interests of keeping on top of the issues board, but feel free to write more comments or open a new issue if you think you have identified a reproducible issue. Thanks again for your interest in the project!

JamesLMilner avatar Aug 17 '24 08:08 JamesLMilner

@JamesLMilner I haven't worked on my project throughout the summer, so nothing new on this one. Not sure how exactly turf works, but my last guess at the time was that adding new vertices to a polygon makes it 'different' from the original for turf, despite area coverage may remain the same, so when it tries to calculate difference the output is a pseudo polygon made of new vertices. Never got to check if that's the case, and if so i don't think it's fixable.

risusinf avatar Aug 18 '24 03:08 risusinf

@JamesLMilner Got back to this, and i report back just to conclude. After trying many approaches i failed to eliminate these rogue deviation in geometry. My final impression was that's because of the difference in coordinate precision -- turf apparently operates at the level of absurd 14 decimals. I came up with a demo showing that turf doesn't consider two terradraw snapshots of identical polygons to be actually identical when the second polygon has redundant vertices at certain sides. In the end i have to write a validation function which would remove stranded sliver polygons and truncate the rest off of the infinitely thin tails. That's i'm in the process of doing.

Снимок экрана_20240914_112700

risusinf avatar Sep 14 '24 04:09 risusinf