refactor: fix all compiler + clippy warnings
- analysis.rs: use .clamp() instead of .max().min(), saturating_sub, inline corner_start into corner_start_s (dead assignment removed) - binary_utils.rs, parser_pcars.rs: use std::array::from_fn for array reads - recording.rs: std::io::Error::other() instead of Error::new(ErrorKind::Other), #[allow(dead_code)] on diagnostic methods (len, total_pushed, dropped_count, ring_stats) - track_model.rs: prefix unused path vars with _, #[allow(dead_code)] on exists() - parser_ksudp.rs: fix doc list item indentation - session.rs: std::mem::take instead of mem::replace(..., Default::default()) cargo build: 0 warnings, clippy: 0 warnings, 33 tests pass
This commit is contained in:
parent
9a4ca18864
commit
d86a87ab7d
7 changed files with 21 additions and 29 deletions
|
|
@ -116,7 +116,7 @@ pub fn analyze_shift_points(
|
|||
|
||||
points.sort_by(|a, b| a.speed_kmh.partial_cmp(&b.speed_kmh).unwrap_or(std::cmp::Ordering::Equal));
|
||||
|
||||
let window = (points.len() / 5).max(3).min(15);
|
||||
let window = (points.len() / 5).clamp(3, 15);
|
||||
let acc_values: Vec<f32> = points.iter().map(|p| p.acceleration_g).collect();
|
||||
let smoothed = smooth(&acc_values, window);
|
||||
|
||||
|
|
@ -177,7 +177,7 @@ fn smooth(values: &[f32], window: usize) -> Vec<f32> {
|
|||
let n = values.len();
|
||||
let mut result = Vec::with_capacity(n);
|
||||
for i in 0..n {
|
||||
let start = if i >= half { i - half } else { 0 };
|
||||
let start = i.saturating_sub(half);
|
||||
let end = (i + half + 1).min(n);
|
||||
let sum: f32 = values[start..end].iter().sum();
|
||||
result.push(sum / (end - start) as f32);
|
||||
|
|
@ -588,7 +588,7 @@ pub fn build_track_model(
|
|||
curvature.push(0.0);
|
||||
|
||||
// Step 7: Smooth curvature
|
||||
let window = (curvature.len() / 50).min(21).max(3);
|
||||
let window = (curvature.len() / 50).clamp(3, 21);
|
||||
let smoothed_curvature = smooth_f64(&curvature, window);
|
||||
|
||||
// Step 8: Auto-detect corners
|
||||
|
|
@ -665,7 +665,7 @@ fn smooth_f64(values: &[f64], window: usize) -> Vec<f64> {
|
|||
let n = values.len();
|
||||
let mut result = Vec::with_capacity(n);
|
||||
for i in 0..n {
|
||||
let start = if i >= half { i - half } else { 0 };
|
||||
let start = i.saturating_sub(half);
|
||||
let end = (i + half + 1).min(n);
|
||||
let sum: f64 = values[start..end].iter().sum();
|
||||
result.push(sum / (end - start) as f64);
|
||||
|
|
@ -676,7 +676,6 @@ fn smooth_f64(values: &[f64], window: usize) -> Vec<f64> {
|
|||
fn detect_corners(curvature: &[f64]) -> Vec<Corner> {
|
||||
let mut corners = Vec::new();
|
||||
let mut in_corner = false;
|
||||
let mut corner_start = 0usize;
|
||||
let mut corner_start_s = 0.0f64;
|
||||
let mut peak_idx = 0usize;
|
||||
let mut peak_kappa = 0.0f64;
|
||||
|
|
@ -688,8 +687,7 @@ fn detect_corners(curvature: &[f64]) -> Vec<Corner> {
|
|||
let abs_k = k.abs();
|
||||
if abs_k > CORNER_THRESHOLD && !in_corner {
|
||||
in_corner = true;
|
||||
corner_start = i.saturating_sub(5);
|
||||
corner_start_s = corner_start as f64 / denom;
|
||||
corner_start_s = i.saturating_sub(5) as f64 / denom;
|
||||
peak_idx = i;
|
||||
peak_kappa = abs_k;
|
||||
} else if abs_k > peak_kappa && in_corner {
|
||||
|
|
|
|||
|
|
@ -88,11 +88,7 @@ pub fn read_f64(data: &[u8], offset: usize) -> f64 {
|
|||
|
||||
/// Read an array of 4 little-endian `f32` from the data at the given offset.
|
||||
pub fn read_f32_4(data: &[u8], offset: usize) -> [f32; NUM_WHEELS] {
|
||||
let mut arr = [0.0f32; NUM_WHEELS];
|
||||
for i in 0..NUM_WHEELS {
|
||||
arr[i] = read_f32(data, offset + i * 4);
|
||||
}
|
||||
arr
|
||||
std::array::from_fn(|i| read_f32(data, offset + i * 4))
|
||||
}
|
||||
|
||||
/// Read an array of 2 little-endian `f32` from the data at the given offset.
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@
|
|||
//!
|
||||
//! IMPORTANT: The AC RTCarInfo C struct uses **natural alignment** (not packed).
|
||||
//! This means padding bytes exist:
|
||||
//!
|
||||
//! - 3 bytes after `char identifier` (offset 0) before `int size` (offset 4)
|
||||
//! - 2 bytes after the 6 bools (offsets 20–25) before the next float (offset 28)
|
||||
//! - 2 bytes after the 6 bools (offsets 20-25) before the next float (offset 28)
|
||||
//!
|
||||
//! Total struct size: 328 bytes (not 323).
|
||||
|
||||
use crate::binary_utils::{read_bool, read_f32, read_f32_4, read_i32};
|
||||
|
|
|
|||
|
|
@ -75,20 +75,12 @@ fn read_i8_at(data: &[u8], offset: usize) -> i8 {
|
|||
|
||||
/// Read 4 consecutive u8 values starting at offset.
|
||||
fn read_u8_4(data: &[u8], offset: usize) -> [u8; NUM_WHEELS] {
|
||||
let mut arr = [0u8; NUM_WHEELS];
|
||||
for i in 0..NUM_WHEELS {
|
||||
arr[i] = read_u8_at(data, offset + i);
|
||||
}
|
||||
arr
|
||||
std::array::from_fn(|i| read_u8_at(data, offset + i))
|
||||
}
|
||||
|
||||
/// Read 4 consecutive i16 values starting at offset.
|
||||
fn read_i16_4(data: &[u8], offset: usize) -> [i16; NUM_WHEELS] {
|
||||
let mut arr = [0i16; NUM_WHEELS];
|
||||
for i in 0..NUM_WHEELS {
|
||||
arr[i] = read_i16(data, offset + i * 2);
|
||||
}
|
||||
arr
|
||||
std::array::from_fn(|i| read_i16(data, offset + i * 2))
|
||||
}
|
||||
|
||||
/// Normalize u8 (0–255) to f32 (0.0–1.0).
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ impl RingBuffer {
|
|||
}
|
||||
|
||||
/// Number of frames currently stored.
|
||||
#[allow(dead_code)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.frames.len()
|
||||
}
|
||||
|
|
@ -103,11 +104,13 @@ impl RingBuffer {
|
|||
}
|
||||
|
||||
/// Total frames ever pushed (monotonically increasing).
|
||||
#[allow(dead_code)]
|
||||
pub fn total_pushed(&self) -> u64 {
|
||||
self.total_pushed
|
||||
}
|
||||
|
||||
/// Number of frames evicted due to ring overflow.
|
||||
#[allow(dead_code)]
|
||||
pub fn dropped_count(&self) -> u64 {
|
||||
self.dropped_count
|
||||
}
|
||||
|
|
@ -336,6 +339,7 @@ impl RecordingManager {
|
|||
}
|
||||
|
||||
/// Get ring buffer stats for a feed.
|
||||
#[allow(dead_code)]
|
||||
pub fn ring_stats(&self, feed_name: &str) -> Option<(usize, u64, u64)> {
|
||||
self.ring_buffers.get(feed_name)
|
||||
.and_then(|b| b.lock().ok())
|
||||
|
|
@ -452,8 +456,7 @@ impl RecordingManager {
|
|||
}
|
||||
|
||||
if !flush_errors.is_empty() {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
return Err(std::io::Error::other(
|
||||
format!("Flush errors: {}", flush_errors.join(", ")),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -617,7 +617,7 @@ fn merge_frames(mut frames: Vec<TelemetryFrame>) -> Vec<TelemetryFrame> {
|
|||
{
|
||||
// Near-duplicate: keep higher-priority frame at write position
|
||||
if feed_priority(frames[read].source) > feed_priority(frames[write].source) {
|
||||
frames[write] = std::mem::replace(&mut frames[read], TelemetryFrame::default());
|
||||
frames[write] = std::mem::take(&mut frames[read]);
|
||||
}
|
||||
} else {
|
||||
write += 1;
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ impl TrackModelStore {
|
|||
if !game_path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let game = game_path
|
||||
let _game = game_path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("")
|
||||
|
|
@ -152,7 +152,7 @@ impl TrackModelStore {
|
|||
if track_path.extension().and_then(|e| e.to_str()) != Some("json") {
|
||||
continue;
|
||||
}
|
||||
let track_name = track_path
|
||||
let _track_name = track_path
|
||||
.file_stem()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("")
|
||||
|
|
@ -220,6 +220,7 @@ impl TrackModelStore {
|
|||
}
|
||||
|
||||
/// Check if a track model exists.
|
||||
#[allow(dead_code)]
|
||||
pub async fn exists(&self, game: &str, track_name: &str) -> bool {
|
||||
self.track_path(game, track_name)
|
||||
.map(|p| p.exists())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue