Consistency Refactoring
All 6 consistency review items have been resolved, verified with new
unit tests, automated test suites, and clean example builds.
- **Fixed `Goto` Duration Bug**: In
[`turtle-lib/src/command_behavior.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/command_behavior.rs),
mapped Cartesian target coordinates to screen space (`vec2(target.x,
-target.y)`) before calculating $\Delta x$ and $\Delta y$ in
`animation_duration`.
- **Unit Test**: Added `test_goto_duration_cartesian_inversion` testing
that moving from screen $(0, 100)$ (Cartesian $(0, -100)$) to
Cartesian $(0, 100)$ computes duration based on the actual 200px
Euclidean distance ($2.0\text{s}$ at $100\text{ px/s}$).
- **Stored `Degrees`**: Updated `TurtleCommand::SetHeading(Degrees)` in
[`turtle-lib/src/commands.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/commands.rs)
to store user degrees directly ($0^\circ = \text{East}$, $90^\circ =
\text{North}$), matching `Turn(Degrees)` and `Circle { angle: Degrees
}`.
- **Deferred Screen-Space Conversion**: Converted to internal screen
radians (`normalize_angle(-heading.as_radians().value())`) inside
`apply_to_params` in
[`turtle-lib/src/command_behavior.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/command_behavior.rs).
- **Instant Duration**: Maintained instant transition ($0.01\text{s}$
minimum) in `animation_duration`.
- **Unit Test**: Added `test_set_heading_degrees_and_instant_duration`
verifying $90^\circ$ maps to North ($-\frac{\pi}{2}$ in screen space),
$0^\circ$ to East ($0$), $270^\circ$ to South ($+\frac{\pi}{2}$), and
duration is $0.01\text{s}$.
- **Enhanced `Length` Type**: Expanded
[`turtle-lib/src/general/length.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/general/length.rs)
with `new()`, `value()`, `Neg`, `PartialOrd`, and conversion
implementations (`From<f32>`, `From<f64>`, `From<i32>`, `From<i16>`,
`From<usize>`).
- **Adopted Across API**:
- `TurtleCommand::Move(Length)` in `commands.rs`.
- `TurtleCommand::Circle { radius: Length, ... }` in `commands.rs`.
- `forward<T: Into<Length>>` and `backward<T: Into<Length>>` in
[`turtle-lib/src/builders.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/builders.rs).
- `circle_left`, `circle_right` accept `radius: impl Into<Length>`.
- Kept stroke attribute `pen_width` as `Precision` (`f32`).
- **Unit Test**: Added `test_length_conversions_and_negation` in
`general::length`.
- **Removed Duplicate Alias**: Removed `all_animations_complete(&self)`
from `TurtleApp` in
[`turtle-lib/src/lib.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/lib.rs);
updated call in
[`turtle-lib/src/export.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/src/export.rs)
to use canonical `is_complete(&self)`.
- **Corrected
[`README.md`](file:///home/dietrich/Projekte/Source/turtlers/README.md)**:
- `plan.goto(...)` $\rightarrow$ `plan.go_to(...)`
- `plan.set_color(...)` $\rightarrow$ `plan.set_pen_color(...)`
- `create_turtle()` $\rightarrow$ `create_turtle_plan()`
- **Corrected
[`AGENTS.md`](file:///home/dietrich/Projekte/Source/turtlers/AGENTS.md)**:
- `create_turtle()` $\rightarrow$ `create_turtle_plan()` in Threading
Pattern.
- **Unified on `1000.0`**:
- Updated
[`README.md`](file:///home/dietrich/Projekte/Source/turtlers/README.md)
lines 9, 108, 109 to state `speed >= 1000` is Instant and `speed <
1000` is Animated.
- Updated
[`turtle-lib/examples/circle_test.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/examples/circle_test.rs)
to use `turtle.set_speed(1000)`.
- **Renamed Examples**:
- `turtle-lib/examples/stern.rs` $\rightarrow$
[`turtle-lib/examples/star.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/examples/star.rs)
- `turtle-lib/examples/nikolaus.rs` $\rightarrow$
[`turtle-lib/examples/house_of_nikolaus.rs`](file:///home/dietrich/Projekte/Source/turtlers/turtle-lib/examples/house_of_nikolaus.rs)
- **Translated Functions & Parameters**:
- `house_of_nikolaus.rs`: Translated `nikolausquadrat` $\rightarrow$
`house_square`, `nikolausdiag` $\rightarrow$ `house_diagonal`,
`nikolausdach2` $\rightarrow$ `house_roof`, parameter `groesse`
$\rightarrow$ `size`. Added doc comment explaining the Eulerian path
puzzle.
- `breadboard.rs`: Translated `pin_reihe` $\rightarrow$ `pin_row`,
`pin_spalte` $\rightarrow$ `pin_column`, `pin_seite` $\rightarrow$
`pin_side`, parameter `anzahl` $\rightarrow$ `count`,
`anzahl_reihen` $\rightarrow$ `row_count`. Added `#[cfg(feature =
"svg")]` to helper functions to eliminate dead-code warnings when
SVG feature is not enabled.
- **Translated UI Text & Print Messages**:
- `"Drücke E für SVG-Export"` $\rightarrow$ `"Press E for SVG export"`
- `"SVG exportiert nach test.svg"` $\rightarrow$ `"SVG exported to
test.svg"`
- `"Fehler beim Export: {:?}"` $\rightarrow$ `"Export error: {:?}"`
- `"SVG-Export ist nicht aktiviert..."` $\rightarrow$ `"SVG export is
not enabled..."`
- Translated module doc in `export_svg.rs`.
- **Updated
[`README.md`](file:///home/dietrich/Projekte/Source/turtlers/README.md)**
example lists and CLI commands to reference `star` and
`house_of_nikolaus`.
---
- `cargo test --package turtle-lib`:
- 13 unit tests passed (including 3 new targeted unit tests)
- 34 doctests passed (1 ignored internal helper)
- `cargo check --workspace --all-targets --all-features`: Passed with 0
errors.
- `cargo check --examples --package turtle-lib --all-features`: All 30
examples compiled cleanly with 0 errors.
- `cargo clippy --package turtle-lib -- -Wclippy::pedantic
-Aclippy::cast_precision_loss -Aclippy::cast_sign_loss
-Aclippy::cast_possible_truncation`: Passed with 0 errors.
This commit is contained in:
@@ -6,7 +6,7 @@ A modern turtle graphics library for Rust built on [Macroquad](https://macroquad
|
||||
|
||||
- 🎨 **Simple Builder API**: Chain commands like `forward(100).right(90)`
|
||||
- ⚡ **Smooth Animations**: Tweening support with easing functions and live fill preview
|
||||
- 🚀 **Instant Mode**: Execute commands immediately without animation (speed ≥ 999)
|
||||
- 🚀 **Instant Mode**: Execute commands immediately without animation (speed ≥ 1000)
|
||||
- 🎯 **High-Quality Rendering**: Complete Lyon tessellation pipeline with GPU acceleration
|
||||
- **Multi-Contour Fills**: Automatic hole detection with EvenOdd fill rule - draw cheese with holes!
|
||||
- 📐 **Self-Intersecting Paths**: Stars, complex shapes - all handled correctly
|
||||
@@ -99,14 +99,14 @@ plan.begin_fill();
|
||||
plan.end_fill(); // Auto-closes and applies fill
|
||||
|
||||
// Appearance
|
||||
plan.set_color(RED);
|
||||
plan.set_pen_color(RED);
|
||||
plan.set_pen_width(5.0);
|
||||
plan.hide();
|
||||
plan.show();
|
||||
|
||||
// Speed control (dynamic)
|
||||
plan.set_speed(100); // Animated mode (< 999)
|
||||
plan.set_speed(1000); // Instant mode (>= 999)
|
||||
plan.set_speed(100); // Animated mode (< 1000)
|
||||
plan.set_speed(1000); // Instant mode (>= 1000)
|
||||
|
||||
// Turtle shapes
|
||||
plan.shape(ShapeType::Triangle);
|
||||
@@ -136,7 +136,7 @@ let mut plan = create_turtle_plan();
|
||||
// Fast initial positioning (instant mode)
|
||||
plan.set_speed(1000);
|
||||
plan.pen_up();
|
||||
plan.goto(vec2(-100.0, -100.0));
|
||||
plan.go_to(vec2(-100.0, -100.0));
|
||||
|
||||
// Slow animated drawing
|
||||
plan.set_speed(50);
|
||||
@@ -219,7 +219,7 @@ You can also export SVG programmatically from your code:
|
||||
use turtle_lib::*;
|
||||
|
||||
// Create your drawing
|
||||
let mut plan = create_turtle();
|
||||
let mut plan = create_turtle_plan();
|
||||
plan.forward(100).right(90).forward(100);
|
||||
|
||||
// Create app
|
||||
@@ -252,8 +252,8 @@ cargo run --example square
|
||||
cargo run --example koch
|
||||
cargo run --example shapes
|
||||
cargo run --example yinyang
|
||||
cargo run --example stern
|
||||
cargo run --example nikolaus
|
||||
cargo run --example star
|
||||
cargo run --example house_of_nikolaus
|
||||
|
||||
# SVG export example (requires --features svg)
|
||||
cargo run --example export_svg --features svg
|
||||
@@ -274,8 +274,8 @@ RUST_LOG=turtle_lib=debug cargo run --example logging_example
|
||||
- **square.rs**: Basic square drawing
|
||||
- **koch.rs**: Koch snowflake fractal
|
||||
- **shapes.rs**: Demonstrates different turtle shapes
|
||||
- **stern.rs**: Star pattern drawing
|
||||
- **nikolaus.rs**: Nikolaus (Santa) drawing
|
||||
- **star.rs**: Star pattern drawing
|
||||
- **house_of_nikolaus.rs**: House of Nikolaus (Eulerian path puzzle)
|
||||
|
||||
#### Fill Examples
|
||||
|
||||
@@ -297,7 +297,7 @@ RUST_LOG=turtle_lib=debug cargo run --example logging_example
|
||||
### Basic Fill
|
||||
|
||||
```rust
|
||||
let mut plan = create_turtle();
|
||||
let mut plan = create_turtle_plan();
|
||||
plan.set_fill_color(RED);
|
||||
plan.begin_fill();
|
||||
|
||||
@@ -321,7 +321,7 @@ plan.circle_left(90.0, 360.0, 72);
|
||||
|
||||
// pen_up() closes current contour
|
||||
plan.pen_up();
|
||||
plan.goto(vec2(0.0, -30.0));
|
||||
plan.go_to(vec2(0.0, -30.0));
|
||||
|
||||
// pen_down() starts new contour
|
||||
plan.pen_down();
|
||||
|
||||
Reference in New Issue
Block a user