tried tossing intersection endpoints into a convex polygon routine, but

it looks pretty bad. keeping around, but disabled.
This commit is contained in:
Dustin Carlino 2019-02-06 09:39:32 -08:00
parent e1155a1d9c
commit a9b9ae61bb
2 changed files with 39 additions and 3 deletions

View File

@ -10,6 +10,7 @@
- handle small roads again somehow?
- bad polygons
- ../initial_maps/024, o101. sorting final endpoints by angle to center isn't foolproof.
- draw the center
- adjacent roads based on angle isnt foolproof either. o177. but it actually looks fine, with the sorting by center.
- the "center" should be average of all the original endpoints. then angle from last line's first pt to that center, since the last line's last pt might actually BE that center.

View File

@ -178,9 +178,44 @@ fn generalized_trim_back(
endpoints.sort_by_key(|pt| HashablePt2D::from(*pt));
endpoints = Pt2D::approx_dedupe(endpoints, Distance::meters(1.0));
// Different ways of making convex polygons from the endpoints. For now, the simpler one looks
// better.
if true {
let center = Pt2D::center(&endpoints);
endpoints.sort_by_key(|pt| center.angle_to(*pt).normalized_degrees() as i64);
endpoints
} else {
use geo;
use geo::algorithm::convexhull::ConvexHull;
// To get a convex polygon, often we can just find the center of these endpoints and sort
// the points by the angle to the center. But this breaks down for some merged
// intersections, so use something more heavy-weight.
let polygon = geo::Polygon::new(
geo::LineString(
endpoints
.into_iter()
.map(|pt| geo::Coordinate {
x: pt.x(),
y: pt.y(),
})
.collect(),
),
vec![],
);
let convex = polygon.convex_hull();
let mut final_endpoints = Pt2D::approx_dedupe(
convex
.exterior
.into_points()
.into_iter()
.map(|pt| Pt2D::new(pt.x(), pt.y()))
.collect(),
Distance::meters(1.0),
);
final_endpoints.reverse();
final_endpoints
}
}
fn deadend(