use Distance, not f64, for some params in geom/ layer, simplifying other code

This commit is contained in:
Dustin Carlino 2019-05-17 12:34:04 -07:00
parent c29039c499
commit 222ddf6a96
7 changed files with 42 additions and 32 deletions

View File

@ -2,7 +2,7 @@ use crate::ui::UI;
use ezgui::{
Canvas, Color, EventCtx, GfxCtx, InputResult, Key, ModalMenu, ScreenPt, ScrollingMenu,
};
use geom::Polygon;
use geom::{Distance, Polygon};
// TODO assumes minimum screen size
const WIDTH: u32 = 255;
@ -81,7 +81,11 @@ impl ColorPicker {
));
g.draw_polygon(
color,
&Polygon::rectangle_topleft(corner, TILE_DIMS, TILE_DIMS),
&Polygon::rectangle_topleft(
corner,
Distance::meters(TILE_DIMS),
Distance::meters(TILE_DIMS),
),
);
}
}

View File

@ -167,12 +167,12 @@ impl ScenarioEditor {
// TODO Draw text label in neighborhood, then src is left and dst is right
let src = mapping[&s.start_from_neighborhood]
.center
.offset(-50.0, 0.0);
.offset(Distance::meters(-50.0), Distance::ZERO);
let dst = match s.goal {
OriginDestination::Neighborhood(ref n) => mapping[n].center,
OriginDestination::Border(i) => ui.primary.map.get_i(i).point,
}
.offset(50.0, 0.0);
.offset(Distance::meters(50.0), Distance::ZERO);
// TODO Draw a self-loop or something
if src == dst {
continue;

View File

@ -242,10 +242,9 @@ pub fn draw_signal_cycle(
return;
}
// TODO argh, fix these types to use Distance
let radius = Distance::meters(0.5);
let box_width = (2.5 * radius).inner_meters();
let box_height = (6.5 * radius).inner_meters();
let box_width = 2.5 * radius;
let box_height = 6.5 * radius;
let center = ctx.map.get_i(cycle.parent).point;
let top_left = center.offset(-box_width / 2.0, -box_height / 2.0);
let percent = time_left.unwrap() / cycle.duration;
@ -256,7 +255,7 @@ pub fn draw_signal_cycle(
);
batch.push(
Color::RED,
Circle::new(center.offset(0.0, (-2.0 * radius).inner_meters()), radius).to_polygon(),
Circle::new(center.offset(Distance::ZERO, -2.0 * radius), radius).to_polygon(),
);
batch.push(Color::grey(0.4), Circle::new(center, radius).to_polygon());
batch.push(
@ -265,7 +264,7 @@ pub fn draw_signal_cycle(
);
batch.push(
Color::GREEN,
Circle::new(center.offset(0.0, (2.0 * radius).inner_meters()), radius).to_polygon(),
Circle::new(center.offset(Distance::ZERO, 2.0 * radius), radius).to_polygon(),
);
batch.draw(g);
}
@ -404,8 +403,8 @@ pub fn draw_signal_diagram(
.get_def("signal editor panel", Color::BLACK.alpha(0.95)),
&Polygon::rectangle_topleft(
Pt2D::new(x1_screen, y1_screen),
total_screen_width,
(padding + intersection_height) * (cycles.len() as f64) * zoom,
Distance::meters(total_screen_width),
Distance::meters((padding + intersection_height) * (cycles.len() as f64) * zoom),
),
);
g.draw_polygon(
@ -418,8 +417,8 @@ pub fn draw_signal_diagram(
x1_screen,
y1_screen + (padding + intersection_height) * (current_cycle as f64) * zoom,
),
total_screen_width,
(padding + intersection_height) * zoom,
Distance::meters(total_screen_width),
Distance::meters((padding + intersection_height) * zoom),
),
);

View File

@ -1,7 +1,7 @@
use crate::render::MIN_ZOOM_FOR_DETAIL;
use crate::ui::UI;
use ezgui::{Color, EventCtx, GfxCtx, ModalMenu};
use geom::{Bounds, Duration, Polygon, Pt2D};
use geom::{Bounds, Distance, Duration, Polygon, Pt2D};
use map_model::{RoadID, Traversable};
use std::collections::HashMap;
@ -120,8 +120,8 @@ impl Heatmap {
self.bounds.min_x + (x as f64) * tile_width,
self.bounds.min_y + (y as f64) * tile_height,
),
tile_width,
tile_height,
Distance::meters(tile_width),
Distance::meters(tile_height),
),
);
}

