Skip to content

Sporadic inverted and degenerate polygons from varying intersection recursion paths #464

@benguild

Description

@benguild

When performing recursive polygon intersections, we occasionally encounter two types of anomalous results:

  1. Inverted polygons - Area > 2π sr (hemisphere), sometimes exactly 4π sr (full sphere)
  2. Degenerate polygons - Area < 1e-15 sr (effectively zero-area computational artifacts)

At first, I thought this was a memory management issue, but we can't find any issue there. This behavior appears non-deterministic or path-dependent …the same geometric inputs can produce either valid results or these anomalies depending on prior operations or recursion paths taken. In other words, if these operations are retried via a different recursion path, they do not occur.

It could be related to snapping behavior (rounding/randomness?) or some unknown internal state, but we're only working with "Clone(s)" of each polygon in any case prior to any operation, so there should not be any conflicts, races, or deallocations… unless it's something I haven't caught in the documentation yet.

Is this expected behavior when operating at higher precisions? Retrying the operations is doable, but I'm concerned that it may be masking something else that's going on, and that is not fully understood. I tried to put together example code, but whenever I try the same geometries in an isolated instance, it does work consistently… which is really a head scratcher.

Our workflow involves:

  • Creating MutableS2ShapeIndex for each polygon via index->Add(shape)
  • Immediately using these indexes in S2BooleanOperation::Build(*a->index, *b->index)
  • Polygon cloning thereafter
  • Each clone gets a fresh index (that's used immediately)

Since MutableS2ShapeIndex uses lazy batch updates for performance, I'm suspecting there could be an issue in this implementation/approach. But, any thoughts would be appreciated. If not, we could investigate further or consider an alternative mitigation/revision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions