From 53af241949a82384b0f02ee1a9c47dec7f869d20 Mon Sep 17 00:00:00 2001 From: maciejpedzich Date: Fri, 28 Feb 2025 23:09:56 +0100 Subject: [PATCH] fix: offset f32 assert range ends by a tenth --- src/packets/car_telemetry.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/packets/car_telemetry.rs b/src/packets/car_telemetry.rs index 8c23a07..ca58df8 100644 --- a/src/packets/car_telemetry.rs +++ b/src/packets/car_telemetry.rs @@ -4,6 +4,11 @@ use crate::constants::{RevLights, Surface}; use binrw::BinRead; use serde::{Deserialize, Serialize}; +// f32 range ends were offset by a tenth to account for values ever so slightly +// greater or lower than the respective extreme. +// There's probably a better way of going about handling this, +// but this will do for now. + #[non_exhaustive] #[derive(BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize)] #[br(little, import(_packet_format: u16))] @@ -13,7 +18,7 @@ pub struct CarTelemetryData { /// Amount of throttle applied. Value in range `(0.0..=1.0)`. #[br( assert( - (0.0..=1.0).contains(&throttle), + (-0.1..=1.1).contains(&throttle), "Car telemetry entry has an invalid throttle value: {}", throttle ), @@ -22,7 +27,7 @@ pub struct CarTelemetryData { /// Steering lock. Value in range `(-1.0..=1.0)`. #[br( assert( - (-1.0..=1.0).contains(&steer), + (-1.1..=1.1).contains(&steer), "Car telemetry entry has an invalid steering lock value: {}", steer ), @@ -31,7 +36,7 @@ pub struct CarTelemetryData { /// Amount of brake applied. Value in range `(0.0..=1.0)`. #[br( assert( - (0.0..=1.0).contains(&brake), + (-0.1..=1.1).contains(&brake), "Car telemetry entry has an invalid brake value: {}", brake ),