...
[dependencies]
geo-types = "0.3.0"
geo-booleanop = { git = "https://github.com/21re/rust-geo-booleanop.git" }
#![forbid(unsafe_code)]
extern crate geo_types;
extern crate geo_booleanop;
use geo_types::*;
use geo_booleanop::boolean::BooleanOp;
fn is_closed(p: &Polygon<f64>) -> bool {
&p.exterior.0[0] == p.exterior.0.last().unwrap()
}
fn main() {
let poly1: Polygon<f64> =
Polygon {
exterior: LineString(
vec![
Coordinate {
x: -530.,
y: -530.
},
Coordinate {
x: -530.,
y: 530.
},
Coordinate {
x: 530.,
y: 530.
},
Coordinate {
x: 530.,
y: -530.
},
Coordinate {
x: -530.,
y: -530.
}
]
),
interiors: vec![]
};
let poly2: Polygon<f64> =
Polygon {
exterior: LineString(
vec![
Coordinate {
x: 1.2500125250252,
y: -531.
},
Coordinate {
x: -98.,
y: -531.
},
Coordinate {
x: -98.,
y: 531.
},
Coordinate {
x: 1.250012525025,
y: 531.
},
Coordinate {
x: 1.2500125250252,
y: -531.
}
]
),
interiors: vec![]
};
println!("{}", is_closed(&poly1));
println!("{}", is_closed(&poly2));
println!("{}", is_closed(&poly1.intersection(&poly2).0[0]));
}
As far as I can tell, the
geo_types::LineStringin ageo_types::Polygonis supposed to have its first and last coordinates be the same. (I believe this is what the docs mean by "closed". Is that correct?)I have found a case where
poly1andpoly2both satisfy that condition, butpoly1.intersection(&poly2)does not.Is this a bug? Or am I just doing something wrong?
Cargo.toml
main.rs
Output: