Skip to content

Commit 9747d34

Browse files
committed
Allow disabling processor range check
1 parent d898de4 commit 9747d34

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- ubuntu-latest
1515
- windows-latest
1616
features:
17-
- std
17+
- std,enforce_processor_range
1818
- no_std
1919
- no_std,serde_alloc
2020
runs-on: ${{ matrix.os }}
@@ -25,7 +25,7 @@ jobs:
2525

2626
- uses: Swatinem/rust-cache@v2
2727
with:
28-
save-if: ${{ matrix.features == 'std' }}
28+
save-if: ${{ matrix.features == 'std,enforce_processor_range' }}
2929

3030
- name: Run tests
3131
run: cargo test --no-default-features --features ${{ matrix.features }}

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pretty_assertions = "1.4.1"
7676
velcro = "0.5.4"
7777

7878
[features]
79-
default = ["std"]
79+
default = ["enforce_processor_range", "std"]
8080
embedded_graphics = [
8181
"dep:eg-font-converter",
8282
"dep:embedded-graphics",
@@ -86,6 +86,7 @@ no_std = [
8686
"dep:serde-json-core",
8787
"lazy_static/spin_no_std",
8888
]
89+
enforce_processor_range = []
8990
serde_alloc = [
9091
"serde/alloc",
9192
]

src/vm/processor.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,25 @@ impl Processor {
6868

6969
// check range
7070

71-
let self_size = (building.block.size as f64) / 2.;
72-
let other_size = (other.block.size as f64) / 2.;
73-
74-
let here = (
75-
building.position.x as f64 + self_size,
76-
building.position.y as f64 + self_size,
77-
);
78-
let there = (
79-
other.position.x as f64 + other_size,
80-
other.position.y as f64 + other_size,
81-
);
82-
83-
let dist_sq = (here.0 - there.0).powi(2) + (here.1 - there.1).powi(2);
84-
let range = building.block.range + other_size;
85-
if dist_sq > range * range {
86-
return false;
71+
#[cfg(feature = "enforce_processor_range")]
72+
{
73+
let self_size = (building.block.size as f64) / 2.;
74+
let other_size = (other.block.size as f64) / 2.;
75+
76+
let here = (
77+
building.position.x as f64 + self_size,
78+
building.position.y as f64 + self_size,
79+
);
80+
let there = (
81+
other.position.x as f64 + other_size,
82+
other.position.y as f64 + other_size,
83+
);
84+
85+
let dist_sq = (here.0 - there.0).powi(2) + (here.1 - there.1).powi(2);
86+
let range = building.block.range + other_size;
87+
if dist_sq > range * range {
88+
return false;
89+
}
8790
}
8891

8992
// finally, get the link name

0 commit comments

Comments
 (0)