small fixes for clippy compliance

This commit is contained in:
Franz Dietrich 2025-10-20 14:46:04 +02:00
parent 0e191c617c
commit 88d188a794
9 changed files with 25 additions and 35 deletions

View File

@ -32,7 +32,7 @@ use syn::{parse_macro_input, ItemFn};
/// } /// }
/// ``` /// ```
/// ///
/// If you need macroquad types not re-exported by turtle_lib: /// If you need macroquad types not re-exported by `turtle_lib`:
/// ///
/// ```ignore /// ```ignore
/// use macroquad::prelude::SKYBLUE; // Import specific items /// use macroquad::prelude::SKYBLUE; // Import specific items

View File

@ -268,7 +268,7 @@ impl TurtlePlan {
/// ///
/// Speed controls how fast the turtle moves during animations: /// Speed controls how fast the turtle moves during animations:
/// - Values `>= 1000`: Instant mode - commands execute immediately without animation. /// - Values `>= 1000`: Instant mode - commands execute immediately without animation.
/// The bigger the number, the more segments are drawn per frame. /// The bigger the number, the more segments are drawn per frame.
/// - Values `< 1000`: Animated mode - turtle moves at specified pixels per second /// - Values `< 1000`: Animated mode - turtle moves at specified pixels per second
/// ///
/// You can dynamically switch between instant and animated modes during execution. /// You can dynamically switch between instant and animated modes during execution.

View File

@ -112,7 +112,7 @@ impl TurtleCommandSender {
pub fn send(&self, queue: CommandQueue) -> Result<(), String> { pub fn send(&self, queue: CommandQueue) -> Result<(), String> {
self.tx self.tx
.send(queue) .send(queue)
.map_err(|e| format!("Channel disconnected: {}", e)) .map_err(|e| format!("Channel disconnected: {e}"))
} }
/// Send commands (non-blocking) /// Send commands (non-blocking)
@ -137,7 +137,7 @@ impl TurtleCommandSender {
pub fn try_send(&self, queue: CommandQueue) -> Result<(), String> { pub fn try_send(&self, queue: CommandQueue) -> Result<(), String> {
self.tx self.tx
.try_send(queue) .try_send(queue)
.map_err(|e| format!("Failed to send: {}", e)) .map_err(|e| format!("Failed to send: {e}"))
} }
} }
@ -165,6 +165,7 @@ impl TurtleCommandReceiver {
/// } /// }
/// # } /// # }
/// ``` /// ```
#[must_use]
pub fn recv_all(&self) -> Vec<CommandQueue> { pub fn recv_all(&self) -> Vec<CommandQueue> {
self.rx.try_iter().collect() self.rx.try_iter().collect()
} }
@ -192,14 +193,14 @@ impl TurtleCommandReceiver {
/// ///
/// The tuple represents (sender, receiver) where: /// The tuple represents (sender, receiver) where:
/// - Sender goes to game logic threads (cloneable, can be distributed) /// - Sender goes to game logic threads (cloneable, can be distributed)
/// - Receiver stays in the render thread (part of TurtleApp internally) /// - Receiver stays in the render thread (part of `TurtleApp` internally)
/// ///
/// # Arguments /// # Arguments
/// * `turtle_id` - The ID of the turtle this channel is for (must be valid) /// * `turtle_id` - The ID of the turtle this channel is for (must be valid)
/// * `buffer_size` - Maximum number of pending command batches before sender blocks /// * `buffer_size` - Maximum number of pending command batches before sender blocks
/// ///
/// # Panics /// # Panics
/// Panics if buffer_size is 0. /// Panics if `buffer_size` is 0.
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
@ -207,9 +208,10 @@ impl TurtleCommandReceiver {
/// # fn example() { /// # fn example() {
/// let (tx, _rx) = turtle_command_channel(0, 100); /// let (tx, _rx) = turtle_command_channel(0, 100);
/// // Sender goes to game threads /// // Sender goes to game threads
/// // Receiver stays in render thread (or TurtleApp) /// // Receiver stays in render thread (or `TurtleApp`)
/// # } /// # }
/// ``` /// ```
#[must_use]
pub fn turtle_command_channel( pub fn turtle_command_channel(
turtle_id: usize, turtle_id: usize,
buffer_size: usize, buffer_size: usize,

View File

@ -93,7 +93,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) {
} }
// Draw in-progress tween lines for all active tweens // Draw in-progress tween lines for all active tweens
for turtle in world.turtles.iter() { for turtle in &world.turtles {
if let Some(tween) = turtle.tween_controller.current_tween() { if let Some(tween) = turtle.tween_controller.current_tween() {
// Only draw if pen is down // Only draw if pen is down
if tween.start_params.pen_down { if tween.start_params.pen_down {
@ -132,7 +132,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) {
} }
// Draw live fill preview for all turtles that are currently filling // Draw live fill preview for all turtles that are currently filling
for turtle in world.turtles.iter() { for turtle in &world.turtles {
if let Some(ref fill_state) = turtle.filling { if let Some(ref fill_state) = turtle.filling {
// Build all contours: completed contours + current contour with animation // Build all contours: completed contours + current contour with animation
let mut all_contours: Vec<Vec<Vec2>> = Vec::new(); let mut all_contours: Vec<Vec<Vec2>> = Vec::new();

View File

@ -11,6 +11,7 @@ use crate::general::AnimationSpeed;
/// Execute side effects for commands that don't involve movement /// Execute side effects for commands that don't involve movement
/// Returns true if the command was handled (caller should skip movement processing) /// Returns true if the command was handled (caller should skip movement processing)
#[allow(clippy::too_many_lines)]
pub fn execute_command_side_effects(command: &TurtleCommand, state: &mut Turtle) -> bool { pub fn execute_command_side_effects(command: &TurtleCommand, state: &mut Turtle) -> bool {
match command { match command {
TurtleCommand::BeginFill => { TurtleCommand::BeginFill => {

View File

@ -118,7 +118,7 @@ impl TurtleApp {
/// ///
/// # Returns /// # Returns
/// A `TurtleCommandSender` that can be cloned and sent to game logic threads. /// A `TurtleCommandSender` that can be cloned and sent to game logic threads.
/// The turtle is automatically managed by TurtleApp. /// The turtle is automatically managed by `TurtleApp`.
/// ///
/// # Examples /// # Examples
/// ```no_run /// ```no_run
@ -236,7 +236,7 @@ impl TurtleApp {
} }
} }
/// Append commands from a CommandQueue to a turtle's animation queue /// Append commands from a `CommandQueue` to a turtle's animation queue
/// ///
/// Used internally by `process_commands()` and can be used directly /// Used internally by `process_commands()` and can be used directly
/// when you have a `CommandQueue` instead of a `TurtlePlan`. /// when you have a `CommandQueue` instead of a `TurtlePlan`.
@ -258,7 +258,7 @@ impl TurtleApp {
self.handle_mouse_zoom(); self.handle_mouse_zoom();
// Update all turtles' tween controllers // Update all turtles' tween controllers
for turtle in self.world.turtles.iter_mut() { for turtle in &mut self.world.turtles {
// Extract draw_commands and controller temporarily to avoid borrow conflicts // Extract draw_commands and controller temporarily to avoid borrow conflicts
// Update the controller // Update the controller

View File

@ -38,7 +38,7 @@ pub struct TurtleParams {
} }
impl Default for TurtleParams { impl Default for TurtleParams {
/// Create TurtleParams from default values /// Create `TurtleParams` from default values
fn default() -> Self { fn default() -> Self {
Self { Self {
position: vec2(0.0, 0.0), position: vec2(0.0, 0.0),
@ -92,7 +92,7 @@ impl Turtle {
Angle::radians(self.params.heading) Angle::radians(self.params.heading)
} }
/// Reset turtle to default state (preserves turtle_id and queued commands) /// Reset turtle to default state (preserves `turtle_id` and queued commands)
pub fn reset(&mut self) { pub fn reset(&mut self) {
// Clear all drawings // Clear all drawings
self.commands.clear(); self.commands.clear();
@ -316,10 +316,10 @@ impl TurtleWorld {
/// Add a new turtle and return its ID /// Add a new turtle and return its ID
pub fn add_turtle(&mut self) -> usize { pub fn add_turtle(&mut self) -> usize {
let turtle_id = self.turtles.len(); let turtle_id = self.turtles.len();
let mut new_turtle = Turtle::default(); let new_turtle = Turtle {
new_turtle.turtle_id = turtle_id; turtle_id,
new_turtle.tween_controller = ..Default::default()
TweenController::new(CommandQueue::new(), AnimationSpeed::default()); };
self.turtles.push(new_turtle); self.turtles.push(new_turtle);
turtle_id turtle_id
} }

View File

@ -294,6 +294,7 @@ pub fn tessellate_circle(
/// # Errors /// # Errors
/// ///
/// Returns an error if tessellation fails. /// Returns an error if tessellation fails.
#[allow(clippy::too_many_arguments)]
pub fn tessellate_arc( pub fn tessellate_arc(
center: Vec2, center: Vec2,
radius: f32, radius: f32,

View File

@ -44,23 +44,13 @@ impl From<TweenVec2> for Vec2 {
} }
/// Controls tweening of turtle commands /// Controls tweening of turtle commands
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct TweenController { pub struct TweenController {
queue: CommandQueue, queue: CommandQueue,
current_tween: Option<CommandTween>, current_tween: Option<CommandTween>,
speed: AnimationSpeed, speed: AnimationSpeed,
} }
impl Default for TweenController {
fn default() -> Self {
Self {
queue: CommandQueue::new(),
current_tween: None,
speed: AnimationSpeed::default(),
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct CommandTween { pub struct CommandTween {
pub turtle_id: usize, pub turtle_id: usize,
@ -98,6 +88,7 @@ impl TweenController {
/// Update the tween, returns `Vec` of (`command`, `start_state`, `end_state`) for all completed commands this frame /// Update the tween, returns `Vec` of (`command`, `start_state`, `end_state`) for all completed commands this frame
/// Also takes commands vec to handle side effects like fill operations /// Also takes commands vec to handle side effects like fill operations
/// Each `command` has its own `start_state` and `end_state` pair /// Each `command` has its own `start_state` and `end_state` pair
#[allow(clippy::too_many_lines)]
pub fn update(state: &mut Turtle) -> Vec<(TurtleCommand, TurtleParams, TurtleParams)> { pub fn update(state: &mut Turtle) -> Vec<(TurtleCommand, TurtleParams, TurtleParams)> {
// In instant mode, execute commands up to the draw calls per frame limit // In instant mode, execute commands up to the draw calls per frame limit
if let AnimationSpeed::Instant(max_draw_calls) = state.tween_controller.speed { if let AnimationSpeed::Instant(max_draw_calls) = state.tween_controller.speed {
@ -106,12 +97,7 @@ impl TweenController {
let mut draw_call_count = 0; let mut draw_call_count = 0;
// Consume commands from the real queue so the current_index advances // Consume commands from the real queue so the current_index advances
loop { while let Some(command) = state.tween_controller.queue.next() {
let command = match state.tween_controller.queue.next() {
Some(cmd) => cmd,
None => break,
};
// Handle SetSpeed command to potentially switch modes // Handle SetSpeed command to potentially switch modes
if let TurtleCommand::SetSpeed(new_speed) = &command { if let TurtleCommand::SetSpeed(new_speed) = &command {
state.params.speed = *new_speed; state.params.speed = *new_speed;