use new polygons for parcels...

This commit is contained in:
Dustin Carlino 2018-06-25 13:29:31 -07:00
parent 1f34f588a3
commit fef18fbf2f
3 changed files with 9 additions and 7 deletions

View File

@ -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<Pt2D>, thickness: f64, color: Color) {
}
}
fn draw_polygon(g: &mut GfxCtx, pts: Vec<Pt2D>, 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<Vec2d>, 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 {

View File

@ -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(),
}

View File

@ -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<Pt2D>, width: f64) -> Vec<Vec<Pt2D>> {
// return Vec2d since this is only used for drawing right now
pub fn polygons_for_polyline(center_pts: &Vec<Pt2D>, width: f64) -> Vec<Vec<Vec2d>> {
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<Pt2D>, width: f64) -> Vec<Vec<Pt2D
]);
result.push(vec![side2[high_idx], side2[high_idx - 1], side1[high_idx]]);
}
result
result.iter().map(|pts| pts.iter().map(|pt| pt.to_vec()).collect()).collect()
}
pub fn shift_polyline(width: f64, pts: &Vec<Pt2D>) -> Vec<Pt2D> {