View File

@ -1,6 +1,6 @@
use crate::screen_geom::ScreenRectangle;
use crate::{Canvas, Color, GfxCtx, ScreenPt};
use geom::{Polygon, Pt2D};
use geom::{Distance, Polygon, Pt2D};
use glium_glyph::glyph_brush::rusttype::Scale;
use glium_glyph::glyph_brush::GlyphCruncher;
use glium_glyph::glyph_brush::{Section, SectionText, VariedSection};
@ -180,8 +180,8 @@ pub fn draw_text_bubble(
c,
&Polygon::rectangle_topleft(
Pt2D::new(top_left.x, top_left.y),
total_width,
total_height,
Distance::meters(total_width),
Distance::meters(total_height),
),
);
}
@ -210,7 +210,11 @@ pub fn draw_text_bubble(
if let Some(c) = line_color {
g.draw_polygon(
*c,
&Polygon::rectangle_topleft(Pt2D::new(top_left.x, y), total_width, height),
&Polygon::rectangle_topleft(
Pt2D::new(top_left.x, y),
Distance::meters(total_width),
Distance::meters(height),
),
);
}
@ -244,7 +248,11 @@ pub fn draw_text_bubble_mapspace(
if let Some(c) = txt.bg_color {
g.draw_polygon(
c,
&Polygon::rectangle_topleft(top_left, total_width, total_height),
&Polygon::rectangle_topleft(
top_left,
Distance::meters(total_width),
Distance::meters(total_height),
),
);
}
@ -277,8 +285,8 @@ pub fn draw_text_bubble_mapspace(
*c,
&Polygon::rectangle_topleft(
Pt2D::new(top_left.x(), top_left.y() + y),
total_width,
height,
Distance::meters(total_width),
Distance::meters(height),
),
);
}

View File

@ -1,6 +1,5 @@
use crate::{Bounds, HashablePt2D, Pt2D};
use crate::{Bounds, Distance, HashablePt2D, Pt2D};
use serde_derive::{Deserialize, Serialize};
use std::f64;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Polygon {
@ -114,7 +113,7 @@ impl Polygon {
Bounds::from(&self.points)
}
pub fn translate(&self, dx: f64, dy: f64) -> Polygon {
pub fn translate(&self, dx: Distance, dy: Distance) -> Polygon {
Polygon {
points: self.points.iter().map(|pt| pt.offset(dx, dy)).collect(),
indices: self.indices.clone(),
@ -133,17 +132,17 @@ impl Polygon {
Pt2D::center(&pts.iter().map(|pt| Pt2D::from(*pt)).collect())
}
pub fn rectangle(center: Pt2D, width: f64, height: f64) -> Polygon {
pub fn rectangle(center: Pt2D, width: Distance, height: Distance) -> Polygon {
Polygon::rectangle_topleft(center.offset(-width / 2.0, -height / 2.0), width, height)
}
pub fn rectangle_topleft(top_left: Pt2D, width: f64, height: f64) -> Polygon {
pub fn rectangle_topleft(top_left: Pt2D, width: Distance, height: Distance) -> Polygon {
Polygon {
points: vec![
top_left,
top_left.offset(width, 0.0),
top_left.offset(width, Distance::ZERO),
top_left.offset(width, height),
top_left.offset(0.0, height),
top_left.offset(Distance::ZERO, height),
],
indices: vec![0, 1, 2, 2, 3, 0],
}

View File

@ -115,8 +115,8 @@ impl Pt2D {
Angle::new((to.y() - self.y()).atan2(to.x() - self.x()))
}
pub fn offset(self, dx: f64, dy: f64) -> Pt2D {
Pt2D::new(self.x() + dx, self.y() + dy)
pub fn offset(self, dx: Distance, dy: Distance) -> Pt2D {
Pt2D::new(self.x() + dx.inner_meters(), self.y() + dy.inner_meters())
}
pub fn center(pts: &Vec<Pt2D>) -> Pt2D {