列车位置计算浮点数误差

This commit is contained in:
joylink_fanyuhong 2024-05-09 15:43:27 +08:00
parent 2e3fc1a1f2
commit bdefc71cef
2 changed files with 3 additions and 2 deletions

@ -1 +1 @@
Subproject commit 56e1948393aa51e0bf16d754292a211f348df161
Subproject commit e4c55ea4b6f9f5f875d59fc5bba51fc21bc8ef97

View File

@ -637,9 +637,10 @@ export class Train extends JlGraphic {
}
const offset = this.states.headOffset / allLength; // 百分比偏移
let offsetL = totalLength * offset;
// 0.01为保证浮点数计算误差
const indexP = lengths.findIndex((l) => {
offsetL -= l;
return offsetL <= 0;
return offsetL <= 0.001;
});
const startP = points[indexP];
const endP = points[indexP + 1];