Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions backend/benches/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ fn heuristic(c: &mut Criterion) {
let end = universe.star_by_name(&"OVD-1SM".to_string()).unwrap();

c.bench_function(
format!("heuristic ({} connections)", start.connections.len()).as_str(),
format!(
"heuristic ({} connections)",
universe.connections[&start.id].len()
)
.as_str(),
|b| {
b.iter(|| {
start
.connections
universe.connections[&start.id]
.iter()
.map(|conn| eftb::calc::path::heuristic(&universe, conn, end))
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion backend/src/calc/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn calc_exit(universe: &Universe, start: &Star, jump_distance: Meters) -> Ve

gate_network.iter().for_each(|id| {
let star = &universe.star_map[id];
for conn in &star.connections {
for conn in &universe.connections[&star.id] {
if conn.conn_type == ConnType::Jump {
let other = &universe.star_map[&conn.target];
let distance = star.distance(other);
Expand Down
18 changes: 7 additions & 11 deletions backend/src/calc/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ pub fn successors(
optimize: PathOptimize,
use_smart_gates: bool,
) -> Vec<(Connection, f64)> {
let star = universe
.star_map
.get(&conn.target)
.expect("Target star not found in universe");
star.connections
universe.connections[&conn.target]
.iter()
// take gates and short jumps - stop searching after we
// find a long jump
Expand Down Expand Up @@ -130,7 +126,7 @@ mod tests {
let universe = Universe::tiny_test();
assert_eq!(
call_calc_path(&universe, 1, 4, 25.0, PathOptimize::Fuel, true),
PathResult::Found(vec![universe.star_map[&1].connections[0].clone()])
PathResult::Found(vec![universe.connections[&1][0].clone()])
);
}

Expand All @@ -141,8 +137,8 @@ mod tests {
assert_eq!(
call_calc_path(&universe, 4, 2, 25.0, PathOptimize::Fuel, false),
PathResult::Found(vec![
universe.star_map[&4].connections[0].clone(),
universe.star_map[&1].connections[1].clone(),
universe.connections[&4][0].clone(),
universe.connections[&1][1].clone(),
])
);
}
Expand All @@ -153,7 +149,7 @@ mod tests {
let universe = Universe::tiny_test();
assert_eq!(
call_calc_path(&universe, 2, 4, 25.0, PathOptimize::Distance, false),
PathResult::Found(vec![universe.star_map[&2].connections[2].clone(),])
PathResult::Found(vec![universe.connections[&2][2].clone(),])
);
}

Expand All @@ -163,7 +159,7 @@ mod tests {
let universe = Universe::tiny_test();
assert_eq!(
call_calc_path(&universe, 4, 3, 25.0, PathOptimize::Hops, false),
PathResult::Found(vec![universe.star_map[&4].connections[4].clone()])
PathResult::Found(vec![universe.connections[&4][4].clone()])
);
}

Expand All @@ -173,7 +169,7 @@ mod tests {
let universe = Universe::tiny_test();
assert_eq!(
call_calc_path(&universe, 4, 3, 25.0, PathOptimize::Hops, true),
PathResult::Found(vec![universe.star_map[&4].connections[1].clone()])
PathResult::Found(vec![universe.connections[&4][1].clone()])
);
}
}
Expand Down