Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KdTree::remove() fails in some circumstances #12

Closed
abey79 opened this issue Mar 25, 2023 · 5 comments · Fixed by #14
Closed

KdTree::remove() fails in some circumstances #12

abey79 opened this issue Mar 25, 2023 · 5 comments · Fixed by #14

Comments

@abey79
Copy link

abey79 commented Mar 25, 2023

I have been able to narrow down a case where remove() incorrectly fails to remove an item, returning 0:

#[test]
    fn test_kiddo_bug() {
        let pts = vec![
            [19.2023, 7.1812],
            [7.6427, 22.5779],
            [26.6314, 34.8920],
            [36.7890, 27.2663],
            [28.3226, 8.5047],
            [5.3914, 28.1360],
            [5.0978, 3.6814],
            [0.5114, 11.6552],
            [4.7981, 21.6210],
            [29.0030, 9.6799],
            [35.5580, 1.8891],
            [3.9160, 25.5702],
            [22.2497, 31.6140],
            [30.7110, 36.7514],
            [0.2828, 12.4298],
            [20.0206, 3.0635],
            [30.6153, 2.8582],
            [23.7179, 6.2048],
            [13.0438, 4.2319],
            [4.6433, 30.9660],
            [5.0588, 5.2028],
            [19.2023, 23.7406],
            [37.3171, 32.7523],
            [12.6957, 15.7080],
            [15.6001, 14.3995],
            [36.0203, 21.0366],
            [6.3956, 2.7644],
            [3.1719, 8.7039],
            [0.9159, 12.2299],
            [23.8157, 14.0699],
            [27.7757, 7.3597],
            [28.4198, 31.3427],
            [2.3290, 6.2364],
            [10.1126, 7.7009],
        ];

        let mut tree = KdTree::<f64, 2>::new();

        for (i, pt) in pts.iter().enumerate() {
            tree.add(pt, i);
        }

        assert_eq!(tree.remove(&pts[0], 0), 1);
    }

This test fails as tree.remove(&pts[0], 0) return 0. Commenting out any of the points in the input array makes the test pass. Removing any/all of the points except 0 works. Removing index 0 fails in all circumstances.

Also, this failing case appears to be sensitive to the specific order of the input points. I can't reproduce the fail by moving points around.

kiddo 2.0.0-beta.5
Toolchain: nightly-2023-03-03
macOS Ventura 13.2.1 on MBP M1 Max

@sdd
Copy link
Owner

sdd commented Mar 25, 2023

Thanks for this report too. This is a strange one! Looks like I'll have to break out the debugger for this one...

@sdd
Copy link
Owner

sdd commented Mar 25, 2023

Confirmed, I see the same behaviour. Looking into it now

@sdd
Copy link
Owner

sdd commented Mar 25, 2023

Fixed! Released as https://crates.io/crates/kiddo/2.0.0-beta.7.

Thanks a lot for the example, it was invaluable in tracking down the problem!

Please do let me know how you get on if you continue to use the v2 beta, especially if you experience any more issues - happy to help.

@abey79
Copy link
Author

abey79 commented Mar 25, 2023

Great, thanks!

abey79 added a commit to abey79/vsvg that referenced this issue Mar 27, 2023
This is a WIP commit before replacement of Kiddo by kdtree 0.7, as kiddo has breaking bugs (eg sdd/kiddo#12).
@wentasah wentasah mentioned this issue Apr 27, 2023
@wentasah
Copy link

It seems there is more problems with point removals. See #28.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants