Skip to content

Commit

Permalink
allow rail to be much closer
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 30, 2023
1 parent a891eb0 commit 2650b4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
35 changes: 14 additions & 21 deletions egregoria/src/map/objects/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ impl Intersection {
let r1 = &roads[r1_id];
let r2 = &roads[r2_id];

let width1 = r1.width * 0.5;
let width2 = r2.width * 0.5;
let min_dist =
Self::interface_calc(r1.width, r2.width, r1.dir_from(id), r2.dir_from(id));
roads[r1_id].max_interface(id, min_dist);
roads[r2_id].max_interface(id, min_dist);
}
}

let w = width1.hypot(width2);
fn interface_calc(w1: f32, w2: f32, dir1: Vec2, dir2: Vec2) -> f32 {
let hwidth1 = w1 * 0.5;
let hwidth2 = w2 * 0.5;

let dir1 = r1.dir_from(id);
let dir2 = r2.dir_from(id);
let w = hwidth1.hypot(hwidth2);

let d = dir1.dot(dir2).clamp(0.0, 1.0);
let sin = (1.0 - d * d).sqrt();
let d = dir1.dot(dir2).clamp(0.0, 1.0);
let sin = (1.0 - d * d).sqrt();

let min_dist = w * 1.1 / sin;
roads[r1_id].max_interface(id, min_dist);
roads[r2_id].max_interface(id, min_dist);
}
(w * 1.1 / sin).min(30.0)
}

pub fn empty_interface(width: f32) -> f32 {
Expand All @@ -170,16 +172,7 @@ impl Intersection {
let id = self.id;
for &r1_id in &self.roads {
let r1 = unwrap_cont!(roads.get(r1_id));

let width1 = r1.width * 0.5;
let w = width1.hypot(width);
let dir1 = r1.dir_from(id);

let d = dir1.dot(dir).clamp(0.0, 1.0);
let sin = (1.0 - d * d).sqrt();

let min_dist = w * 1.1 / sin;
max_inter = max_inter.max(min_dist);
max_inter = max_inter.max(Self::interface_calc(r1.width, width, r1.dir_from(id), dir));
}
max_inter
}
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/roadbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub fn roadbuild(goria: &Egregoria, uiworld: &mut UiWorld) {

fn check_angle(map: &Map, from: MapProject, to: Vec2, is_rail: bool) -> bool {
let max_turn_angle = if is_rail {
10.0 * std::f32::consts::PI / 180.0
1.0 * std::f32::consts::PI / 180.0
} else {
30.0 * std::f32::consts::PI / 180.0
};
Expand Down

0 comments on commit 2650b4b

Please sign in to comment.