georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.48k stars 191 forks source link

Panic in RegionAssembly reproducibly #1127

Open frehberg opened 6 months ago

frehberg commented 6 months ago

Occasionally (1:8) I observe a panic condition. I managed to print out the data of RegionAssembly causing the panic, and using this data to create a regression test (see PR)

Code with regresssion test assembling 3668 segments/lines https://github.com/georust/geo/pull/1126

The panic occures in the the check in file assembly.rs

            debug_assert!(num_segments % 2 == 0, "assembly segments must be eulierian");

The execution path leading to this point of the RegionAssembly occures in the context of bop.sweep() in the following code

impl<T: GeoFloat> BooleanOps for MultiPolygon<T> {
    type Scalar = T;

    fn boolean_op(&self, other: &Self, op: OpType) -> MultiPolygon<Self::Scalar> {
        let spec = BoolOp::from(op);
        let mut bop = Proc::new(spec, self.coords_count() + other.coords_count());
        bop.add_multi_polygon(self, 0);
        bop.add_multi_polygon(other, 1);
        bop.sweep()
    }

Appreciating any hint why this crash occures and how to avoid the panic crash

Screenshot from 2023-12-21 11-30-58

urschrei commented 6 months ago

1102, #1103, and #1104 may be related here.

frehberg commented 6 months ago

is the code of RegionAssembly crashing due to a bug in the algorithm, or due to bad input parameters? In case of the latter, how to prevent this?

urschrei commented 6 months ago

It's crashing due to a bug, and a fix is unlikely in the short term.

frehberg commented 6 months ago

hopefully this test https://github.com/georust/geo/pull/1126 can help you to reproduce the issue and fix the code