mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Make Polygon::from_geojson preserve rings. This fixes the WIP elevation contours. #82
This commit is contained in:
parent
92d3a890ea
commit
c1ac3cf39d
@ -180,7 +180,9 @@ impl Isochrone {
|
||||
match feature.geometry.unwrap().value {
|
||||
geojson::Value::MultiPolygon(polygons) => {
|
||||
for p in polygons {
|
||||
batch.push(color, Polygon::from_geojson(&p).scale(resolution_m));
|
||||
if let Ok(poly) = Polygon::from_geojson(&p) {
|
||||
batch.push(color, poly.scale(resolution_m));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -73,18 +73,14 @@ impl Polygon {
|
||||
Polygon::with_holes(outer, rings)
|
||||
}
|
||||
|
||||
// TODO Doesn't remember rings yet
|
||||
pub fn from_geojson(raw: &Vec<Vec<Vec<f64>>>) -> Polygon {
|
||||
let (vertices, holes, dims) = earcutr::flatten(raw);
|
||||
let indices = downsize(earcutr::earcut(&vertices, &holes, dims));
|
||||
Polygon {
|
||||
points: vertices
|
||||
.chunks(2)
|
||||
.map(|pair| Pt2D::new(pair[0], pair[1]))
|
||||
.collect(),
|
||||
indices,
|
||||
rings: None,
|
||||
pub fn from_geojson(raw: &Vec<Vec<Vec<f64>>>) -> Result<Polygon> {
|
||||
let mut rings = Vec::new();
|
||||
for pts in raw {
|
||||
let transformed: Vec<Pt2D> =
|
||||
pts.iter().map(|pair| Pt2D::new(pair[0], pair[1])).collect();
|
||||
rings.push(Ring::new(transformed)?);
|
||||
}
|
||||
Ok(Polygon::from_rings(rings))
|
||||
}
|
||||
|
||||
// TODO No guarantee points forms a ring. In fact, the main caller is from SVG->lyon parsing,
|
||||
|
@ -210,10 +210,9 @@ pub fn make_heatmap(
|
||||
// Don't block the map underneath
|
||||
let color = Color::rgb(c.r as usize, c.g as usize, c.b as usize).alpha(0.6);
|
||||
for p in polygons {
|
||||
batch.push(
|
||||
color,
|
||||
Polygon::from_geojson(&p).scale(opts.resolution as f64),
|
||||
);
|
||||
if let Ok(poly) = Polygon::from_geojson(&p) {
|
||||
batch.push(color, poly.scale(opts.resolution as f64));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
Loading…
Reference in New Issue
Block a user