mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
implementing draw_line and draw_rounded_line directly
This commit is contained in:
parent
88ef720f16
commit
1d9f3320fa
@ -75,21 +75,13 @@ impl<'a> GfxCtx<'a> {
|
|||||||
// Use graphics::Line internally for now, but make it easy to switch to something else by
|
// Use graphics::Line internally for now, but make it easy to switch to something else by
|
||||||
// picking this API now.
|
// picking this API now.
|
||||||
pub fn draw_line(&mut self, color: Color, thickness: f64, line: &geom::Line) {
|
pub fn draw_line(&mut self, color: Color, thickness: f64, line: &geom::Line) {
|
||||||
graphics::Line::new(color.0, thickness).draw(
|
self.draw_polygon(color, &line.to_polyline().make_polygons_blindly(thickness));
|
||||||
line_to_array(line),
|
|
||||||
&self.ctx.draw_state,
|
|
||||||
self.ctx.transform,
|
|
||||||
self.gfx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &geom::Line) {
|
pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &geom::Line) {
|
||||||
graphics::Line::new_round(color.0, thickness).draw(
|
self.draw_line(color, thickness, line);
|
||||||
line_to_array(line),
|
self.draw_circle(color, &geom::Circle::new(line.pt1(), thickness / 2.0));
|
||||||
&self.ctx.draw_state,
|
self.draw_circle(color, &geom::Circle::new(line.pt2(), thickness / 2.0));
|
||||||
self.ctx.transform,
|
|
||||||
self.gfx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_arrow(&mut self, color: Color, thickness: f64, head_size: f64, line: &geom::Line) {
|
pub fn draw_arrow(&mut self, color: Color, thickness: f64, head_size: f64, line: &geom::Line) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{line_intersection, Angle, Pt2D, EPSILON_DIST};
|
use crate::{line_intersection, Angle, PolyLine, Pt2D, EPSILON_DIST};
|
||||||
use dimensioned::si;
|
use dimensioned::si;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -26,6 +26,10 @@ impl Line {
|
|||||||
vec![self.0, self.1]
|
vec![self.0, self.1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_polyline(&self) -> PolyLine {
|
||||||
|
PolyLine::new(self.points())
|
||||||
|
}
|
||||||
|
|
||||||
// TODO valid to do euclidean distance on world-space points that're formed from
|
// TODO valid to do euclidean distance on world-space points that're formed from
|
||||||
// Haversine?
|
// Haversine?
|
||||||
pub fn length(&self) -> si::Meter<f64> {
|
pub fn length(&self) -> si::Meter<f64> {
|
||||||
|
@ -152,7 +152,7 @@ impl PolyLine {
|
|||||||
|
|
||||||
if self.pts.len() == 2 {
|
if self.pts.len() == 2 {
|
||||||
let l = Line::new(self.pts[0], self.pts[1]).shift(width);
|
let l = Line::new(self.pts[0], self.pts[1]).shift(width);
|
||||||
return PolyLine::new(vec![l.pt1(), l.pt2()]);
|
return l.to_polyline();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result: Vec<Pt2D> = Vec::new();
|
let mut result: Vec<Pt2D> = Vec::new();
|
||||||
@ -213,7 +213,7 @@ impl PolyLine {
|
|||||||
fn shift_blindly_with_sharp_angles(&self, width: f64) -> PolyLine {
|
fn shift_blindly_with_sharp_angles(&self, width: f64) -> PolyLine {
|
||||||
if self.pts.len() == 2 {
|
if self.pts.len() == 2 {
|
||||||
let l = Line::new(self.pts[0], self.pts[1]).shift(width);
|
let l = Line::new(self.pts[0], self.pts[1]).shift(width);
|
||||||
return PolyLine::new(vec![l.pt1(), l.pt2()]);
|
return l.to_polyline();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result: Vec<Pt2D> = Vec::new();
|
let mut result: Vec<Pt2D> = Vec::new();
|
||||||
|
@ -66,7 +66,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PolyLine::new(vec![pt1, pt2]).shift(width),
|
PolyLine::new(vec![pt1, pt2]).shift(width),
|
||||||
Some(PolyLine::new(vec![l.pt1(), l.pt2()]))
|
Some(l.to_polyline())
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user