Skip to content

Index out of bounds when creating a buffer #61

@hwuerz

Description

@hwuerz

Summary

Thank you very much for the nice library and the active development! I use iOverlay via the geo crate. However, in the example below, I get an index out of bounds error. I suspect that this is related to some kind of numerical problem. When I visualize the polygon, it actually looks OK.

Steps to reproduce

use std::f64::consts::PI;

use geo::{
    Buffer, Coord, LineString, Polygon,
    buffer::{BufferStyle, LineCap, LineJoin},
};

fn main() {
    let coords = vec![
        [411162.0470393328, 5848155.806033095],
        [411162.3299983172, 5848152.285037002],
        [411162.44901687186, 5848149.446047744],
        [411167.5609553484, 5848148.9709500875],
        [411175.2629817156, 5848147.891970595],
        [411186.7560237078, 5848146.501955947],
        [411203.86503249686, 5848144.432009658],
        [411214.44804030936, 5848143.314944228],
        [411221.0470393328, 5848142.421999892],
        [411227.85697585624, 5848141.499026259],
        [411233.74100905936, 5848140.505007705],
        [411238.4249690203, 5848139.349978408],
        [411242.85697585624, 5848138.25305458],
        [411249.1400569109, 5848136.395022353],
        [411256.6129573015, 5848134.406008681],
        [411262.81803542655, 5848132.916018447],
        [411275.2460139422, 5848129.93298622],
        [411284.6999934344, 5848127.662966689],
        [411292.3739436297, 5848125.3869657125],
        [411295.41703445, 5848123.3430204],
        [411297.0079768328, 5848121.340945205],
        [411297.43900710624, 5848119.1510037985],
        [411293.11698562186, 5848105.54602333],
        [411287.24100905936, 5848076.412966689],
        [411286.6709407, 5848062.798953017],
        [411286.98099929374, 5848053.410037002],
        [411288.3879817156, 5848038.451052627],
        [411294.0620539813, 5848006.396975478],
        [411294.9409602312, 5847995.477053603],
        [411295.2140315203, 5847988.534060439],
        [411296.3359797625, 5847983.056033095],
        [411297.8600276141, 5847976.624026259],
        [411297.86698562186, 5847976.590945205],
        [411298.2679865984, 5847974.952029189],
        [411301.5709651141, 5847965.958010634],
        [411303.7980158953, 5847955.29602333],
        [411305.12797195, 5847948.927004775],
        [411307.15897780936, 5847937.4279813375],
        [411307.711956325, 5847934.313967666],
        [411310.8889582781, 5847916.500979384],
        [411311.8309748797, 5847911.5959500875],
        [411312.3839533953, 5847898.51098915],
        [411311.64603835624, 5847891.3459500875],
        [411308.97904616874, 5847878.494997939],
        [411303.793987575, 5847862.650027236],
        [411301.5509455828, 5847857.5080594625],
        [411297.4499934344, 5847849.958010634],
        [411294.81303054374, 5847846.331057509],
        [411281.3550227312, 5847828.88598915],
        [411261.0709651141, 5847805.2369412985],
        [411259.2100032, 5847804.3619412985],
        [411258.0150569109, 5847803.80005165],
        [411254.8910334734, 5847803.62805458],
        [411251.86503249686, 5847805.3430204],
        [411249.4499934344, 5847802.375002822],
        [411248.2519953875, 5847800.202029189],
        [411248.1909602312, 5847794.432009658],
        [411253.23197585624, 5847785.8170194235],
        [411255.7970393328, 5847788.224978408],
        [411257.6870539813, 5847789.534060439],
        [411259.8690608172, 5847790.333010634],
        [411262.0520442156, 5847790.332034072],
        [411268.8910334734, 5847788.8420438375],
        [411269.4320490984, 5847790.333010634],
        [411270.6329768328, 5847793.6369657125],
        [411269.1820490984, 5847794.332034072],
        [411267.65397292655, 5847796.224001845],
        [411266.9259455828, 5847798.990969619],
        [411267.6709407, 5847800.479006728],
        [411268.7440608172, 5847802.625979384],
        [411281.10795241874, 5847816.8850125875],
        [411283.4420588641, 5847819.822024306],
        [411294.9740412859, 5847834.3430204],
        [411304.0699885515, 5847846.6369657125],
        [411307.27103835624, 5847852.748049697],
        [411309.8900569109, 5847857.912966689],
        [411311.78300124686, 5847864.460940322],
        [411313.6019709734, 5847869.698977431],
        [411314.9850276141, 5847872.171999892],
        [411317.53104812186, 5847875.446047744],
        [411320.7970393328, 5847877.480959853],
        [411325.86600905936, 5847879.2180204],
        [411335.5499690203, 5847882.012942275],
        [411368.4549983172, 5847890.26098915],
        [411387.668987575, 5847895.4010037985],
        [411397.7240412859, 5847898.576052627],
        [411405.50297195, 5847902.333010634],
        [411411.0599787859, 5847905.931033095],
        [411418.5199397234, 5847911.750979384],
        [411434.2660334734, 5847926.797976455],
        [411436.82304030936, 5847934.838015517],
        [411437.5780451922, 5847936.113039931],
        [411434.0089533953, 5847946.812991103],
        [411431.19804030936, 5847949.901980361],
        [411411.5659602312, 5847985.880984267],
        [411407.6529963641, 5847993.0510282125],
        [411404.77994948905, 5848000.453982314],
        [411402.93803054374, 5848007.354983291],
        [411399.39701491874, 5848029.913943252],
        [411392.9289973406, 5848080.029055556],
        [411390.43998366874, 5848099.298953017],
        [411388.8789485125, 5848106.744021377],
        [411386.1429865984, 5848113.750979384],
        [411383.2870295672, 5848120.22595497],
        [411379.1269953875, 5848126.2580594625],
        [411373.0499690203, 5848132.165041884],
        [411368.44901687186, 5848135.741946181],
        [411362.3199885515, 5848138.749026259],
        [411354.7980158953, 5848141.105959853],
        [411345.8729670672, 5848143.8990506735],
        [411334.5969660906, 5848146.394045791],
        [411322.7279475359, 5848149.957034072],
        [411321.0050471453, 5848151.457034072],
        [411319.7229426531, 5848152.791995009],
        [411319.23698073905, 5848154.2740506735],
        [411319.336956325, 5848156.656008681],
        [411339.95194655936, 5848207.255007705],
        [411351.7620051531, 5848236.444949111],
        [411364.9020198015, 5848268.477053603],
        [411376.5170100359, 5848297.156008681],
        [411377.7340510515, 5848300.22595497],
        [411395.8690608172, 5848345.97595497],
        [411411.2689631609, 5848381.8459500875],
        [411413.1310237078, 5848382.543948134],
        [411405.27994948905, 5848384.8010282125],
        [411332.1410334734, 5848206.078005752],
        [411309.5890315203, 5848150.895998916],
        [411307.8690608172, 5848147.239993056],
        [411305.3419612078, 5848144.284060439],
        [411301.6329768328, 5848141.729983291],
        [411296.9740412859, 5848139.974978408],
        [411293.77494460624, 5848139.145022353],
        [411290.1350520281, 5848139.240969619],
        [411276.68998366874, 5848140.473025283],
        [411274.44901687186, 5848140.531008681],
        [411266.961956325, 5848144.207034072],
        [411247.6239436297, 5848146.937014541],
        [411246.2670100359, 5848147.2369412985],
        [411240.0699885515, 5848148.041018447],
        [411234.7219660906, 5848150.973025283],
        [411224.2479670672, 5848149.892947158],
        [411223.6759455828, 5848148.834963759],
        [411222.2269709734, 5848148.297976455],
        [411213.2560237078, 5848149.380984267],
        [411189.6649592547, 5848152.199953994],
        [411162.0470393328, 5848155.806033095],
    ];

    let hole = vec![
        [411294.2500422625, 5848072.3189725485],
        [411373.9180110125, 5848124.016970595],
        [411377.22904616874, 5848118.990969619],
        [411393.0859797625, 5848020.979983291],
        [411394.7030451922, 5848005.639040908],
        [411397.4359553484, 5848003.376955947],
        [411431.1029475359, 5847937.537966689],
        [411431.2639582781, 5847933.187991103],
        [411314.8390315203, 5848005.308962783],
        [411314.5590022234, 5848009.708010634],
        [411309.3459895281, 5848009.447024306],
        [411305.3719905047, 5848010.244997939],
        [411294.2500422625, 5848072.3189725485],
    ];

    let coords = coords
        .into_iter()
        .map(|c| Coord::from((c[0], c[1])))
        .collect::<Vec<_>>();
    let ls = LineString::new(coords);

    let hole = hole
        .into_iter()
        .map(|c| Coord::from((c[0], c[1])))
        .collect::<Vec<_>>();
    let ls_hole = LineString::new(hole);

    let polygon = Polygon::new(ls, vec![ls_hole]);

    let angle = 10.0 / (PI / 2.0);
    let _buffer = polygon.buffer_with_style(
        BufferStyle::new(600.0)
            .line_cap(LineCap::Round(angle))
            .line_join(LineJoin::Round(angle)),
    );
    println!("Buffer created successfully");
}

Expected behavior

A new polygon with a buffer of 600 meters.

Actual behavior

The program crashes with an index out of bounds error.

thread 'main' panicked at /home/hmwuerz/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/i_overlay-4.0.7/src/bind/solver.rs:91:33:
index out of bounds: the len is 1 but the index is 9223372036854775807

Environment

  • iOverlay version: 4.0.7
  • Rust version: 1.89.0
  • OS: Ubuntu 24.04

Additional context

Thank you for the great lib! Let me know, if I should provide any other information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions