mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 16:02:23 +03:00
refactoring some approx_eq EPSILON_DIST checks
This commit is contained in:
parent
32a308f120
commit
142bd57aa0
@ -12,7 +12,6 @@
|
||||
- can we capture snapshots of incremental changes?
|
||||
- save initial map at every step, be able to load raw + initial with a focus point
|
||||
- generic viewer should be easy... something that stores polygon and ID, wraps the quadtree, etc
|
||||
- try merging the shortest roads first
|
||||
- deal with loop roads
|
||||
|
||||
- manually draw a picture of the weird intersection to see what would look reasonable. i think we need original road bands from deleted stuff to make decent polygons.
|
||||
|
@ -44,7 +44,7 @@ impl Plugin for WarpState {
|
||||
&ctx.primary.draw_map,
|
||||
) {
|
||||
let at = ctx.canvas.center_to_map_pt();
|
||||
if at.approx_eq(pt, geom::EPSILON_DIST) {
|
||||
if at.epsilon_eq(pt) {
|
||||
ctx.primary.current_selection = Some(id);
|
||||
return false;
|
||||
}
|
||||
|
@ -20,10 +20,7 @@ impl PolyLine {
|
||||
// squish down points here and make sure the final result is at least EPSILON_DIST.
|
||||
// But probably better for the callers to do this -- they have better understanding of what
|
||||
// needs to be squished down, why, and how.
|
||||
if pts
|
||||
.windows(2)
|
||||
.any(|pair| pair[0].approx_eq(pair[1], EPSILON_DIST))
|
||||
{
|
||||
if pts.windows(2).any(|pair| pair[0].epsilon_eq(pair[1])) {
|
||||
let length = pts.windows(2).fold(Distance::ZERO, |so_far, pair| {
|
||||
so_far + pair[0].dist_to(pair[1])
|
||||
});
|
||||
@ -122,7 +119,7 @@ impl PolyLine {
|
||||
// Does this line contain the last point of the slice?
|
||||
if dist_so_far + length >= end {
|
||||
let last_pt = line.dist_along(end - dist_so_far);
|
||||
if result.last().unwrap().approx_eq(last_pt, EPSILON_DIST) {
|
||||
if result.last().unwrap().epsilon_eq(last_pt) {
|
||||
result.pop();
|
||||
}
|
||||
result.push(last_pt);
|
||||
@ -135,7 +132,7 @@ impl PolyLine {
|
||||
|
||||
// If we're in the middle, just collect the endpoint. But not if it's too close to the
|
||||
// previous point (namely, the start, which could be somewhere far along a line)
|
||||
if !result.is_empty() && !result.last().unwrap().approx_eq(line.pt2(), EPSILON_DIST) {
|
||||
if !result.is_empty() && !result.last().unwrap().epsilon_eq(line.pt2()) {
|
||||
result.push(line.pt2());
|
||||
}
|
||||
|
||||
@ -390,7 +387,7 @@ impl PolyLine {
|
||||
let mut pts = self.pts.clone();
|
||||
pts.split_off(idx + 1);
|
||||
// Make sure the last line isn't too tiny
|
||||
if pts.last().unwrap().approx_eq(pt, EPSILON_DIST) {
|
||||
if pts.last().unwrap().epsilon_eq(pt) {
|
||||
pts.pop();
|
||||
}
|
||||
pts.push(pt);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{trim_f64, Angle, Distance, GPSBounds, LonLat};
|
||||
use crate::{trim_f64, Angle, Distance, GPSBounds, LonLat, EPSILON_DIST};
|
||||
use aabb_quadtree::geom::{Point, Rect};
|
||||
use ordered_float::NotNan;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@ -31,6 +31,11 @@ impl Pt2D {
|
||||
self.dist_to(other) <= threshold
|
||||
}
|
||||
|
||||
// Useful shortcut that's easy to refactor in the future.
|
||||
pub fn epsilon_eq(self, other: Pt2D) -> bool {
|
||||
self.approx_eq(other, EPSILON_DIST)
|
||||
}
|
||||
|
||||
pub fn from_gps(gps: LonLat, b: &GPSBounds) -> Option<Pt2D> {
|
||||
// TODO hack to construct test maps more easily
|
||||
if b.represents_world_space {
|
||||
|
@ -75,7 +75,7 @@ fn trim_front_path(bldg_points: &Vec<Pt2D>, path: Line) -> Line {
|
||||
for bldg_line in bldg_points.windows(2) {
|
||||
let l = Line::new(bldg_line[0], bldg_line[1]);
|
||||
if let Some(hit) = l.intersection(&path) {
|
||||
if !hit.approx_eq(path.pt2(), geom::EPSILON_DIST) {
|
||||
if !hit.epsilon_eq(path.pt2()) {
|
||||
return Line::new(hit, path.pt2());
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ pub fn short_roads(map: &mut InitialMap) {
|
||||
let orig_count = map.roads.len();
|
||||
|
||||
// Every time we change a road, other roads we might've already processed could shorten, so
|
||||
// we have to redo everything.
|
||||
// we have to redo everything. Note that order of merging doesn't SEEM to matter much...
|
||||
// tried tackling the shortest roads first, no effect.
|
||||
loop {
|
||||
if let Some(r) = map
|
||||
.roads
|
||||
|
Loading…
Reference in New Issue
Block a user