Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix handling of polygons with holes #38

Merged
merged 1 commit into from
Apr 1, 2024
Merged

Conversation

ckp95
Copy link
Contributor

@ckp95 ckp95 commented Apr 1, 2024

The Rust version currently doesn't handle polygons with holes properly, because it doesn't account for interior rings.

The JS version:

import polylabel from "polylabel"

const polygon = [
    // exterior
    [
        [0, 0],
        [100, 0],
        [100, 100],
        [0, 100],
    ],

    // interior
    [
        [60, 60],
        [80, 60],
        [80, 80],
        [60, 80],
    ],
]

const result = polylabel(polygon, 1.0)
console.log(result)
[ 35.15625, 35.15625, distance: 35.13436819020658 ]

Diagram:

good-polylabel

But the current Rust version gives 50, 50, i.e. just the centre of the outer ring:

bad-polylabel

This PR brings polylabel-rs in line with the JS implementation.

@urschrei urschrei merged commit 85ae4ef into urschrei:master Apr 1, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants