Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 13, 2023
1 parent ca9b731 commit 8060956
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion egregoria/src/map/objects/parking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ParkingSpots {
}

pub fn random_spot(&self, rng: u64) -> Option<ParkingSpotID> {
if self.spots.len() == 0 {
if self.spots.is_empty() {
return None;
}
let mut iter = self.spots.keys();
Expand Down
4 changes: 2 additions & 2 deletions egregoria/src/map_dynamic/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ mod tests {
assert!(lanes.contains(disp.lanes.keys().next().unwrap()));

// second insert in same lane
let ent2 = mk_ent(1 << 32 + 1);
let ent2 = mk_ent((1 << 32) + 1);
disp.register(ent2, &map, Vec3::new(0.0, 0.0, 0.0));
assert_eq!(disp.positions.len(), 2);
assert_eq!(disp.lanes.len(), 1);
assert_eq!(disp.lanes.values().next().unwrap(), &vec![ent, ent2]);

// insert in another lane
let ent3 = mk_ent(1 << 32 + 2);
let ent3 = mk_ent((1 << 32) + 2);
disp.register(ent3, &map, Vec3::new(100.0, 10.0, 0.0));
assert_eq!(disp.positions.len(), 3);
assert_eq!(disp.lanes.len(), 2);
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/map_dynamic/itinerary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Itinerary {
let rng = common::hash_u64((tick.0, r.cur.kind));

if let Some((lp, new_route)) =
Self::random_route(rng, position, tick, &map, pathkind)
Self::random_route(rng, position, tick, map, pathkind)
{
self.reversed_local_path = lp;
*r = new_route;
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/tests/test_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use common::saveload::{Bincode, Encoder};
use geom::vec3;
use quickcheck::{Arbitrary, Gen};

static REPLAY: &'static [u8] = include_bytes!("world_replay.json");
static REPLAY: &[u8] = include_bytes!("world_replay.json");

fn check_coherent(map: &Map, proj: MapProject) {
match proj.kind {
Expand Down
93 changes: 46 additions & 47 deletions wgpu_engine/src/geometry/earcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ fn earcut_inner(
return;
}

if hole_indices.len() > 0 {
if !hole_indices.is_empty() {
outer_node = eliminate_holes(&mut ll, data, hole_indices, outer_node);
}

Expand Down Expand Up @@ -1115,12 +1115,12 @@ mod tests {

// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON)
// into a form Earcut accepts
pub fn flatten(data: &Vec<Vec<Vec<f32>>>) -> (Vec<f32>, Vec<usize>, usize) {
pub fn flatten(data: &[Vec<Vec<f32>>]) -> (Vec<f32>, Vec<usize>, usize) {
(
data.iter()
.cloned()
.flatten()
.flatten()
.cloned()
.collect::<Vec<f32>>(), // flat data
data.iter()
.take(data.len() - 1)
Expand Down Expand Up @@ -1174,24 +1174,19 @@ mod tests {
n.z,
));
}
return s;
s
}

fn deviation(
data: &Vec<f32>,
hole_indices: &Vec<usize>,
dims: usize,
triangles: &Vec<usize>,
) -> f32 {
fn deviation(data: &[f32], hole_indices: &[usize], dims: usize, triangles: &[usize]) -> f32 {
if DIM != dims {
return f32::NAN;
}
let mut indices = hole_indices.clone();
let mut indices: Vec<_> = hole_indices.to_vec();
indices.push(data.len() / DIM);
let (ix, iy) = (indices.iter(), indices.iter().skip(1));
let body_area = signed_area(&data, 0, indices[0] * DIM).abs();
let body_area = signed_area(data, 0, indices[0] * DIM).abs();
let polygon_area = ix.zip(iy).fold(body_area, |a, (ix, iy)| {
a - signed_area(&data, ix * DIM, iy * DIM).abs()
a - signed_area(data, ix * DIM, iy * DIM).abs()
});

let i = triangles.iter().skip(0).step_by(3).map(|x| x * DIM);
Expand All @@ -1210,7 +1205,7 @@ mod tests {

fn cycles_report(ll: &LinkedLists) -> String {
if ll.nodes.len() == 1 {
return format!("[]");
return "[]".to_string();
}
let mut markv: Vec<usize> = Vec::new();
markv.resize(ll.nodes.len(), 0);
Expand Down Expand Up @@ -1370,10 +1365,10 @@ mod tests {

let m = vec![0.0, 0.0, 0.5, 0.5, 1.0, 0.0, 0.5, 0.4];
let (ll, _) = linked_list(&m, 0, m.len(), true);
assert!(is_ear(&ll, 4, 1, 2) == false);
assert!(is_ear(&ll, 1, 2, 3) == true);
assert!(is_ear(&ll, 2, 3, 4) == false);
assert!(is_ear(&ll, 3, 4, 1) == true);
assert!(!is_ear(&ll, 4, 1, 2));
assert!(is_ear(&ll, 1, 2, 3));
assert!(!is_ear(&ll, 2, 3, 4));
assert!(is_ear(&ll, 3, 4, 1));

let m = vec![0.0, 0.0, 0.5, 0.5, 1.0, 0.0];
let (ll, _) = linked_list(&m, 0, m.len(), true);
Expand Down Expand Up @@ -1511,10 +1506,10 @@ mod tests {
let m = vec![0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0];
let (ll, _) = linked_list(&m, 0, m.len(), true);

assert!(false == intersects_polygon(&ll, ll.noderef(0), ll.noderef(2)));
assert!(false == intersects_polygon(&ll, ll.noderef(2), ll.noderef(0)));
assert!(false == intersects_polygon(&ll, ll.noderef(1), ll.noderef(3)));
assert!(false == intersects_polygon(&ll, ll.noderef(3), ll.noderef(1)));
assert!(!intersects_polygon(&ll, ll.noderef(0), ll.noderef(2)));
assert!(!intersects_polygon(&ll, ll.noderef(2), ll.noderef(0)));
assert!(!intersects_polygon(&ll, ll.noderef(1), ll.noderef(3)));
assert!(!intersects_polygon(&ll, ll.noderef(3), ll.noderef(1)));

let m = vec![0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.1, 0.1, 0.9, 1.0, 0.0, 1.0];
let (ll, _) = linked_list(&m, 0, m.len(), true);
Expand Down Expand Up @@ -1547,35 +1542,39 @@ mod tests {
);
};
}
ti!(false, 0 + 1, 2 + 1, 0 + 1, 1 + 1);
ti!(false, 0 + 1, 2 + 1, 1 + 1, 2 + 1);
ti!(false, 0 + 1, 2 + 1, 2 + 1, 3 + 1);
ti!(false, 0 + 1, 2 + 1, 3 + 1, 0 + 1);
ti!(true, 0 + 1, 2 + 1, 3 + 1, 1 + 1);
ti!(true, 0 + 1, 2 + 1, 1 + 1, 3 + 1);
ti!(true, 2 + 1, 0 + 1, 3 + 1, 1 + 1);
ti!(true, 2 + 1, 0 + 1, 1 + 1, 3 + 1);
ti!(false, 0 + 1, 1 + 1, 2 + 1, 3 + 1);
ti!(false, 1 + 1, 0 + 1, 2 + 1, 3 + 1);
ti!(false, 0 + 1, 0 + 1, 2 + 1, 3 + 1);
ti!(false, 0 + 1, 1 + 1, 3 + 1, 2 + 1);
ti!(false, 1 + 1, 0 + 1, 3 + 1, 2 + 1);

ti!(true, 0 + 1, 2 + 1, 2 + 1, 0 + 1); // special cases
ti!(true, 0 + 1, 2 + 1, 0 + 1, 2 + 1);
ti!(false, 1, 2 + 1, 1, 1 + 1);
ti!(false, 1, 2 + 1, 1 + 1, 2 + 1);
ti!(false, 1, 2 + 1, 2 + 1, 3 + 1);
ti!(false, 1, 2 + 1, 3 + 1, 1);
ti!(true, 1, 2 + 1, 3 + 1, 1 + 1);
ti!(true, 1, 2 + 1, 1 + 1, 3 + 1);
ti!(true, 2 + 1, 1, 3 + 1, 1 + 1);
ti!(true, 2 + 1, 1, 1 + 1, 3 + 1);
ti!(false, 1, 1 + 1, 2 + 1, 3 + 1);
ti!(false, 1 + 1, 1, 2 + 1, 3 + 1);
ti!(false, 1, 1, 2 + 1, 3 + 1);
ti!(false, 1, 1 + 1, 3 + 1, 2 + 1);
ti!(false, 1 + 1, 1, 3 + 1, 2 + 1);

ti!(true, 1, 2 + 1, 2 + 1, 1); // special cases
ti!(true, 1, 2 + 1, 1, 2 + 1);

let m = vec![0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.1, 0.1, 0.9, 1.0, 0.0, 1.0];
let (ll, _) = linked_list(&m, 0, m.len(), true);
assert_eq!(
false,
pseudo_intersects(&ll.nodes[4], &ll.nodes[5], &ll.nodes[1], &ll.nodes[3])
);
assert!(!pseudo_intersects(
&ll.nodes[4],
&ll.nodes[5],
&ll.nodes[1],
&ll.nodes[3]
));

// special case
assert_eq!(
true,
pseudo_intersects(&ll.nodes[4], &ll.nodes[5], &ll.nodes[3], &ll.nodes[1])
);
assert!(pseudo_intersects(
&ll.nodes[4],
&ll.nodes[5],
&ll.nodes[3],
&ll.nodes[1]
));
}

#[test]
Expand Down Expand Up @@ -1749,7 +1748,7 @@ mod tests {
triangles.push(c);
});
assert!(cycle_len(&ll, 1) == 7);
assert!(triangles.len() == 0);
assert!(triangles.is_empty());

// second test - we have three points that immediately cause
// self intersection. so it should, in theory, detect and clean
Expand Down

0 comments on commit 8060956

Please sign in to comment.