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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using BooleanOp with geo #32

Closed
afternoon2 opened this issue Apr 18, 2022 · 5 comments
Closed

Using BooleanOp with geo #32

afternoon2 opened this issue Apr 18, 2022 · 5 comments

Comments

@afternoon2
Copy link

afternoon2 commented Apr 18, 2022

Hello!

I'd like to ask a beginner question which I haven't found answer for (or I was looking for it badly 馃槄)

I use geo (not geo_types) in my project, and while trying to perform an intersection operation like this:

use geo::Polygon;
use geo_booleanop::boolean::BooleanOp;

pub fn clip(polygon: &Polygon<f64>, fill_shapes: &[Polygon<f64>]) {
    let value = fill_shapes.iter()
        .map(|shape| polygon.intersection(shape));
}

I get an error from the VSCode:

no method named `intersection` found for reference `&geo::Polygon<f64>` in the current scope

I see that, contrary to the README of this project, geo_booleanop uses geo_types instead of geo. Is it possible to use this library with geo?

Thank you for help!

@afternoon2
Copy link
Author

Ok, after a while, I switched to using geo_types version 0.7.4, but I keep getting the same error:

no method named `intersection` found for reference `&geo::Polygon<f64>` in the current scope

@afternoon2
Copy link
Author

afternoon2 commented Apr 18, 2022

So, in the end I followed the solution described here

use geo_booleanop::boolean::BooleanOp;
use old_geo_types::Polygon;

pub fn clip(
    polygon: &old_geo_types::Polygon<f64>,
    fill_shapes: &[old_geo_types::Polygon<f64>],
) -> Vec<old_geo_types::Polygon<f64>> {
    fill_shapes
        .iter()
        .flat_map(|shape| {
            polygon
                .intersection(shape)
                .iter()
                .cloned()
                .collect::<Vec<Polygon<f64>>>()
        })
        .collect::<Vec<Polygon<f64>>>()
}

Cargo.toml:

geo = "0.20.0"
geo-booleanop = "0.3.2"
geo-types = "0.7.4"
old-geo-types = { package = "geo-types", version = "0.6.2" }

@michaelkirk
Copy link
Contributor

The latest release of geo-booleanop for crates.io is 0.3.2, but there is not corresponding tag for that release on GH, so it's hard to know which commit that corresponds to. The latest version of rust-geo-booleanop on GH is compatible with geo-types 0.7.4.

I'm curious if your problem would equally go away (without the workaround) if you used geo-booleanop from github:

geo-booleanop = { git = "https://github.com/21re/rust-geo-booleanop" }

BTW - this kind of opaque error due to redundant incompatible versions is a common pain point in rust. Maybe you're already aware, but a tool I find useful is:

cargo tree -d

Which will show you any crates being included more than once. Seeing multiple versions of geo-types is sometimes OK if they live in non-overlapping code, but usually it's undesirable even then.

@afternoon2
Copy link
Author

Oh, I didn't know that! I'll try to use your advice, thank you!

@afternoon2
Copy link
Author

Yaay, it worked! Thank you very much!

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

No branches or pull requests

2 participants