Skip to content

Commit

Permalink
Bring in the code for coloring cells by area... with definite bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Dec 20, 2023
1 parent 461af23 commit 5d4d3b5
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 17 deletions.
28 changes: 28 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ wasm-bindgen = "0.2.87"
web-sys = { version = "0.3.64", features = ["console"] }
bincode = "1.3.3"
petgraph = "0.6.4"
contour = "0.12.0"
2 changes: 2 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use wasm_bindgen::prelude::*;

use self::cells::Cell;
use self::neighbourhood::Neighbourhood;
use self::render_cells::RenderCells;
use self::shortcuts::Shortcuts;

mod cells;
mod mercator;
mod neighbourhood;
mod render_cells;
mod scrape;
mod shortcuts;
mod tags;
Expand Down
32 changes: 18 additions & 14 deletions backend/src/neighbourhood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ use geo::{
};
use geojson::{Feature, GeoJson, Geometry};

use crate::{Cell, IntersectionID, MapModel, RoadID, Shortcuts};
use crate::render_cells::Color;
use crate::{Cell, IntersectionID, MapModel, RenderCells, RoadID, Shortcuts};

pub struct Neighbourhood {
pub interior_roads: HashSet<RoadID>,
crosses: HashMap<RoadID, f64>,
pub border_intersections: HashSet<IntersectionID>,
pub boundary_polygon: Polygon,
}

impl Neighbourhood {
Expand Down Expand Up @@ -60,6 +62,7 @@ impl Neighbourhood {
interior_roads,
crosses,
border_intersections,
boundary_polygon: boundary,
})
}

Expand All @@ -69,28 +72,16 @@ impl Neighbourhood {
// TODO Decide how/where state lives
let modal_filters = BTreeMap::new();
let cells = Cell::find_all(map, self, &modal_filters);
let render_cells = RenderCells::new(map, self, &cells);
let shortcuts = Shortcuts::new(map, self);

// TODO Temporary rendering
let mut road_to_cell = HashMap::new();
for (idx, cell) in cells.iter().enumerate() {
for (r, _) in &cell.roads {
road_to_cell.insert(*r, idx);
}
}

for r in &self.interior_roads {
let mut f = map.get_r(*r).to_gj(&map.mercator);
f.set_property("kind", "interior_road");
f.set_property(
"shortcuts",
shortcuts.count_per_road.get(r).cloned().unwrap_or(0),
);
if let Some(cell) = road_to_cell.get(r) {
f.set_property("cell", *cell);
} else {
error!("A road has no cell");
}
features.push(f);
}
for (r, pct) in &self.crosses {
Expand All @@ -105,6 +96,19 @@ impl Neighbourhood {
features.push(f);
}

for (polygons, color) in render_cells
.polygons_per_cell
.into_iter()
.zip(render_cells.colors)
{
let mut f = Feature::from(Geometry::from(&map.mercator.to_wgs84(&polygons)));
match color {
Color::Disconnected => f.set_property("color", "disconnected"),
Color::Cell(idx) => f.set_property("color", idx),
}
features.push(f);
}

GeoJson::from(features)
}
}
Loading

0 comments on commit 5d4d3b5

Please sign in to comment.