Skip to content

Commit bdac20c

Browse files
PaulDancesunjay
andcommitted
Apply suggestions from code review
Add a compile-time error indicating the need to use `features unstable`. Rephrase some documentation and tweak minor things here and there. Co-authored-by: Sunjay Varma <[email protected]>
1 parent 712b2e0 commit bdac20c

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

examples/flower.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//! They both provide the ability to draw a circular arc defined by the given `radius` and `extent`
55
//! parameters, while the first makes the turtle draw it to the left and the second to the right.
66
7+
// To run this example, use the command: cargo run --features unstable --example flower
8+
#[cfg(all(not(feature = "unstable")))]
9+
compile_error!("This example relies on unstable features. Run with `--features unstable`");
10+
711
use turtle::{Angle, Distance, Drawing};
812

913
const TURTLE_SPEED: &str = "faster";
@@ -74,9 +78,12 @@ fn main() {
7478

7579
// Right leaf.
7680
turtle.right(RIGHT_LEAF_INCLINATION);
77-
turtle.arc_right(RIGHT_LEAF_BOTTOM_RADIUS, RIGHT_LEAF_BOTTOM_EXTENT);
81+
// Note that `arc_left` with a negative radius is the same as calling `arc_right`.
82+
// This is used below for illustration purposes only. You'd probably want to use
83+
// `arc_right` in real code.
84+
turtle.arc_left(-RIGHT_LEAF_BOTTOM_RADIUS, RIGHT_LEAF_BOTTOM_EXTENT);
7885
turtle.right(RIGHT_LEAF_INCLINATION);
79-
turtle.arc_right(RIGHT_LEAF_TOP_RADIUS, -RIGHT_LEAF_TOP_EXTENT);
86+
turtle.arc_left(-RIGHT_LEAF_TOP_RADIUS, -RIGHT_LEAF_TOP_EXTENT);
8087

8188
// Trunk.
8289
turtle.end_fill();

src/ipc_protocol/protocol.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,17 @@ impl ProtocolClient {
368368
}
369369

370370
pub async fn circular_arc(&self, id: TurtleId, radius: Distance, extent: Radians, direction: RotationDirection) {
371-
if radius.is_normal() && extent.is_normal() {
372-
let steps = 250; // Arbitrary value for now.
373-
let step = radius.abs() * extent.to_radians() / steps as f64;
374-
let rotation = radius.signum() * extent / steps as f64;
375-
376-
for _ in 0..steps {
377-
self.move_forward(id, step).await;
378-
self.rotate_in_place(id, rotation, direction).await;
379-
}
371+
if !radius.is_normal() || !extent.is_normal() {
372+
return;
373+
}
374+
375+
let steps = 250; // Arbitrary value for now.
376+
let step = radius.abs() * extent.to_radians() / steps as f64;
377+
let rotation = radius.signum() * extent / steps as f64;
378+
379+
for _ in 0..steps {
380+
self.move_forward(id, step).await;
381+
self.rotate_in_place(id, rotation, direction).await;
380382
}
381383
}
382384

src/turtle.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,20 @@ impl Turtle {
210210
/// thus globally turning counterclockwise.
211211
///
212212
/// It is configured through the `radius` and `extent` arguments:
213-
/// * `radius` places the center of the arc itself `Distance` units away from the left of the
213+
/// * `radius` places the center of the arc itself `radius` units away from the left of the
214214
/// turtle, with respect to its current orientation. When negative, it does so to the right.
215215
/// * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that
216216
/// forms the circular portion of the given `radius`. When negative, the turtle moves
217217
/// backwards instead, but it still goes to its left. It can also be greater than the
218218
/// turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using
219219
/// radians: the turtle will simply continue to draw until the complete angle is reached.
220220
///
221-
/// This method does *nothing* if either one of the provided arguments is not "normal" in the
222-
/// sense of [floating-point numbers' definition](f64::is_normal) of it.
223-
///
224221
/// # Example
225222
///
226223
/// ```rust
227224
/// # use turtle::Turtle;
228225
/// let mut turtle = Turtle::new();
229226
///
230-
/// // No movement when anormal.
231-
/// turtle.arc_left(0.0, 1.0);
232-
/// turtle.arc_left(f64::NAN, -f64::INFINITY);
233227
/// assert_eq!(turtle.position(), [0.0, 0.0].into());
234228
/// assert_eq!(turtle.heading(), 90.0);
235229
///
@@ -272,26 +266,20 @@ impl Turtle {
272266
/// thus globally turning clockwise.
273267
///
274268
/// It is configured through the `radius` and `extent` arguments:
275-
/// * `radius` places the center of the arc itself `Distance` units away from the right of the
269+
/// * `radius` places the center of the arc itself `radius` units away from the right of the
276270
/// turtle, with respect to its current orientation. When negative, it does so to the left.
277271
/// * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that
278272
/// forms the circular portion of the given `radius`. When negative, the turtle moves
279273
/// backwards instead, but it still goes to its right. It can also be greater than the
280274
/// turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using
281275
/// radians: the turtle will simply continue to draw until the complete angle is reached.
282276
///
283-
/// This method does *nothing* if either one of the provided arguments is not "normal" in the
284-
/// sense of [floating-point numbers' definition](f64::is_normal) of it.
285-
///
286277
/// # Example
287278
///
288279
/// ```rust
289280
/// # use turtle::Turtle;
290281
/// let mut turtle = Turtle::new();
291282
///
292-
/// // No movement when anormal.
293-
/// turtle.arc_right(0.0, 1.0);
294-
/// turtle.arc_right(f64::NAN, -f64::INFINITY);
295283
/// assert_eq!(turtle.position(), [0.0, 0.0].into());
296284
/// assert_eq!(turtle.heading(), 90.0);
297285
///

0 commit comments

Comments
 (0)