Skip to content

Commit

Permalink
Fixing typos and substitute functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Groneschild committed Jun 19, 2024
1 parent dd884d1 commit 59c7116
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
14 changes: 7 additions & 7 deletions native_app/src/newgui/tools/roadbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn roadbuild(sim: &Simulation, uiworld: &UiWorld) {

let grid_size = 20.0;
let unproj = unwrap_ret!(inp.unprojected);
let mut interpoliation_points: Vec<Vec3> = Vec::new();
let mut interpolation_points: Vec<Vec3> = Vec::new();
let nosnapping = inp.act.contains(&InputAction::NoSnapping);

let mouse_height = match (state.height_reference, state.build_state) {
Expand All @@ -66,8 +66,8 @@ pub fn roadbuild(sim: &Simulation, uiworld: &UiWorld) {
unproj.xy().snap(grid_size, grid_size).z(mouse_height)
},
Snapping::SnapToAngle => {
interpoliation_points = state.update_points(map, unproj);
interpoliation_points.iter()
interpolation_points = state.posible_interpolations(map, unproj);
interpolation_points.iter()
.map(|point| {point.xy()})
.filter_map(|point| {
let distance = point.distance(unproj.xy());
Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn roadbuild(sim: &Simulation, uiworld: &UiWorld) {
}
}

state.update_drawing(map, immdraw, cur_proj, patwidth, is_valid, points, interpoliation_points);
state.update_drawing(map, immdraw, cur_proj, patwidth, is_valid, points, interpolation_points);

if is_valid && inp.just_act.contains(&InputAction::Select) {
log::info!("left clicked with state {:?} and {:?}", state.build_state, cur_proj.kind);
Expand Down Expand Up @@ -450,7 +450,7 @@ impl RoadBuildResource {
patwidth: f32,
is_valid: bool,
points: Option<PolyLine3>,
interpoliation_points: Vec<Vec3>,
interpolation_points: Vec<Vec3>,
) {
let mut proj_pos = proj.pos;
proj_pos.z += 0.4;
Expand All @@ -460,7 +460,7 @@ impl RoadBuildResource {
simulation::colors().gui_danger
};

interpoliation_points.iter().for_each(|p|{
interpolation_points.iter().for_each(|p|{
immdraw.circle(*p, 2.0);
});

Expand Down Expand Up @@ -513,7 +513,7 @@ impl RoadBuildResource {
immdraw.polyline(p.into_vec(), patwidth, false).color(col);
}

pub fn update_points(
pub fn posible_interpolations(
&self,
map: &Map,
mousepos: Vec3,
Expand Down
25 changes: 11 additions & 14 deletions simulation/src/map/objects/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,21 @@ impl Intersection {
}

fn interface_calc_numerically(&self, w1: f32, w2: f32, r1: &Road, r2: &Road) -> f32 {
let w = (w1+w2)* 0.75;
let w: f32 = (w1+w2)* 0.80;

let mut points1: Vec<(Vec3, Vec3)> = r1.points().equipoints_dir(1.0, true).collect();
let mut points2: Vec<(Vec3, Vec3)> = r2.points().equipoints_dir(1.0, true).collect();
let mut points1: Vec<(Vec3, Vec3)> = r1.points()
.points_dirs_along((1..r1.points().length() as i32).map(|d| d as f32)).collect();
let mut points2: Vec<(Vec3, Vec3)> = r2.points()
.points_dirs_along((1..r2.points().length() as i32).map(|d| d as f32)).collect();

if r1.dst == self.id { points1.reverse(); }
if r2.dst == self.id { points2.reverse(); }
if !(r1.src == self.id) { points1.reverse(); }
if !(r2.src == self.id) { points2.reverse(); }

let points = points1.into_iter().zip(points2)
points1.into_iter().zip(points2)
.map(|((p1,_),(p2,_))| (p1.xy(), p2.xy()) )
.find(|p| p.0.distance(p.1) > w );

if let Some(p) = points {
(self.pos.xy().distance(p.0) + self.pos.xy().distance(p.0)) * 0.5
} else {
50.0
}

.find(|p| p.0.distance(p.1) > w )
.and_then(|p| Some((self.pos.xy().distance(p.0)+self.pos.xy().distance(p.0))*0.5))
.unwrap_or(50.0)
}

pub fn empty_interface(width: f32) -> f32 {
Expand Down

0 comments on commit 59c7116

Please sign in to comment.