trimming front paths to building edges

This commit is contained in:
Dustin Carlino 2018-08-22 11:54:18 -07:00
parent 00056e6e81
commit a2399f6613
3 changed files with 21 additions and 6 deletions

View File

@ -112,12 +112,12 @@
0.7, 0.7,
0.7, 0.7,
0.7, 0.7,
1.0 0.8
], ],
"BuildingPath": [ "BuildingPath": [
0.8, 0.6,
0.8, 0.6,
0.8, 0.6,
1.0 1.0
], ],
"BuildingBoundary": [ "BuildingBoundary": [

View File

@ -20,6 +20,10 @@ impl Line {
self.1 self.1
} }
pub fn points(&self) -> Vec<Pt2D> {
vec![self.0, self.1]
}
// TODO valid to do euclidean distance on world-space points that're formed from // TODO valid to do euclidean distance on world-space points that're formed from
// Haversine? // Haversine?
pub fn length(&self) -> si::Meter<f64> { pub fn length(&self) -> si::Meter<f64> {

View File

@ -1,5 +1,5 @@
use geo; use geo;
use geom::{Bounds, Line, Pt2D}; use geom::{Bounds, Line, Pt2D, PolyLine};
use geometry; use geometry;
use ordered_float::NotNaN; use ordered_float::NotNaN;
use raw_data; use raw_data;
@ -19,7 +19,7 @@ pub(crate) fn make_building(
.map(|coord| Pt2D::from_gps(coord, bounds)) .map(|coord| Pt2D::from_gps(coord, bounds))
.collect(); .collect();
//let front_path = find_front_path_using_street_names(&points, &b.osm_tags, lanes, roads); //let front_path = find_front_path_using_street_names(&points, &b.osm_tags, lanes, roads);
let front_path = find_front_path(&points, lanes); let front_path = trim_front_path(&points, find_front_path(&points, lanes));
Building { Building {
points, points,
@ -30,6 +30,17 @@ pub(crate) fn make_building(
} }
} }
// Adjust the path to start on the building's border, not center
fn trim_front_path(bldg_points: &Vec<Pt2D>, path: Line) -> Line {
let poly = PolyLine::new(bldg_points.clone());
if let Some(hit) = poly.intersection(&PolyLine::new(path.points())) {
Line::new(hit, path.pt2())
} else {
// Just give up
path
}
}
fn find_front_path(bldg_points: &Vec<Pt2D>, lanes: &Vec<Lane>) -> Line { fn find_front_path(bldg_points: &Vec<Pt2D>, lanes: &Vec<Lane>) -> Line {
use geo::prelude::{ClosestPoint, EuclideanDistance}; use geo::prelude::{ClosestPoint, EuclideanDistance};