mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
explicitly making shift right/left for Line
This commit is contained in:
parent
bc6a61fc74
commit
caf4006837
@ -139,8 +139,8 @@ impl Renderable for DrawLane {
|
||||
|
||||
// TODO this always does it at pt1
|
||||
fn perp_line(l: Line, length: f64) -> Line {
|
||||
let pt1 = l.shift(length / 2.0).pt1();
|
||||
let pt2 = l.reverse().shift(length / 2.0).pt2();
|
||||
let pt1 = l.shift_right(length / 2.0).pt1();
|
||||
let pt2 = l.shift_left(length / 2.0).pt1();
|
||||
Line::new(pt1, pt2)
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ fn calculate_stop_sign_line(road: &Road, lane: &Lane, map: &Map) -> Option<Marki
|
||||
// Don't clobber the yellow line.
|
||||
let line = if road.is_canonical_lane(lane.id) {
|
||||
perp_line(
|
||||
Line::new(pt1, pt2).shift(BIG_ARROW_THICKNESS / 2.0),
|
||||
Line::new(pt1, pt2).shift_right(BIG_ARROW_THICKNESS / 2.0),
|
||||
LANE_THICKNESS - BIG_ARROW_THICKNESS,
|
||||
)
|
||||
} else {
|
||||
|
@ -161,7 +161,7 @@ impl DrawCrosswalk {
|
||||
|
||||
// TODO copied from DrawLane
|
||||
fn perp_line(l: Line, length: f64) -> Line {
|
||||
let pt1 = l.shift(length / 2.0).pt1();
|
||||
let pt2 = l.reverse().shift(length / 2.0).pt2();
|
||||
let pt1 = l.shift_right(length / 2.0).pt1();
|
||||
let pt2 = l.shift_left(length / 2.0).pt1();
|
||||
Line::new(pt1, pt2)
|
||||
}
|
||||
|
@ -53,14 +53,6 @@ impl Line {
|
||||
line_intersection(self, other)
|
||||
}
|
||||
|
||||
pub fn shift(&self, width: f64) -> Line {
|
||||
let angle = self.angle().rotate_degs(90.0);
|
||||
Line(
|
||||
self.pt1().project_away(width, angle),
|
||||
self.pt2().project_away(width, angle),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn shift_right(&self, width: f64) -> Line {
|
||||
assert!(width >= 0.0);
|
||||
let angle = self.angle().rotate_degs(90.0);
|
||||
|
@ -157,7 +157,7 @@ impl PolyLine {
|
||||
}
|
||||
|
||||
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_right(width);
|
||||
return l.to_polyline();
|
||||
}
|
||||
|
||||
@ -170,8 +170,8 @@ impl PolyLine {
|
||||
loop {
|
||||
let pt3_raw = self.pts[pt3_idx];
|
||||
|
||||
let l1 = Line::new(pt1_raw, pt2_raw).shift(width);
|
||||
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
||||
let l1 = Line::new(pt1_raw, pt2_raw).shift_right(width);
|
||||
let l2 = Line::new(pt2_raw, pt3_raw).shift_right(width);
|
||||
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
||||
// original geometry is redundant.
|
||||
let pt2_shift = line_intersection(&l1, &l2).unwrap_or_else(|| l1.pt2());
|
||||
@ -220,7 +220,7 @@ impl PolyLine {
|
||||
// Doesn't massage sharp twists into more points. For polygon rendering.
|
||||
fn shift_blindly_with_sharp_angles(&self, width: f64) -> PolyLine {
|
||||
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_right(width);
|
||||
return l.to_polyline();
|
||||
}
|
||||
|
||||
@ -233,8 +233,8 @@ impl PolyLine {
|
||||
loop {
|
||||
let pt3_raw = self.pts[pt3_idx];
|
||||
|
||||
let l1 = Line::new(pt1_raw, pt2_raw).shift(width);
|
||||
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
||||
let l1 = Line::new(pt1_raw, pt2_raw).shift_right(width);
|
||||
let l2 = Line::new(pt2_raw, pt3_raw).shift_right(width);
|
||||
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
||||
// original geometry is redundant.
|
||||
let pt2_shift = line_intersection(&l1, &l2).unwrap_or_else(|| l1.pt2());
|
||||
|
@ -32,7 +32,7 @@ impl Pt2D {
|
||||
|
||||
// TODO This is a small first step...
|
||||
pub fn approx_eq(&self, other: Pt2D) -> bool {
|
||||
let eps = 0.0000001;
|
||||
let eps = 0.000_000_1;
|
||||
(self.x - other.x).abs() < eps && (self.y - other.y) < eps
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ fn make_walking_turns(i: &Intersection, all_roads: &Vec<&Road>, lanes: &Vec<&Lan
|
||||
// Make the crosswalk to the other side
|
||||
if let Some(l2) = get_outgoing_sidewalk(wraparound_get(&roads, idx1).0, lanes, i.id) {
|
||||
// Jut out a bit into the intersection, cross over, then jut back in.
|
||||
let line = Line::new(l1.last_pt(), l2.first_pt()).shift(LANE_THICKNESS / 2.0);
|
||||
let line = Line::new(l1.last_pt(), l2.first_pt()).shift_right(LANE_THICKNESS / 2.0);
|
||||
let geom_fwds =
|
||||
PolyLine::new(vec![l1.last_pt(), line.pt1(), line.pt2(), l2.first_pt()]);
|
||||
|
||||
|
@ -29,23 +29,23 @@ pub fn run(t: &mut TestRunner) {
|
||||
let pt5 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
|
||||
|
||||
let width = 50.0;
|
||||
let pt1_s = Line::new(pt1, pt2).shift(width).pt1();
|
||||
let pt1_s = Line::new(pt1, pt2).shift_right(width).pt1();
|
||||
let pt2_s = line_intersection(
|
||||
&Line::new(pt1, pt2).shift(width),
|
||||
&Line::new(pt2, pt3).shift(width),
|
||||
&Line::new(pt1, pt2).shift_right(width),
|
||||
&Line::new(pt2, pt3).shift_right(width),
|
||||
)
|
||||
.unwrap();
|
||||
let pt3_s = line_intersection(
|
||||
&Line::new(pt2, pt3).shift(width),
|
||||
&Line::new(pt3, pt4).shift(width),
|
||||
&Line::new(pt2, pt3).shift_right(width),
|
||||
&Line::new(pt3, pt4).shift_right(width),
|
||||
)
|
||||
.unwrap();
|
||||
let pt4_s = line_intersection(
|
||||
&Line::new(pt3, pt4).shift(width),
|
||||
&Line::new(pt4, pt5).shift(width),
|
||||
&Line::new(pt3, pt4).shift_right(width),
|
||||
&Line::new(pt4, pt5).shift_right(width),
|
||||
)
|
||||
.unwrap();
|
||||
let pt5_s = Line::new(pt4, pt5).shift(width).pt2();
|
||||
let pt5_s = Line::new(pt4, pt5).shift_right(width).pt2();
|
||||
|
||||
assert_eq!(
|
||||
PolyLine::new(vec![pt1, pt2, pt3, pt4, pt5]).shift(width),
|
||||
@ -62,7 +62,7 @@ pub fn run(t: &mut TestRunner) {
|
||||
let pt2 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
|
||||
|
||||
let width = 50.0;
|
||||
let l = Line::new(pt1, pt2).shift(width);
|
||||
let l = Line::new(pt1, pt2).shift_right(width);
|
||||
|
||||
assert_eq!(
|
||||
PolyLine::new(vec![pt1, pt2]).shift(width),
|
||||
|
Loading…
Reference in New Issue
Block a user