Merge pull request #5 from enaut/copilot/research-turtle-lib-architecture

Align turtle-lib API docs with actual speed/reset/coordinate/heading semantics
This commit is contained in:
Franz Dietrich 2026-05-21 22:17:42 +02:00 committed by GitHub
commit 89c778289c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -349,6 +349,10 @@ impl TurtlePlan {
/// - `180°` points left (west) /// - `180°` points left (west)
/// - `270°` points down (south) /// - `270°` points down (south)
/// ///
/// Internally, turtle heading is stored in radians in a Y-down render space.
/// This method converts from user-facing degrees (Y-up mental model) to that
/// internal representation.
///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
@ -366,6 +370,8 @@ impl TurtlePlan {
/// } /// }
/// ``` /// ```
pub fn set_heading<T: Into<Degrees>>(&mut self, heading: T) -> &mut Self { pub fn set_heading<T: Into<Degrees>>(&mut self, heading: T) -> &mut Self {
// Convert user-facing turtle heading (degrees, Y-up mental model)
// to internal radians used by the render-space pipeline.
self.queue self.queue
.push(TurtleCommand::SetHeading(-heading.into().as_radians())); .push(TurtleCommand::SetHeading(-heading.into().as_radians()));
self self
@ -610,11 +616,14 @@ impl TurtlePlan {
/// The turtle moves in a straight line to the specified coordinates. /// The turtle moves in a straight line to the specified coordinates.
/// If the pen is down, a line is drawn. The turtle's heading is not changed. /// If the pen is down, a line is drawn. The turtle's heading is not changed.
/// ///
/// Coordinates are in screen space: /// Coordinates use turtle-style Cartesian space:
/// - `(0, 0)` is at the center /// - `(0, 0)` is at the center
/// - Positive x goes right /// - Positive x goes right
/// - Positive y goes up /// - Positive y goes up
/// ///
/// Internally, Macroquad uses Y-down screen coordinates; this command
/// performs the Y-axis conversion when executed.
///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
@ -677,7 +686,7 @@ impl TurtlePlan {
/// Resets the turtle to its default state. /// Resets the turtle to its default state.
/// ///
/// This clears all drawings, clears the animation queue, and resets all turtle parameters: /// This clears all drawings, clears active fill state, and resets turtle parameters:
/// - Position: (0, 0) /// - Position: (0, 0)
/// - Heading: 0° (facing right) /// - Heading: 0° (facing right)
/// - Pen: down /// - Pen: down
@ -688,6 +697,8 @@ impl TurtlePlan {
/// - Shape: arrow /// - Shape: arrow
/// - Speed: default /// - Speed: default
/// ///
/// Note: queued commands are not removed; `reset()` itself is a command in the queue.
///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run

View File

@ -34,7 +34,9 @@ pub enum TurtleCommand {
// Position // Position
Goto(Coordinate), Goto(Coordinate),
/// Heading stored as radians — already converted by the builder. /// Heading stored as internal radians (Y-down render-space convention).
/// Values passed via `TurtlePlan::set_heading` are converted from
/// user-facing degrees before this command is enqueued.
SetHeading(Radians), SetHeading(Radians),
// Visibility // Visibility

View File

@ -13,7 +13,11 @@ pub use length::Length;
/// Precision type for calculations /// Precision type for calculations
pub type Precision = f32; pub type Precision = f32;
/// 2D coordinate in screen space /// 2D coordinate value (`Vec2`) used by turtle commands and state.
///
/// Coordinate orientation depends on API context:
/// - `go_to()` input uses turtle-style coordinates (Y+ is up)
/// - internal render-space state uses Macroquad-style Y-down coordinates
pub type Coordinate = Vec2; pub type Coordinate = Vec2;
/// Visibility flag for turtle /// Visibility flag for turtle

View File

@ -215,7 +215,7 @@ impl TurtleApp {
/// ///
/// Speed is controlled by `SetSpeed` commands in the queue. /// Speed is controlled by `SetSpeed` commands in the queue.
/// Use `set_speed()` on the turtle plan to set animation speed. /// Use `set_speed()` on the turtle plan to set animation speed.
/// Speed >= 999 = instant mode, speed < 999 = animated mode. /// Speed >= 1000 = instant mode, speed < 1000 = animated mode.
/// ///
/// # Arguments /// # Arguments
/// * `queue` - The command queue to execute /// * `queue` - The command queue to execute
@ -228,7 +228,7 @@ impl TurtleApp {
/// ///
/// Speed is controlled by `SetSpeed` commands in the queue. /// Speed is controlled by `SetSpeed` commands in the queue.
/// Use `set_speed()` on the turtle plan to set animation speed. /// Use `set_speed()` on the turtle plan to set animation speed.
/// Speed >= 999 = instant mode, speed < 999 = animated mode. /// Speed >= 1000 = instant mode, speed < 1000 = animated mode.
/// ///
/// # Arguments /// # Arguments
/// * `turtle_id` - The ID of the turtle to control /// * `turtle_id` - The ID of the turtle to control