From fef18fbf2f0dcc94524131406a2b888f45705c2d Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 25 Jun 2018 13:29:31 -0700 Subject: [PATCH] use new polygons for parcels... --- editor/src/experimental.rs | 6 +++--- editor/src/render/parcel.rs | 4 ++-- map_model/src/polyline.rs | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/editor/src/experimental.rs b/editor/src/experimental.rs index 5cd724f0f0..6e695aa29e 100644 --- a/editor/src/experimental.rs +++ b/editor/src/experimental.rs @@ -4,6 +4,7 @@ use ezgui::canvas::Canvas; use ezgui::input::UserInput; use graphics; use graphics::types::Color; +use graphics::math::Vec2d; use gui; use map_model::{polygons_for_polyline, shift_polyline, Pt2D}; use piston::input::Key; @@ -176,9 +177,8 @@ fn draw_polyline(g: &mut GfxCtx, pts: Vec, thickness: f64, color: Color) { } } -fn draw_polygon(g: &mut GfxCtx, pts: Vec, color: Color) { - let tuples: Vec<[f64; 2]> = pts.iter().map(|pt| [pt.x(), pt.y()]).collect(); - graphics::Polygon::new(color).draw(&tuples, &g.ctx.draw_state, g.ctx.transform, g.gfx); +fn draw_polygon(g: &mut GfxCtx, pts: Vec, color: Color) { + graphics::Polygon::new(color).draw(&pts, &g.ctx.draw_state, g.ctx.transform, g.gfx); } fn angle_degrees(from: Pt2D, to: Pt2D) -> f64 { diff --git a/editor/src/render/parcel.rs b/editor/src/render/parcel.rs index 07d36bbd44..99a0150d8c 100644 --- a/editor/src/render/parcel.rs +++ b/editor/src/render/parcel.rs @@ -21,9 +21,9 @@ impl DrawParcel { pub fn new(p: &map_model::Parcel) -> DrawParcel { DrawParcel { id: p.id, - boundary_polygons: geometry::thick_multiline( - &geometry::ThickLine::Centered(PARCEL_BOUNDARY_THICKNESS), + boundary_polygons: map_model::polygons_for_polyline( &p.points, + PARCEL_BOUNDARY_THICKNESS ), fill_polygon: p.points.iter().map(|pt| [pt.x(), pt.y()]).collect(), } diff --git a/map_model/src/polyline.rs b/map_model/src/polyline.rs index 79deb1706b..57b1600947 100644 --- a/map_model/src/polyline.rs +++ b/map_model/src/polyline.rs @@ -1,5 +1,6 @@ use Pt2D; use std::f64; +use graphics::math::Vec2d; // TODO unsure why this doesn't work. maybe see if mouse is inside polygon to check it out? /*fn polygon_for_polyline(center_pts: &Vec<(f64, f64)>, width: f64) -> Vec<[f64; 2]> { @@ -15,7 +16,8 @@ use std::f64; // TODO why do we need a bunch of triangles? why doesn't the single polygon triangulate correctly? // TODO ideally, detect when the polygon overlaps itself due to sharp lines and too much width -pub fn polygons_for_polyline(center_pts: &Vec, width: f64) -> Vec> { +// return Vec2d since this is only used for drawing right now +pub fn polygons_for_polyline(center_pts: &Vec, width: f64) -> Vec> { let side1 = shift_polyline(width / 2.0, center_pts); let mut reversed_center_pts = center_pts.clone(); reversed_center_pts.reverse(); @@ -31,7 +33,7 @@ pub fn polygons_for_polyline(center_pts: &Vec, width: f64) -> Vec) -> Vec {