profile
viewpoint
Sunjay Varma sunjay @rust-lang @sunjay03 on Twitter http://sunjay.dev I'm experimenting with and exploring all kinds of interesting things! Everything here might not be clean and production ready code. Enjoy!

RustBeginners/awesome-rust-mentors 365

A list of rust lang mentors tagged by topics of interest

brain-lang/brain 99

A high level programming language that compiles into the brainfuck esoteric programming language

sunjay/caves 26

2D Cave Exploration Game with Procedurally Generated Levels

sunjay/component_group 19

A Rust crate for working with a group of Components (in the Specs ECS)

mgattozzi/chronicle.rs 17

Documenting Rust's history for future users and generations

sunjay/dino 5

Compiler / PL Experimentation

sunjay/ci 3

Continuous integration utilities for Rust

RhinoEditor/rhino 2

Rhino Editor - Image Editor for Linux (work in progress)

sunjay/crategrep 2

Search all the source code on crates.io with ripgrep

issue openedsunjay/pea

User-defined types

Allow types to be defined in programs with the struct keyword.

1. Struct Declarations and Literals

  • [ ] should be able to define struct types (even recursive types)
  • [ ] struct literals should require all fields to be specified (with no duplicates)
  • [ ] struct literals should assert that each field type is as expected
  • [ ] struct literals should produce a value of the defined type
  • [ ] printing a struct prints the struct name, e.g. <struct Foo>

2. Field Access

  • [ ] read the value of a field using value.field syntax
  • [ ] write to a field using assignment expr.field = value
  • [ ] error if field being accessed doesn't actually exist
  • [ ] error if assigning to a field with the wrong type of expr

Test Case: Structs

// run-pass/structs.pea
struct Foo {
    a: i64,
    b: [u8],
}

fn main() {
    let a = 32;
    let value = Foo {
        // Struct literal field shorthand syntax
        a,
        b: b"abcdefg",
    };

    println!(value);
    //TODO: Field access
    // println!(value.a);
    // println!(value.b);

    do_stuff(value);

    let empty = EmptyStruct {};
    println!(empty);
}

fn do_stuff(value: Foo) {
    // Order of fields in the struct literal does not matter
    value = Foo {b: b"ab", a: -3};
    //TODO: value = Foo {b: b"ab", a: value.a * -3};
    println!(value);
    //TODO: Field access
    // println!(value.a);
    // println!(value.b);

    // println!(value);
    // println!(value.a);
    // println!(value.b);

    // value.a = -1;
    // println!(value.a);
    // println!(value.b);

    // value.b = b"";
    // println!(value.a);
    // println!(value.b);
}

struct EmptyStruct {}

// This struct is uninstantiable, but still technically valid
struct SelfRef {
    value: SelfRef,
}

Test Case: Field Access

// ui/unknown_field.pea
struct Cool {
    pie: [i64],
}

fn main() {
    let value = Cool {pie: [1, 3]};
    println!(value.pie);
    println!(value.doesnotexist);
}

created time in 7 days

issue commentsunjay/turtle

Linux X11 crash when mouse enters window or is moved

Hi @enaut. Thanks for reporting this issue. See this comment for more details: https://github.com/sunjay/turtle/issues/202#issuecomment-695811144

enaut

comment created time in 7 days

push eventsunjay/pea

Sunjay Varma

commit sha 163188d6b43249bc5594443114156fb70d9e5017

Allowing named types to unify if they are the same named type

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 767cad2075502d66ff247d673d8fa9d8f1bbd5fe

Finishing type inference for struct literal field assuming that a type var for the field has already been inserted into the context

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 260d21c16519730cf4c1f19f1a35cf8e3929df4e

Need to desugar struct literal field short-hand syntax right away or name resolution and type inference cannot take place on field expression

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 7552ccc3ad59091d729dc25c9c5672a480586422

Partial work on type inference for struct literals + subst for struct literal types

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 9c23ad3192ebe7f1e5cb9e3427f016b8d97487dd

Storing Gc<Scope> everywhere instead of Scope to avoid unnecessarily expensive clones

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 6413d7e7bfa42928f9e88470eeaaace646b750f5

Logging allocated memory before and after sweep

view details

Sunjay Varma

commit sha 7e241270a40a39c58e2bef88d3695a95509392bf

Running garbage collector once at the end of compilation to clean up extra memory that will not be used by the interpreter

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 2c3a11202dfd51a0b78b3ee7ef433e21c4613e1e

Moved GC tests out into their own module where they can use the GC in isolation

view details

Sunjay Varma

commit sha 70d5bf8c36a94ef7e3ef4bbc9b2e5313a7cb4540

Implementing Trace for RwLock and Mutex

view details

Sunjay Varma

commit sha d55823509d8fcbdb0d1967deadcb2695d51527b9

Using Gc<T> instead of Arc<T> throughout entire codebase

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha d1fa387aaaa1af4c07f8730d349b5bb61e055c1b

type inference for struct decls

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha f5d75470b3ba4c955503a1863535e62521b71ca2

methods and fields will be implemented later

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 82ca4e027826b1e9faf64fea99557c1f8528a2d4

Added a trait and macros for formatting/printing something while also passing in some additional context

view details

Sunjay Varma

commit sha cab2c7d71c2c7024dfb592e1a3e03c708fc1d8b5

Allowing arbitrary named types to be resolved into `nir::Ty::Named`

view details

push time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 391cb26abefdc8182e2e8647bc34bc6bb6910b26

Forgot to disallow struct literals in else if statements

view details

push time in 8 days

issue openedsunjay/pea

Declarations in inner scopes

Currently, declarations are only allowed at the top-level of a module. This works well and avoids a bunch of implementation issues. Having types nested in inner scopes (e.g. functions, blocks, etc.) can be useful for privacy/encapsulation. For example, some types are only used within a function to execute a function's body, so it can make sense to scope that type to the function itself.

Implementing this feature can get a little complicated though because it changes the algorithm we use to pickup declarations. Consider the following program:

struct Foo {
   x: i64,
}

impl Foo {
    fn new() -> Foo {
        Foo {x: 3}
    }
}

fn main() {
    let f = Foo::new();
    f.wow();

    let q = 4;
    if q > 5 {
        impl Foo {
            fn wow() {
                 println!("wow!");
            }
        }
    }
}

This program is written to be intentionally misleading. It is however completely correct and will execute with no issues. The misleading part is that because the impl block is inside the if, we assume that the method may only become available if the condition is true at runtime. This is not the case however.

Critically, our name resolution algorithm has to change to extract declaration information from all levels of the syntax tree (including submodules once we have a module system). This is the only way to ensure that inner impl blocks like this still add inherent methods to the type they refer to, regardless of the location of that type.

If we naively continue with our currently algorithm, we'll pickup the outer impl block but only see the inner one once we walk the conditional statement.

The tricky thing with this is that although we can walk the tree recursively and pickup impls along the way, we cannot do the same with types. The type hierarchy needs to be recorded, but not flattened. We can't just walk impls first and then do types later because impls require types to already be resolved so we can figure out which type the impl belongs to.

impl Foo {
    fn new() -> Foo {
        Foo {x: 3}
    }
}

fn main() {
    let f = Foo::new();
    f.wow();

    let q = 4;
    if q > 5 {
        impl Foo {
            fn wow() {
                 println!("wow!");
            }
        }
        
        struct Bar {}
    }

    let bar = Bar {}; // Error!
}

struct Foo {
   x: i64,
}

This is a valid program except for the line at the end of main that references Bar. Notice that the types need to be resolved before the impl blocks. The whole syntax tree needs to be walked to collect all the impl blocks for each type. The namespace hierarchy needs to be recorded in order for the usage of Bar outside of its scope to be an error.

Rust uses a structure of "ribs" to collect the namespace hierarchy. We can potentially do the same. The only tricky thing is that we would need to design the data structure to allow us to maintain our current position in the ribs as we recurse down the syntax tree.

created time in 8 days

push eventsunjay/pea

Sunjay Varma

commit sha 4d906f60776f62662e8ae36f0c8079aea58d42bb

Resolving struct literals by storing field names from struct decl

view details

push time in 9 days

push eventsunjay/pea

Sunjay Varma

commit sha 0efe989009cbdf0fc6203668e07a0809ba27e0d3

Added missing span methods for FuncDecl and nir::FuncParam

view details

Sunjay Varma

commit sha 273847aaf7d4bbc909dcc86482e4fa5f6beb565b

Name resolution for struct decls

view details

push time in 9 days

push eventsunjay/pea

Sunjay Varma

commit sha 7f934c0d425c6cac591242e8fa2baab3eba778eb

Fixed parsing ambiguity in conditions introduced by struct literal syntax

view details

push time in 9 days

push eventsunjay/pea

Sunjay Varma

commit sha 24963912de4bcd305e750affd8cc688b26a9ef54

Parsing struct declarations and struct literals

view details

push time in 9 days

PR closed sunjay/turtle

Update tokio requirement from 0.2 to 0.3 dependencies

Updates the requirements on tokio to permit the latest version. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/tokio-rs/tokio/releases">tokio's releases</a>.</em></p> <blockquote> <h2>Tokio v0.2.22</h2> <p>This release introduces initial support for <a href="https://crates.io/crates/tracing"><code>tracing</code></a> instrumentation within the Tokio runtime, enabled by the "tracing" feature flag. In addition, it contains a number of bug fixes and API additions.</p> <h3>Fixes</h3> <ul> <li>docs: misc improvements (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2572">#2572</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2658">#2658</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2663">#2663</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2656">#2656</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2647">#2647</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2630">#2630</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2487">#2487</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2621">#2621</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2624">#2624</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2600">#2600</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2623">#2623</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2622">#2622</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2577">#2577</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2569">#2569</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2589">#2589</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2575">#2575</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2540">#2540</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2564">#2564</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2567">#2567</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2520">#2520</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2521">#2521</a>, <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2493">#2493</a>)</li> <li>rt: allow calls to <code>block_on</code> inside calls to <code>block_in_place</code> that are themselves inside <code>block_on</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2645">#2645</a>)</li> <li>net: fix non-portable behavior when dropping <code>TcpStream</code> <code>OwnedWriteHalf</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2597">#2597</a>)</li> <li>io: improve stack usage by allocating large buffers on directly on the heap (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2634">#2634</a>)</li> <li>io: fix unsound pin projection in <code>AsyncReadExt::read_buf</code> and <code>AsyncWriteExt::write_buf</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2612">#2612</a>)</li> <li>io: fix unnecessary zeroing for <code>AsyncRead</code> implementors (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2525">#2525</a>)</li> <li>io: Fix <code>BufReader</code> not correctly forwarding <code>poll_write_buf</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2654">#2654</a>)</li> <li>io: fix panic in <code>AsyncReadExt::read_line</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2541">#2541</a>)</li> </ul> <h3>Changes</h3> <ul> <li>coop: returning <code>Poll::Pending</code> no longer decrements the task budget (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2549">#2549</a>)</li> </ul> <h3>Added</h3> <ul> <li>io: little-endian variants of <code>AsyncReadExt</code> and <code>AsyncWriteExt</code> methods (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/1915">#1915</a>)</li> <li>task: add <a href="https://crates.io/crates/tracing"><code>tracing</code></a> instrumentation to spawned tasks (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2655">#2655</a>)</li> <li>sync: allow unsized types in <code>Mutex</code> and <code>RwLock</code> (via <code>default</code> constructors) (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2615">#2615</a>)</li> <li>net: add <code>ToSocketAddrs</code> implementation for <code>&[SocketAddr]</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2604">#2604</a>)</li> <li>fs: add <code>OpenOptionsExt</code> for <code>OpenOptions</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2515">#2515</a>)</li> <li>fs: add <code>DirBuilder</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2524">#2524</a>)</li> </ul> <p>Signed-off-by: Eliza Weisman <a href="mailto:eliza@buoyant.io">eliza@buoyant.io</a></p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/tokio-rs/tokio/commit/21f726041cf9a4ca408d97394af220caf90312ed"><code>21f7260</code></a> chore: prepare to release 0.2.22 (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2672">#2672</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/c344aac9252c34fcce196200a99529734b5cb9e8"><code>c344aac</code></a> sync: support larger number of semaphore permits (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2607">#2607</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/cbb4abc8aeee1f7304ce6c0d6b160ce99dd2c8cf"><code>cbb4abc</code></a> chore: add audit check (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2595">#2595</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/14723f9786260ad115aae788c9753a44edf0394d"><code>14723f9</code></a> doc: update links in README.md and CONTRIBUTING.md (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2609">#2609</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/04a2826084743e80762a32fcee912a3dfbb86a63"><code>04a2826</code></a> provide a way to drop a runtime in an async context (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2646">#2646</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/28a93e604454d435476eb8bb2eee809fd86b001d"><code>28a93e6</code></a> Update doc comments (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2572">#2572</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/dd28831e1301f09b992dabf5f9e47656ee6d981c"><code>dd28831</code></a> io: Forward poll_write_buf on BufReader (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2654">#2654</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/6dcce1901a53f099bf10f242943b44010f264171"><code>6dcce19</code></a> sync: remove misleading comment (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2666">#2666</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/32f46d7b883e1447833630464f168bb160fb51c9"><code>32f46d7</code></a> time: improve Entry field comment (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2671">#2671</a>)</li> <li><a href="https://github.com/tokio-rs/tokio/commit/356c81c97780f69f0897f4797d87a9cc2620678c"><code>356c81c</code></a> dns: document that strings require the DNS feature (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/2663">#2663</a>)</li> <li>Additional commits viewable in <a href="https://github.com/tokio-rs/tokio/compare/tokio-0.2.0...tokio-0.2.22">compare view</a></li> </ul> </details> <br />

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
  • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot dashboard:

  • Update frequency (including time of day and day of week)
  • Pull request limits (per update run and/or open at any time)
  • Automerge options (never/patch/minor, and dev/runtime dependencies)
  • Out-of-range updates (receive only lockfile updates, if desired)
  • Security updates (receive only security updates, if desired)

</details>

+1 -1

1 comment

1 changed file

dependabot-preview[bot]

pr closed time in 9 days

pull request commentsunjay/turtle

Update tokio requirement from 0.2 to 0.3

There are quite a few changes with this, many quite subtle, so I'll be doing it myself.

dependabot-preview[bot]

comment created time in 9 days

issue openedsunjay/pea

Mutability Analysis

Idea: Make variables immutable by default (like Rust) and only allow variables/function parameters to be mutated if they are explicitly marked mut. This requires some static analysis to make sure that immutable variables are never assigned to and that immutable variables are never passed as a mutable function parameter.

struct Foo {
    value: i64,
}

fn foo(mut x: Foo, y: Foo) {
    x.value = x.value + y.value;
    x = y; // Okay: Reassigns the local `x`, but the value passed in is still a rvalue
    y = x; // Error!
    y.value = -32; // Error!
}

fn main() {
    let q = Foo {value: 33};
    q.value = 3; // Error!
    q = Foo {value: 1}; // Error!
    foo(q, q); // Error!

    let mut r = q;
    foo(r, q); // Okay: changes the `value` of r
    foo(r, r); // Okay: reference to `r` is used for both parameters
    foo(q, r); // Error!

    r = q; // Okay: `r` is reassigned to `q` (not a deep clone)
    r.value = -32; // Okay: `r` and `q` have a `value` of `-32`
}

created time in 10 days

issue closedsunjay/turtle

Bug: turtle crashes when using std::env, only fixed on current git.

When compiling a program using turtle as well as std::env, an unnamed thread panics because of failed IPC on Manjaro Linux (kernel version 5.8.11-1). Minimal example:

use turtle::Turtle;
use std::env;

fn main() {
    for a in env::args() {
        println!("{}", a);
    }
    let mut turtle = Turtle::new();
}

I reproduced this with the crates.io version as well as the website-linked git version, only the current git version runs correctly. Here the panic:

    Finished dev [unoptimized + debuginfo] target(s) in 3.07s
     Running `target/debug/hilbert`
target/debug/hilbert
thread '<unnamed>' panicked at 'bug: failed to read response from renderer process', /home/fl0wless/.cargo/git/checkouts/turtle-7d4ec58877c500b9/bf64b83/src/messenger.rs:41:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The same bug with direct invocation and as release build. I don't know if this happens on other platforms, it would be great if those repos were updated.

closed time in 11 days

Fl0wless

issue commentsunjay/turtle

Bug: turtle crashes when using std::env, only fixed on current git.

I appreciate the report. Hope that got it resolved. :)

Fl0wless

comment created time in 11 days

issue commentsunjay/turtle

Bug: turtle crashes when using std::env, only fixed on current git.

Thanks for reporting this! This is actually expected behavior. Please see the start function in the docs for a way to resolve the issue: https://docs.rs/turtle/1.0.0-rc.3/turtle/fn.start.html

Let me know if you have any other questions :)

Fl0wless

comment created time in 11 days

PR closed sunjay/turtle

Reformat codebase using standard style

As recently discussed, the current codebase declares a non-standard style in its .rustfmt.toml configuration file. However, that style is not used, as running cargo fmt changes a lot of files. Therefore this PR removes the rustfmt configuration and reformats the whole codebase. As an additional feature, a style check has been added to the CI jobs in order to enforce and normalize a project style. CONTRIBUTING.md has been updated accordingly.

+1674 -1071

2 comments

65 changed files

PaulDance

pr closed time in 13 days

pull request commentsunjay/turtle

Reformat codebase using standard style

Hi Paul, I'm still not satisfied with rustfmt's current formatting. I'll re-evaluate using it in a couple of months. Please try to be patient until then.

PaulDance

comment created time in 13 days

push eventsunjay/pea

Sunjay Varma

commit sha 38be9203fa36aa70ce0b57584b76fa4315ec15d0

Removed specialized opcodes for different operators now that we are using method resolution for that

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha bb625bf5fef86d7a151f28cd505b0e50d6c4f07b

Forgot to check for divide/remainder by zero in prelude

view details

Sunjay Varma

commit sha c22b36f9bd1672ded290000585865af2e3a1e6eb

Desugaring operators as method calls and reusing method call resolution code

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 8397345c118cf24466c39d5cea8cbd3c5a2a3312

Added a space before the return type arrow when displaying a function type

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 58dfb6bbb53750b7018bff90ab8ad50a21d8f5a3

Adding min/max method to i64 and u8 to complete method call tests

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 220accaa056cabf04f56135dcca6f68736aaaca4

Using `PrimMethods` to implement method lookup in type inference based on current receiver type + desugaring method calls into function calls

view details

push time in 14 days

push eventsunjay/turtle

Paul Mabileau

commit sha c4bed54c4f7f6652a967779a5e32de9478f76b35

Add arc_left and arc_right methods to Turtle They block on corresponding AsyncTurtle methods. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha 1c1c5dfb1e14bac2c0b0a22633686d763cdb4722

Add arc_left and arc_right methods on AsyncTurtle They call the circular_arc method of ProtocolClient with adapted values. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha 4500d5c28c2bbdde3aa0ce849a26b039a364b63c

Add circular_arc method on ProtocolClient Classical implementation for now: splits the arc in many forward movements and rotations. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha a32d75f4f1be28674157c6303a2c72ee67964e4b

Add zero, NaN, Inf and -Inf tests for arc methods They go in the `turtle::tests::ignores_nan_inf_zero` function and check that all the possible combinations of those do not make the turtle move. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha e7f1815bdeea0640782dba9c9c378b326fc5d728

Add documentation to arc methods It should provide good explanations of both methods with dedicated and thourough examples. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha d4b59759224fcc6eb3cad0a733d3e9e69f76deb0

Add unstable attributes to new arc methods Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha 712b2e0bcc9b6e21b2c8ee0b7e991bc78763f4eb

Add example illustrating the new arc methods It draws a simple flower only using arcs, rotations and fills. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha bdac20cb8ca9e686abbd736e097d0ee3479b2cf2

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 <sunjay@users.noreply.github.com>

view details

push time in 14 days

PR merged sunjay/turtle

Implement #82: Add an arc method

This is part of #82 by following the mentoring instructions. However, only the part 1 is covered in the current state, hence the draft. Part 2 will be implemented when the intermediate review is finished and adequate instructions completed.

Steps of the issue that have been covered:

  • [x] Step 1: Add methods on Turtle called arc_left and arc_right that block on corresponding methods on AsyncTurtle.
  • [x] Step 2: Add arc_left and arc_right asynchronous methods on AsyncTurtle that await on a new circular_arc method on ProtocolClient.
  • [x] Step 3: Add the circular_arc method on ProtocolClient.
    • [x] Signature changed from issue: added the necessary TurtleId.
    • [x] Implementation with inscribed fixed-sized regular polygon approximation
    • [x] using the move_forward and rotate_in_place methods.
    • [ ] No changes to Radians.
  • [x] Documentation
    • [x] Major points should be covered.
    • [x] Detailed examples with assertions.
  • [x] New flower example illustrating arcs
  • [x] using different pen sizes.
  • [x] Abnormal cases are ignored: new tests cover that in turtle::tests::ignores_nan_inf_zero.
  • [x] The methods are marked as "unstable".
  • [x] Tests run fine.

The documentation looks like this for now:

image image image image

As a general comment, the overall structure should be satisfying, it is quite simple after all. However, the current implementation interestingly performs very poorly: it is imprecise, very slow, laggy and gets worse over time. That could be caused by a mistake or just by the simplistic algorithm used that generates hundreds of IPC requests. Either way, it is definitely not the intended final state.

+300 -0

2 comments

4 changed files

PaulDance

pr closed time in 14 days

PullRequestReviewEvent

push eventsunjay/pea

Sunjay Varma

commit sha 78e9e1c0e0fe725a931b3117a0208956bef790e3

Populating methods for all primitive types into a new methods table returned by the prelude

view details

push time in 14 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the

"itself" refers to the arc here. I think this confusion points to the fact that this sentence should probably just be rewritten.

PaulDance

comment created time in 14 days

PullRequestReviewEvent

push eventsunjay/pea

Sunjay Varma

commit sha 6416e1a0893871e79c68280b8b4fe9a4ba40abdc

Forgot to recursively call macros for generating impls for PrimFuncTy and IntoNativeFunc

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 18b1b024f3ebdc7bc6587c2192298f489b2d12be

Disabling stress tests on windows

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 195ebedf5194eb67da277587a9ec1a38e77e8701

Adding GC stress test to CI

view details

push time in 14 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl ProtocolClient {         }     } +    pub async fn circular_arc(&self, id: TurtleId, radius: Distance, extent: Radians, direction: RotationDirection) {+        if radius.is_normal() && extent.is_normal() {+            let steps = 250;    // Arbitrary value for now.+            let step = radius.abs() * extent.to_radians() / steps as f64;+            let rotation = radius.signum() * extent / steps as f64;++            for _ in 0..steps {+                self.move_forward(id, step).await;+                self.rotate_in_place(id, rotation, direction).await;+            }+        }

Let's make the change to keep this code consistent with the rest of the file. I don't think this condition is important enough to wrap the rest of the code in the function. It's fairly easy to understand that we're checking is_normal and returning early if either parameter is a value we can't use.

PaulDance

comment created time in 14 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

+//! Draws a simple geometric sort of flower with customizable dimensions.+//!+//! This example makes extensive use of the turtle arc methods: [`arc_left`] and [`arc_right`].+//! They both provide the ability to draw a circular arc defined by the given `radius` and `extent`+//! parameters, while the first makes the turtle draw it to the left and the second to the right.++use turtle::{Angle, Distance, Drawing};++const TURTLE_SPEED: &str = "faster";+const BOTTOM_MARGIN: Distance = 25.0;++const LEAF_FILL_COLOR: &str = "green";+const LEAF_BORDER_COLOR: &str = "dark green";+const LEAF_BORDER_WIDTH: Distance = 1.0;+const LEFT_LEAF_RADIUS: Distance = 200.0;+const LEFT_LEAF_EXTENT: Angle = 45.0;+const RIGHT_LEAF_INCLINATION: Angle = 15.0;+const RIGHT_LEAF_BOTTOM_RADIUS: Distance = 250.0;+const RIGHT_LEAF_BOTTOM_EXTENT: Angle = 45.0;+const RIGHT_LEAF_TOP_RADIUS: Distance = 157.0;+const RIGHT_LEAF_TOP_EXTENT: Angle = 75.0;++const TRUNK_COLOR: &str = LEAF_BORDER_COLOR;+const TRUNK_WIDTH: Distance = 3.0;+const TRUNK_PIECE_COUNT: usize = 4;+const TRUNK_PIECE_RADIUS: Distance = 500.0;+const TRUNK_PIECE_EXTENT: Angle = 15.0;++const PETALS_COUNT: usize = 4;+const PETALS_FILL_COLOR: &str = "purple";+const PETALS_BORDER_COLOR: &str = "dark purple";+const PETALS_BORDER_WIDTH: Distance = LEAF_BORDER_WIDTH;+const PETALS_INIT_LEFT: Angle = 65.0;+const PETALS_SIDE_RADIUS: Distance = 80.0;+const PETALS_SIDE_EXTENT: Angle = 90.0;+const PETALS_SPACE_GAP: Angle = 20.0;+const PETALS_SPACE_RADIUS: Distance = 40.0;+const PETALS_SPACE_EXTENT: Angle = 30.0;++fn main() {+    // Acquiring resources.+    let mut drawing = Drawing::new();+    let size = drawing.size();+    let mut turtle = drawing.add_turtle();++    // Initial positioning.+    turtle.set_speed("instant");+    turtle.pen_up();+    turtle.go_to([+        -(size.width as f64) / 6.0,+        -(size.height as f64) / 2.0 + BOTTOM_MARGIN,+    ]);+    turtle.pen_down();++    // Setup.+    turtle.use_degrees();+    turtle.set_speed(TURTLE_SPEED);++    // Body.+    turtle.set_fill_color(LEAF_FILL_COLOR);+    turtle.set_pen_color(LEAF_BORDER_COLOR);++    for _ in 0..TRUNK_PIECE_COUNT {+        // Leaves:+        turtle.set_pen_size(LEAF_BORDER_WIDTH);+        turtle.set_pen_color(LEAF_BORDER_COLOR);+        turtle.begin_fill();++        // Left leaf.+        turtle.arc_left(LEFT_LEAF_RADIUS, LEFT_LEAF_EXTENT);+        turtle.right(LEFT_LEAF_EXTENT);+        turtle.arc_right(LEFT_LEAF_RADIUS, -LEFT_LEAF_EXTENT);+        turtle.right(LEFT_LEAF_EXTENT);++        // Right leaf.+        turtle.right(RIGHT_LEAF_INCLINATION);+        turtle.arc_right(RIGHT_LEAF_BOTTOM_RADIUS, RIGHT_LEAF_BOTTOM_EXTENT);+        turtle.right(RIGHT_LEAF_INCLINATION);+        turtle.arc_right(RIGHT_LEAF_TOP_RADIUS, -RIGHT_LEAF_TOP_EXTENT);

Keep in mind that this code is for illustration purposes only, so it's okay to put in something illustrative like this even though you'd probably never do that in real life. The point is to demonstrate the effect of the negative radius, even though it's likely that you'd probably prefer to use the other method here.

If you can find a better place for it I am totally fine with that. I just want to make sure we have the negative radius case covered somewhere.

PaulDance

comment created time in 14 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the

Yeah usually that expression is used with a variable, e.g. "the store is x km away". It doesn't really read well with the type. You could try phrasing the sentence differently, but I think just changing it to "radius units away" will fix it.

PaulDance

comment created time in 14 days

PullRequestReviewEvent

push eventsunjay/pea

Sunjay Varma

commit sha ec5a2bb7c0a3bfcff7841aece161b975f21888dc

Forgot to trace name when the field changed to Gc<str>

view details

push time in 14 days

push eventsunjay/pea

Sunjay Varma

commit sha 888146d0265f1eb0cd4c223bc1fd69a4926ffcc4

Using `Gc<str>` instead of `Arc<str>` for function name in value (matches prim::Func to prim::NativeFunc)

view details

Sunjay Varma

commit sha 192e2bc0c1664e01f1d2078daafec1bb70113ca7

Allowing native functions to be called

view details

push time in 15 days

push eventsunjay/pea

Sunjay Varma

commit sha 4ba8889ead1b78787352a64b02fe273732420867

Resolving ConstIds from prelude in codegen

view details

push time in 15 days

push eventsunjay/pea

Sunjay Varma

commit sha 6007df86d47aaaf04cca7ccfe602fddaa27063d3

Type checking items from prelude

view details

push time in 15 days

push eventsunjay/pea

Sunjay Varma

commit sha 9f4241b10fffb69900373be0fdec772d22b1b0bc

Adding type information to package by making native functions typed

view details

push time in 15 days

push eventsunjay/pea

Sunjay Varma

commit sha 8dbf544a6c9a91a651f93a2444d63a8d74a70ee2

Allowing names to be looked up in the prelude when they aren't found in any scope

view details

push time in 15 days

pull request commentsunjay/turtle

Implement #82: Add an arc method

Please also rebase this branch when you get a chance. :)

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///+    /// # Example+    ///+    /// ```rust+    /// # use turtle::Turtle;+    /// let mut turtle = Turtle::new();+    ///+    /// // No movement when anormal.+    /// turtle.arc_left(0.0, 1.0);+    /// turtle.arc_left(f64::NAN, -f64::INFINITY);+    /// assert_eq!(turtle.position(), [0.0, 0.0].into());+    /// assert_eq!(turtle.heading(), 90.0);+    ///+    /// // Quarter of a circle.+    /// turtle.arc_left(100.0, 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Full circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0);+    /// assert!((turtle.position() - [0.0, 0.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 90.0).abs() <= 0.1);+    ///+    /// // Full + quarter circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0 + 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 2.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Negative radius: flip center to the right.+    /// turtle.reset();+    /// turtle.arc_left(-100.0, 90.0);+    /// assert!((turtle.position() - [100.0, 100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    ///+    /// // Negative extent: go backwards to the left.+    /// turtle.reset();+    /// turtle.arc_left(100.0, -90.0);+    /// assert!((turtle.position() - [-100.0, -100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    /// ```+    #[cfg(feature = "unstable")]+    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]+    pub fn arc_left(&mut self, radius: Distance, extent: Angle) {+        block_on(self.turtle.arc_left(radius, extent))+    }++    /// Draw a circular arc starting at the current position and going to the right of the turtle,+    /// thus globally turning clockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the right of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the left.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its right. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///+    /// # Example+    ///+    /// ```rust+    /// # use turtle::Turtle;+    /// let mut turtle = Turtle::new();+    ///+    /// // No movement when anormal.+    /// turtle.arc_right(0.0, 1.0);+    /// turtle.arc_right(f64::NAN, -f64::INFINITY);

same as above

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///+    /// # Example+    ///+    /// ```rust+    /// # use turtle::Turtle;+    /// let mut turtle = Turtle::new();+    ///+    /// // No movement when anormal.+    /// turtle.arc_left(0.0, 1.0);+    /// turtle.arc_left(f64::NAN, -f64::INFINITY);+    /// assert_eq!(turtle.position(), [0.0, 0.0].into());+    /// assert_eq!(turtle.heading(), 90.0);+    ///+    /// // Quarter of a circle.+    /// turtle.arc_left(100.0, 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Full circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0);+    /// assert!((turtle.position() - [0.0, 0.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 90.0).abs() <= 0.1);+    ///+    /// // Full + quarter circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0 + 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 2.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Negative radius: flip center to the right.+    /// turtle.reset();+    /// turtle.arc_left(-100.0, 90.0);+    /// assert!((turtle.position() - [100.0, 100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    ///+    /// // Negative extent: go backwards to the left.+    /// turtle.reset();+    /// turtle.arc_left(100.0, -90.0);+    /// assert!((turtle.position() - [-100.0, -100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    /// ```+    #[cfg(feature = "unstable")]+    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]+    pub fn arc_left(&mut self, radius: Distance, extent: Angle) {+        block_on(self.turtle.arc_left(radius, extent))+    }++    /// Draw a circular arc starting at the current position and going to the right of the turtle,+    /// thus globally turning clockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the right of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the left.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its right. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///

same as above

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 mod tests {         turtle.wait(::std::f64::INFINITY);         turtle.wait(-::std::f64::INFINITY); +        turtle.arc_left(0.0, 0.0);+        turtle.arc_left(0.0, f64::NAN);+        turtle.arc_left(0.0, f64::INFINITY);+        turtle.arc_left(0.0, -f64::INFINITY);+        turtle.arc_left(f64::NAN, 0.0);+        turtle.arc_left(f64::NAN, f64::NAN);+        turtle.arc_left(f64::NAN, f64::INFINITY);+        turtle.arc_left(f64::NAN, -f64::INFINITY);+        turtle.arc_left(f64::INFINITY, 0.0);+        turtle.arc_left(f64::INFINITY, f64::NAN);+        turtle.arc_left(f64::INFINITY, f64::INFINITY);+        turtle.arc_left(f64::INFINITY, -f64::INFINITY);+        turtle.arc_left(-f64::INFINITY, 0.0);+        turtle.arc_left(-f64::INFINITY, f64::NAN);+        turtle.arc_left(-f64::INFINITY, f64::INFINITY);+        turtle.arc_left(-f64::INFINITY, -f64::INFINITY);++        turtle.arc_right(0.0, 0.0);+        turtle.arc_right(0.0, f64::NAN);+        turtle.arc_right(0.0, f64::INFINITY);+        turtle.arc_right(0.0, -f64::INFINITY);+        turtle.arc_right(f64::NAN, 0.0);+        turtle.arc_right(f64::NAN, f64::NAN);+        turtle.arc_right(f64::NAN, f64::INFINITY);+        turtle.arc_right(f64::NAN, -f64::INFINITY);+        turtle.arc_right(f64::INFINITY, 0.0);+        turtle.arc_right(f64::INFINITY, f64::NAN);+        turtle.arc_right(f64::INFINITY, f64::INFINITY);+        turtle.arc_right(f64::INFINITY, -f64::INFINITY);+        turtle.arc_right(-f64::INFINITY, 0.0);+        turtle.arc_right(-f64::INFINITY, f64::NAN);+        turtle.arc_right(-f64::INFINITY, f64::INFINITY);+        turtle.arc_right(-f64::INFINITY, -f64::INFINITY);

Thanks for adding these unit tests! Appreciate you looking through and thinking of this. 😁

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///+    /// # Example+    ///+    /// ```rust+    /// # use turtle::Turtle;+    /// let mut turtle = Turtle::new();+    ///+    /// // No movement when anormal.+    /// turtle.arc_left(0.0, 1.0);+    /// turtle.arc_left(f64::NAN, -f64::INFINITY);

Deleting for the same reason as above.

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///

Let's not document this for now. It's not documented anywhere else and I haven't actually decided yet if "silently fail" is the right way to go here. Explicitly documenting the behaviour is a bit more of a commitment than I want to make right now.

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.

I haven't had time to rework this, but I think it can be explained a bit clearer if you try rewriting it. No worries if this is all we can do for now. We can always rework later. (Similar comment for this bullet in arc_right)

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

+//! Draws a simple geometric sort of flower with customizable dimensions.+//!+//! This example makes extensive use of the turtle arc methods: [`arc_left`] and [`arc_right`].+//! They both provide the ability to draw a circular arc defined by the given `radius` and `extent`+//! parameters, while the first makes the turtle draw it to the left and the second to the right.++use turtle::{Angle, Distance, Drawing};++const TURTLE_SPEED: &str = "faster";+const BOTTOM_MARGIN: Distance = 25.0;++const LEAF_FILL_COLOR: &str = "green";+const LEAF_BORDER_COLOR: &str = "dark green";+const LEAF_BORDER_WIDTH: Distance = 1.0;+const LEFT_LEAF_RADIUS: Distance = 200.0;+const LEFT_LEAF_EXTENT: Angle = 45.0;+const RIGHT_LEAF_INCLINATION: Angle = 15.0;+const RIGHT_LEAF_BOTTOM_RADIUS: Distance = 250.0;+const RIGHT_LEAF_BOTTOM_EXTENT: Angle = 45.0;+const RIGHT_LEAF_TOP_RADIUS: Distance = 157.0;+const RIGHT_LEAF_TOP_EXTENT: Angle = 75.0;++const TRUNK_COLOR: &str = LEAF_BORDER_COLOR;+const TRUNK_WIDTH: Distance = 3.0;+const TRUNK_PIECE_COUNT: usize = 4;+const TRUNK_PIECE_RADIUS: Distance = 500.0;+const TRUNK_PIECE_EXTENT: Angle = 15.0;++const PETALS_COUNT: usize = 4;+const PETALS_FILL_COLOR: &str = "purple";+const PETALS_BORDER_COLOR: &str = "dark purple";+const PETALS_BORDER_WIDTH: Distance = LEAF_BORDER_WIDTH;+const PETALS_INIT_LEFT: Angle = 65.0;+const PETALS_SIDE_RADIUS: Distance = 80.0;+const PETALS_SIDE_EXTENT: Angle = 90.0;+const PETALS_SPACE_GAP: Angle = 20.0;+const PETALS_SPACE_RADIUS: Distance = 40.0;+const PETALS_SPACE_EXTENT: Angle = 30.0;++fn main() {+    // Acquiring resources.+    let mut drawing = Drawing::new();+    let size = drawing.size();+    let mut turtle = drawing.add_turtle();++    // Initial positioning.+    turtle.set_speed("instant");+    turtle.pen_up();+    turtle.go_to([+        -(size.width as f64) / 6.0,+        -(size.height as f64) / 2.0 + BOTTOM_MARGIN,+    ]);+    turtle.pen_down();++    // Setup.+    turtle.use_degrees();+    turtle.set_speed(TURTLE_SPEED);++    // Body.+    turtle.set_fill_color(LEAF_FILL_COLOR);+    turtle.set_pen_color(LEAF_BORDER_COLOR);++    for _ in 0..TRUNK_PIECE_COUNT {+        // Leaves:+        turtle.set_pen_size(LEAF_BORDER_WIDTH);+        turtle.set_pen_color(LEAF_BORDER_COLOR);+        turtle.begin_fill();++        // Left leaf.+        turtle.arc_left(LEFT_LEAF_RADIUS, LEFT_LEAF_EXTENT);+        turtle.right(LEFT_LEAF_EXTENT);+        turtle.arc_right(LEFT_LEAF_RADIUS, -LEFT_LEAF_EXTENT);+        turtle.right(LEFT_LEAF_EXTENT);++        // Right leaf.+        turtle.right(RIGHT_LEAF_INCLINATION);+        turtle.arc_right(RIGHT_LEAF_BOTTOM_RADIUS, RIGHT_LEAF_BOTTOM_EXTENT);+        turtle.right(RIGHT_LEAF_INCLINATION);+        turtle.arc_right(RIGHT_LEAF_TOP_RADIUS, -RIGHT_LEAF_TOP_EXTENT);
        // Note that `arc_left` with a negative radius is the same as calling `arc_right`.
        // This is used below for illustration purposes only. You'd probably want to use
        // `arc_right` in real code.
        turtle.arc_left(-RIGHT_LEAF_BOTTOM_RADIUS, RIGHT_LEAF_BOTTOM_EXTENT);
        turtle.right(RIGHT_LEAF_INCLINATION);
        turtle.arc_left(-RIGHT_LEAF_TOP_RADIUS, -RIGHT_LEAF_TOP_EXTENT);

I think it's a good idea to demonstrate what happens if radius is negative, even if this usage is a bit contrived. It both helps the learner reading this and helps us with our testing. I may have just missed something, but I didn't see you use this anywhere else, so I added it here. Feel free to pick a better spot if you have one in mind.

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl ProtocolClient {         }     } +    pub async fn circular_arc(&self, id: TurtleId, radius: Distance, extent: Radians, direction: RotationDirection) {+        if radius.is_normal() && extent.is_normal() {+            let steps = 250;    // Arbitrary value for now.+            let step = radius.abs() * extent.to_radians() / steps as f64;+            let rotation = radius.signum() * extent / steps as f64;++            for _ in 0..steps {+                self.move_forward(id, step).await;+                self.rotate_in_place(id, rotation, direction).await;+            }+        }

The top if statement is more of a guard than anything else so let's just do what the rest of the code in this file does and return immediately from it. That reduces the level of indentation for the rest of the code.

        if !radius.is_normal() || !extent.is_normal() {
            return;
        }

        let steps = 250;    // Arbitrary value for now.
        let step = radius.abs() * extent.to_radians() / steps as f64;
        let rotation = radius.signum() * extent / steps as f64;

        for _ in 0..steps {
            self.move_forward(id, step).await;
            self.rotate_in_place(id, rotation, direction).await;
        }
PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the
    ///  * `radius` places the center of the arc itself `radius` units away from the left of the

nit: I think you mean radius units away (Distance is the type, not the value/variable).

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

 impl Turtle {         block_on(self.turtle.wait(secs))     } +    /// Draw a circular arc starting at the current position and going to the left of the turtle,+    /// thus globally turning counterclockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the left of the+    ///    turtle, with respect to its current orientation. When negative, it does so to the right.+    ///  * `extent` controls how much of the arc is to be drawn, that is to say the `Angle` that+    ///    forms the circular portion of the given `radius`. When negative, the turtle moves+    ///    backwards instead, but it still goes to its left. It can also be greater than the+    ///    turtle's current angle unit domain limit, i.e. 360° when using degrees or 2π when using+    ///    radians: the turtle will simply continue to draw until the complete angle is reached.+    ///+    /// This method does *nothing* if either one of the provided arguments is not "normal" in the+    /// sense of [floating-point numbers' definition](f64::is_normal) of it.+    ///+    /// # Example+    ///+    /// ```rust+    /// # use turtle::Turtle;+    /// let mut turtle = Turtle::new();+    ///+    /// // No movement when anormal.+    /// turtle.arc_left(0.0, 1.0);+    /// turtle.arc_left(f64::NAN, -f64::INFINITY);+    /// assert_eq!(turtle.position(), [0.0, 0.0].into());+    /// assert_eq!(turtle.heading(), 90.0);+    ///+    /// // Quarter of a circle.+    /// turtle.arc_left(100.0, 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Full circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0);+    /// assert!((turtle.position() - [0.0, 0.0].into()).len() <= 0.5);+    /// assert!((turtle.heading() - 90.0).abs() <= 0.1);+    ///+    /// // Full + quarter circle.+    /// turtle.reset();+    /// turtle.arc_left(100.0, 360.0 + 90.0);+    /// assert!((turtle.position() - [-100.0, 100.0].into()).len() <= 2.5);+    /// assert!((turtle.heading() - 180.0).abs() <= 0.1);+    ///+    /// // Negative radius: flip center to the right.+    /// turtle.reset();+    /// turtle.arc_left(-100.0, 90.0);+    /// assert!((turtle.position() - [100.0, 100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    ///+    /// // Negative extent: go backwards to the left.+    /// turtle.reset();+    /// turtle.arc_left(100.0, -90.0);+    /// assert!((turtle.position() - [-100.0, -100.0].into()).len() <= 0.5);+    /// assert!(turtle.heading().abs().min((turtle.heading() - 360.0).abs()) <= 0.1);+    /// ```+    #[cfg(feature = "unstable")]+    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]+    pub fn arc_left(&mut self, radius: Distance, extent: Angle) {+        block_on(self.turtle.arc_left(radius, extent))+    }++    /// Draw a circular arc starting at the current position and going to the right of the turtle,+    /// thus globally turning clockwise.+    ///+    /// It is configured through the `radius` and `extent` arguments:+    ///  * `radius` places the center of the arc itself `Distance` units away from the right of the
    ///  * `radius` places the center of the arc itself `radius` units away from the right of the

same as above

PaulDance

comment created time in 15 days

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

+//! Draws a simple geometric sort of flower with customizable dimensions.

Wow! This example is gorgeous. Definitely something for the examples README. (Maybe in a follow-up PR?)

image

Great work! 🎉 🎉 😁 🌹

PaulDance

comment created time in 15 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Implement #82: Add an arc method

+//! Draws a simple geometric sort of flower with customizable dimensions.+//!+//! This example makes extensive use of the turtle arc methods: [`arc_left`] and [`arc_right`].+//! They both provide the ability to draw a circular arc defined by the given `radius` and `extent`+//! parameters, while the first makes the turtle draw it to the left and the second to the right.++use turtle::{Angle, Distance, Drawing};
// To run this example, use the command: cargo run --features unstable --example flower
#[cfg(all(not(feature = "unstable")))]
compile_error!("This example relies on unstable features. Run with `--features unstable`");

use turtle::{Angle, Distance, Drawing};

Like the other examples that use unstable features, let's add this line so people know the command they need to use to run it.

PaulDance

comment created time in 15 days

PullRequestReviewEvent

push eventsunjay/pea

Sunjay Varma

commit sha b56cbcd63afbab56b77409eb68ff9ec448734257

Allowing creation of Gc<str> from Arc<str>

view details

Sunjay Varma

commit sha 15dfff71aff9a88ee617fc9efcab5c47280897bf

Allowing any function or closure to be turned into a native function and using that to add `clock` native function to prelude

view details

push time in 16 days

issue commentsunjay/turtle

Flood Fill

Sure, yeah. That name makes sense too. The fill name was mainly to refer back to the corresponding Logo command. Adherence to that is not mandatory.

sunjay

comment created time in 16 days

issue commentsunjay/turtle

Flood Fill

Yes. Those methods do not perform a flood fill. They fill the path that the turtle is currently drawing.

sunjay

comment created time in 16 days

PR merged sunjay/turtle

Fix #205: update glutin

This fixes #205. The latest glutin version bumps winit's which introduces a number of breaking changes including renaming some enumeration variants:

Breaking: Prefixed virtual key codes Add, Multiply, Divide, Decimal, and Subtract with Numpad.

This meant that matches on previous names obviously failed, but not at compile-time however: because the function imported the enumeration's variants locally, previous names thus matched anything. That caused Add to be understood as a name binding instead of a variant: the compiler only raised warnings, but not proper errors. Note that all the tests ran just fine, even with the warnings being emitted. Of course the CI being configured to reject warnings helped us catch this, but in order to avoid such a confusion in the future, this PR not only fixes the matter at hand by adding the Numpad prefix to all changed names, but also puts the enumeration name in the match arms instead of importing them. That would help raise a more specific error sooner. This strategy has been applied to other match expressions in the module as well. Also, the unsupported keys have all been put in a _ match arm pattern instead of listing the rest of them, which was useless and error-prone as additional variants were also added in the version bump.

Winit's changelog seems to indicate that the introduced breaking changes were meant to help differentiate between the usual minus key and the numpad's one:

Breaking: On X11, - key is mapped to the Minus virtual key code, instead of Subtract.

This could mean that:

  • The current mapping is incorrect: taking into account this PR's changes, VirtualKeyCode::NumpadSubtract is mapped to Key::Minus, which might not be the initial intent.
  • Other similar changes are may occur.
+8 -7

1 comment

2 changed files

PaulDance

pr closed time in 17 days

issue closedsunjay/turtle

Update to latest glutin version

See #204

The latest version of glutin (and winit) make several breaking changes that affect our code. Luckily, we don't depend on the library for any of our public interface. We should be able to update to the latest version without having to make any breaking changes in turtle.

Mentoring Instructions

  1. Change the version of glutin to the latest version (see #204)
  2. Fix all of the compilation errors
  3. Read the changelog of glutin and winit for the versions since our current version and make sure we didn't miss anything
  4. Try running a few examples to make sure turtle still works
  5. Open a PR and make sure to mention any breaking change that isn't visible in the code but that we should still be aware of

closed time in 17 days

sunjay

push eventsunjay/turtle

dependabot-preview[bot]

commit sha a6fde5c50635691f6c1a29dd31f03b4d943aa662

Update glutin requirement from 0.24 to 0.25 Updates the requirements on [glutin](https://github.com/rust-windowing/glutin) to permit the latest version. - [Release notes](https://github.com/rust-windowing/glutin/releases) - [Changelog](https://github.com/rust-windowing/glutin/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-windowing/glutin/compare/v0.24.1...v0.25.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

view details

Paul Mabileau

commit sha 37eab2c2c54c829fc120a3248b7f0dd995093667

Fix #205: update to latest glutin version Some breaking changes were performed to some of winit's event enumerations in its latest version as one of glutin's dependencies, so some match expressions in the `event` module broke down. This fixes them notably by using the enumeration name in match arms in order to generate compilation errors instead of warnings if this happens again. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

Paul Mabileau

commit sha 960049a17e57d9e7d83b0c46fbe24cd977235df5

Go back on most of the changes See #208 for the details. Also, the newly added keycodes have been merged with already existing supported keys. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>

view details

push time in 17 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum Key {  impl Key {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]-    fn from_keycode(key: glutin_event::VirtualKeyCode) -> Option<Self> {-        use glutin_event::VirtualKeyCode::*;+    fn from_keycode(key: VirtualKeyCode) -> Option<Self> {         Some(match key {

@PaulDance These errors will be quite rare (only when keycodes change), so I'd much rather optimize for having less code to read through than the precision of the error message. The main problem being solved here is that the errors were "silent" (as warnings) and we would rather that they be actual errors. I'd really prefer to keep this code as it was before while solving only that problem.

PaulDance

comment created time in 18 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum Key {  impl Key {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]-    fn from_keycode(key: glutin_event::VirtualKeyCode) -> Option<Self> {-        use glutin_event::VirtualKeyCode::*;+    fn from_keycode(key: VirtualKeyCode) -> Option<Self> {         Some(match key {-            Key1 => Key::Num1,-            Key2 => Key::Num2,-            Key3 => Key::Num3,-            Key4 => Key::Num4,-            Key5 => Key::Num5,-            Key6 => Key::Num6,-            Key7 => Key::Num7,-            Key8 => Key::Num8,-            Key9 => Key::Num9,-            Key0 => Key::Num0,--            A => Key::A,-            B => Key::B,-            C => Key::C,-            D => Key::D,-            E => Key::E,-            F => Key::F,-            G => Key::G,-            H => Key::H,-            I => Key::I,-            J => Key::J,-            K => Key::K,-            L => Key::L,-            M => Key::M,-            N => Key::N,-            O => Key::O,-            P => Key::P,-            Q => Key::Q,-            R => Key::R,-            S => Key::S,-            T => Key::T,-            U => Key::U,-            V => Key::V,-            W => Key::W,-            X => Key::X,-            Y => Key::Y,-            Z => Key::Z,--            Escape => Key::Esc,--            F1 => Key::F1,-            F2 => Key::F2,-            F3 => Key::F3,-            F4 => Key::F4,-            F5 => Key::F5,-            F6 => Key::F6,-            F7 => Key::F7,-            F8 => Key::F8,-            F9 => Key::F9,-            F10 => Key::F10,-            F11 => Key::F11,-            F12 => Key::F12,-            F13 => Key::F13,-            F14 => Key::F14,-            F15 => Key::F15,-            F16 => Key::F16,-            F17 => Key::F17,-            F18 => Key::F18,-            F19 => Key::F19,-            F20 => Key::F20,-            F21 => Key::F21,-            F22 => Key::F22,-            F23 => Key::F23,-            F24 => Key::F24,--            Home => Key::Home,-            Delete => Key::Delete,-            End => Key::End,-            PageDown => Key::PageDown,-            PageUp => Key::PageUp,-            Back => Key::Backspace,-            Return => Key::Return,-            Space => Key::Space,--            Left => Key::LeftArrow,-            Up => Key::UpArrow,-            Right => Key::RightArrow,-            Down => Key::DownArrow,--            Numpad0 => Key::Numpad0,-            Numpad1 => Key::Numpad1,-            Numpad2 => Key::Numpad2,-            Numpad3 => Key::Numpad3,-            Numpad4 => Key::Numpad4,-            Numpad5 => Key::Numpad5,-            Numpad6 => Key::Numpad6,-            Numpad7 => Key::Numpad7,-            Numpad8 => Key::Numpad8,-            Numpad9 => Key::Numpad9,--            Add => Key::Plus,-            Apostrophe => Key::Apostrophe,-            At => Key::At,-            Backslash => Key::Backslash,-            Colon => Key::Colon,-            Comma => Key::Comma,-            Decimal => Key::Decimal,-            Divide => Key::Divide,-            Equals => Key::Equals,-            Grave => Key::Backtick,-            LBracket => Key::LeftBracket,-            Minus => Key::Minus,-            Multiply => Key::Multiply,-            NumpadComma => Key::NumpadComma,-            NumpadEnter => Key::NumpadEnter,-            NumpadEquals => Key::NumpadEquals,-            Period => Key::Period,-            RBracket => Key::RightBracket,-            Semicolon => Key::Semicolon,-            Slash => Key::Slash,-            Subtract => Key::Minus,-            Tab => Key::Tab,+            VirtualKeyCode::Key1 => Key::Num1,+            VirtualKeyCode::Key2 => Key::Num2,+            VirtualKeyCode::Key3 => Key::Num3,+            VirtualKeyCode::Key4 => Key::Num4,+            VirtualKeyCode::Key5 => Key::Num5,+            VirtualKeyCode::Key6 => Key::Num6,+            VirtualKeyCode::Key7 => Key::Num7,+            VirtualKeyCode::Key8 => Key::Num8,+            VirtualKeyCode::Key9 => Key::Num9,+            VirtualKeyCode::Key0 => Key::Num0,++            VirtualKeyCode::A => Key::A,+            VirtualKeyCode::B => Key::B,+            VirtualKeyCode::C => Key::C,+            VirtualKeyCode::D => Key::D,+            VirtualKeyCode::E => Key::E,+            VirtualKeyCode::F => Key::F,+            VirtualKeyCode::G => Key::G,+            VirtualKeyCode::H => Key::H,+            VirtualKeyCode::I => Key::I,+            VirtualKeyCode::J => Key::J,+            VirtualKeyCode::K => Key::K,+            VirtualKeyCode::L => Key::L,+            VirtualKeyCode::M => Key::M,+            VirtualKeyCode::N => Key::N,+            VirtualKeyCode::O => Key::O,+            VirtualKeyCode::P => Key::P,+            VirtualKeyCode::Q => Key::Q,+            VirtualKeyCode::R => Key::R,+            VirtualKeyCode::S => Key::S,+            VirtualKeyCode::T => Key::T,+            VirtualKeyCode::U => Key::U,+            VirtualKeyCode::V => Key::V,+            VirtualKeyCode::W => Key::W,+            VirtualKeyCode::X => Key::X,+            VirtualKeyCode::Y => Key::Y,+            VirtualKeyCode::Z => Key::Z,++            VirtualKeyCode::Escape => Key::Esc,++            VirtualKeyCode::F1 => Key::F1,+            VirtualKeyCode::F2 => Key::F2,+            VirtualKeyCode::F3 => Key::F3,+            VirtualKeyCode::F4 => Key::F4,+            VirtualKeyCode::F5 => Key::F5,+            VirtualKeyCode::F6 => Key::F6,+            VirtualKeyCode::F7 => Key::F7,+            VirtualKeyCode::F8 => Key::F8,+            VirtualKeyCode::F9 => Key::F9,+            VirtualKeyCode::F10 => Key::F10,+            VirtualKeyCode::F11 => Key::F11,+            VirtualKeyCode::F12 => Key::F12,+            VirtualKeyCode::F13 => Key::F13,+            VirtualKeyCode::F14 => Key::F14,+            VirtualKeyCode::F15 => Key::F15,+            VirtualKeyCode::F16 => Key::F16,+            VirtualKeyCode::F17 => Key::F17,+            VirtualKeyCode::F18 => Key::F18,+            VirtualKeyCode::F19 => Key::F19,+            VirtualKeyCode::F20 => Key::F20,+            VirtualKeyCode::F21 => Key::F21,+            VirtualKeyCode::F22 => Key::F22,+            VirtualKeyCode::F23 => Key::F23,+            VirtualKeyCode::F24 => Key::F24,++            VirtualKeyCode::Home => Key::Home,+            VirtualKeyCode::Delete => Key::Delete,+            VirtualKeyCode::End => Key::End,+            VirtualKeyCode::PageDown => Key::PageDown,+            VirtualKeyCode::PageUp => Key::PageUp,+            VirtualKeyCode::Back => Key::Backspace,+            VirtualKeyCode::Return => Key::Return,+            VirtualKeyCode::Space => Key::Space,++            VirtualKeyCode::Left => Key::LeftArrow,+            VirtualKeyCode::Up => Key::UpArrow,+            VirtualKeyCode::Right => Key::RightArrow,+            VirtualKeyCode::Down => Key::DownArrow,++            VirtualKeyCode::Numpad0 => Key::Numpad0,+            VirtualKeyCode::Numpad1 => Key::Numpad1,+            VirtualKeyCode::Numpad2 => Key::Numpad2,+            VirtualKeyCode::Numpad3 => Key::Numpad3,+            VirtualKeyCode::Numpad4 => Key::Numpad4,+            VirtualKeyCode::Numpad5 => Key::Numpad5,+            VirtualKeyCode::Numpad6 => Key::Numpad6,+            VirtualKeyCode::Numpad7 => Key::Numpad7,+            VirtualKeyCode::Numpad8 => Key::Numpad8,+            VirtualKeyCode::Numpad9 => Key::Numpad9,++            VirtualKeyCode::Apostrophe => Key::Apostrophe,+            VirtualKeyCode::At => Key::At,+            VirtualKeyCode::Backslash => Key::Backslash,+            VirtualKeyCode::Colon => Key::Colon,+            VirtualKeyCode::Comma => Key::Comma,+            VirtualKeyCode::Equals => Key::Equals,+            VirtualKeyCode::Grave => Key::Backtick,+            VirtualKeyCode::LBracket => Key::LeftBracket,+            VirtualKeyCode::Minus => Key::Minus,+            VirtualKeyCode::NumpadAdd => Key::Plus,+            VirtualKeyCode::NumpadComma => Key::NumpadComma,+            VirtualKeyCode::NumpadDecimal => Key::Decimal,+            VirtualKeyCode::NumpadDivide => Key::Divide,+            VirtualKeyCode::NumpadEnter => Key::NumpadEnter,+            VirtualKeyCode::NumpadEquals => Key::NumpadEquals,+            VirtualKeyCode::NumpadMultiply => Key::Multiply,+            VirtualKeyCode::NumpadSubtract => Key::Minus,+            VirtualKeyCode::Period => Key::Period,+            VirtualKeyCode::RBracket => Key::RightBracket,+            VirtualKeyCode::Semicolon => Key::Semicolon,+            VirtualKeyCode::Slash => Key::Slash,+            VirtualKeyCode::Tab => Key::Tab,              // Unsupported keys (could be changed in the future)-            Snapshot |-            Scroll |-            Pause |-            Insert |-            Compose |-            Caret |-            Numlock |-            AbntC1 |-            AbntC2 |-            Apps |-            Ax |-            Calculator |-            Capital |-            Convert |-            Kana |-            Kanji |-            LAlt |-            LControl |-            LShift |-            LWin |-            Mail |-            MediaSelect |-            MediaStop |-            Mute |-            MyComputer |-            NavigateForward |-            NavigateBackward |-            NextTrack |-            NoConvert |-            OEM102 |-            PlayPause |-            Power |-            PrevTrack |-            RAlt |-            RControl |-            RShift |-            RWin |-            Sleep |-            Stop |-            Sysrq |-            Underline |-            Unlabeled |-            VolumeDown |-            VolumeUp |-            Wake |-            WebBack |-            WebFavorites |-            WebForward |-            WebHome |-            WebRefresh |-            WebSearch |-            WebStop |-            Yen |-            Copy |-            Paste |-            Cut => return None,+            _ => return None,

@PaulDance It's so that we know if new keys are added that we may want to support. It also helps us in cases where an old key has a new mapping (e.g. if they eventually add a third kind of keycode for the minus symbol). Either way, it's better for us to have a compilation error than to silently miss changes in this API.

PaulDance

comment created time in 18 days

PullRequestReviewEvent

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum PressedState {  impl PressedState {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]-    fn from_state(state: glutin_event::ElementState) -> PressedState {+    fn from_state(state: ElementState) -> PressedState {         match state {-            glutin_event::ElementState::Pressed => PressedState::Pressed,-            glutin_event::ElementState::Released => PressedState::Released,+            ElementState::Pressed => PressedState::Pressed,+            ElementState::Released => PressedState::Released,

Could you change this code back to the way it was? It looks like this isn't related to any changes needed when updating the glutin version.

Some background: When we initially wrote this code, we avoided importing too many glutin::event types because that helps clarify which types are coming from glutin and which types belong to our event API. Prefixing glutin's types with glutin_event:: makes it completely unambiguous when you're reading the code. It would be great if the code could go back to using the convention.

PaulDance

comment created time in 18 days

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum MouseButton { impl MouseButton {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]     fn from_button(button: glutin_event::MouseButton) -> Option<Self> {-        use glutin_event::MouseButton::*;         match button {

If you add the #[deny] attribute I mentioned above, we can avoid prefixing these lines too.

PaulDance

comment created time in 18 days

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum Key {  impl Key {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]-    fn from_keycode(key: glutin_event::VirtualKeyCode) -> Option<Self> {-        use glutin_event::VirtualKeyCode::*;+    fn from_keycode(key: VirtualKeyCode) -> Option<Self> {         Some(match key {-            Key1 => Key::Num1,-            Key2 => Key::Num2,-            Key3 => Key::Num3,-            Key4 => Key::Num4,-            Key5 => Key::Num5,-            Key6 => Key::Num6,-            Key7 => Key::Num7,-            Key8 => Key::Num8,-            Key9 => Key::Num9,-            Key0 => Key::Num0,--            A => Key::A,-            B => Key::B,-            C => Key::C,-            D => Key::D,-            E => Key::E,-            F => Key::F,-            G => Key::G,-            H => Key::H,-            I => Key::I,-            J => Key::J,-            K => Key::K,-            L => Key::L,-            M => Key::M,-            N => Key::N,-            O => Key::O,-            P => Key::P,-            Q => Key::Q,-            R => Key::R,-            S => Key::S,-            T => Key::T,-            U => Key::U,-            V => Key::V,-            W => Key::W,-            X => Key::X,-            Y => Key::Y,-            Z => Key::Z,--            Escape => Key::Esc,--            F1 => Key::F1,-            F2 => Key::F2,-            F3 => Key::F3,-            F4 => Key::F4,-            F5 => Key::F5,-            F6 => Key::F6,-            F7 => Key::F7,-            F8 => Key::F8,-            F9 => Key::F9,-            F10 => Key::F10,-            F11 => Key::F11,-            F12 => Key::F12,-            F13 => Key::F13,-            F14 => Key::F14,-            F15 => Key::F15,-            F16 => Key::F16,-            F17 => Key::F17,-            F18 => Key::F18,-            F19 => Key::F19,-            F20 => Key::F20,-            F21 => Key::F21,-            F22 => Key::F22,-            F23 => Key::F23,-            F24 => Key::F24,--            Home => Key::Home,-            Delete => Key::Delete,-            End => Key::End,-            PageDown => Key::PageDown,-            PageUp => Key::PageUp,-            Back => Key::Backspace,-            Return => Key::Return,-            Space => Key::Space,--            Left => Key::LeftArrow,-            Up => Key::UpArrow,-            Right => Key::RightArrow,-            Down => Key::DownArrow,--            Numpad0 => Key::Numpad0,-            Numpad1 => Key::Numpad1,-            Numpad2 => Key::Numpad2,-            Numpad3 => Key::Numpad3,-            Numpad4 => Key::Numpad4,-            Numpad5 => Key::Numpad5,-            Numpad6 => Key::Numpad6,-            Numpad7 => Key::Numpad7,-            Numpad8 => Key::Numpad8,-            Numpad9 => Key::Numpad9,--            Add => Key::Plus,-            Apostrophe => Key::Apostrophe,-            At => Key::At,-            Backslash => Key::Backslash,-            Colon => Key::Colon,-            Comma => Key::Comma,-            Decimal => Key::Decimal,-            Divide => Key::Divide,-            Equals => Key::Equals,-            Grave => Key::Backtick,-            LBracket => Key::LeftBracket,-            Minus => Key::Minus,-            Multiply => Key::Multiply,-            NumpadComma => Key::NumpadComma,-            NumpadEnter => Key::NumpadEnter,-            NumpadEquals => Key::NumpadEquals,-            Period => Key::Period,-            RBracket => Key::RightBracket,-            Semicolon => Key::Semicolon,-            Slash => Key::Slash,-            Subtract => Key::Minus,-            Tab => Key::Tab,+            VirtualKeyCode::Key1 => Key::Num1,+            VirtualKeyCode::Key2 => Key::Num2,+            VirtualKeyCode::Key3 => Key::Num3,+            VirtualKeyCode::Key4 => Key::Num4,+            VirtualKeyCode::Key5 => Key::Num5,+            VirtualKeyCode::Key6 => Key::Num6,+            VirtualKeyCode::Key7 => Key::Num7,+            VirtualKeyCode::Key8 => Key::Num8,+            VirtualKeyCode::Key9 => Key::Num9,+            VirtualKeyCode::Key0 => Key::Num0,++            VirtualKeyCode::A => Key::A,+            VirtualKeyCode::B => Key::B,+            VirtualKeyCode::C => Key::C,+            VirtualKeyCode::D => Key::D,+            VirtualKeyCode::E => Key::E,+            VirtualKeyCode::F => Key::F,+            VirtualKeyCode::G => Key::G,+            VirtualKeyCode::H => Key::H,+            VirtualKeyCode::I => Key::I,+            VirtualKeyCode::J => Key::J,+            VirtualKeyCode::K => Key::K,+            VirtualKeyCode::L => Key::L,+            VirtualKeyCode::M => Key::M,+            VirtualKeyCode::N => Key::N,+            VirtualKeyCode::O => Key::O,+            VirtualKeyCode::P => Key::P,+            VirtualKeyCode::Q => Key::Q,+            VirtualKeyCode::R => Key::R,+            VirtualKeyCode::S => Key::S,+            VirtualKeyCode::T => Key::T,+            VirtualKeyCode::U => Key::U,+            VirtualKeyCode::V => Key::V,+            VirtualKeyCode::W => Key::W,+            VirtualKeyCode::X => Key::X,+            VirtualKeyCode::Y => Key::Y,+            VirtualKeyCode::Z => Key::Z,++            VirtualKeyCode::Escape => Key::Esc,++            VirtualKeyCode::F1 => Key::F1,+            VirtualKeyCode::F2 => Key::F2,+            VirtualKeyCode::F3 => Key::F3,+            VirtualKeyCode::F4 => Key::F4,+            VirtualKeyCode::F5 => Key::F5,+            VirtualKeyCode::F6 => Key::F6,+            VirtualKeyCode::F7 => Key::F7,+            VirtualKeyCode::F8 => Key::F8,+            VirtualKeyCode::F9 => Key::F9,+            VirtualKeyCode::F10 => Key::F10,+            VirtualKeyCode::F11 => Key::F11,+            VirtualKeyCode::F12 => Key::F12,+            VirtualKeyCode::F13 => Key::F13,+            VirtualKeyCode::F14 => Key::F14,+            VirtualKeyCode::F15 => Key::F15,+            VirtualKeyCode::F16 => Key::F16,+            VirtualKeyCode::F17 => Key::F17,+            VirtualKeyCode::F18 => Key::F18,+            VirtualKeyCode::F19 => Key::F19,+            VirtualKeyCode::F20 => Key::F20,+            VirtualKeyCode::F21 => Key::F21,+            VirtualKeyCode::F22 => Key::F22,+            VirtualKeyCode::F23 => Key::F23,+            VirtualKeyCode::F24 => Key::F24,++            VirtualKeyCode::Home => Key::Home,+            VirtualKeyCode::Delete => Key::Delete,+            VirtualKeyCode::End => Key::End,+            VirtualKeyCode::PageDown => Key::PageDown,+            VirtualKeyCode::PageUp => Key::PageUp,+            VirtualKeyCode::Back => Key::Backspace,+            VirtualKeyCode::Return => Key::Return,+            VirtualKeyCode::Space => Key::Space,++            VirtualKeyCode::Left => Key::LeftArrow,+            VirtualKeyCode::Up => Key::UpArrow,+            VirtualKeyCode::Right => Key::RightArrow,+            VirtualKeyCode::Down => Key::DownArrow,++            VirtualKeyCode::Numpad0 => Key::Numpad0,+            VirtualKeyCode::Numpad1 => Key::Numpad1,+            VirtualKeyCode::Numpad2 => Key::Numpad2,+            VirtualKeyCode::Numpad3 => Key::Numpad3,+            VirtualKeyCode::Numpad4 => Key::Numpad4,+            VirtualKeyCode::Numpad5 => Key::Numpad5,+            VirtualKeyCode::Numpad6 => Key::Numpad6,+            VirtualKeyCode::Numpad7 => Key::Numpad7,+            VirtualKeyCode::Numpad8 => Key::Numpad8,+            VirtualKeyCode::Numpad9 => Key::Numpad9,++            VirtualKeyCode::Apostrophe => Key::Apostrophe,+            VirtualKeyCode::At => Key::At,+            VirtualKeyCode::Backslash => Key::Backslash,+            VirtualKeyCode::Colon => Key::Colon,+            VirtualKeyCode::Comma => Key::Comma,+            VirtualKeyCode::Equals => Key::Equals,+            VirtualKeyCode::Grave => Key::Backtick,+            VirtualKeyCode::LBracket => Key::LeftBracket,+            VirtualKeyCode::Minus => Key::Minus,+            VirtualKeyCode::NumpadAdd => Key::Plus,+            VirtualKeyCode::NumpadComma => Key::NumpadComma,+            VirtualKeyCode::NumpadDecimal => Key::Decimal,+            VirtualKeyCode::NumpadDivide => Key::Divide,+            VirtualKeyCode::NumpadEnter => Key::NumpadEnter,+            VirtualKeyCode::NumpadEquals => Key::NumpadEquals,+            VirtualKeyCode::NumpadMultiply => Key::Multiply,+            VirtualKeyCode::NumpadSubtract => Key::Minus,+            VirtualKeyCode::Period => Key::Period,+            VirtualKeyCode::RBracket => Key::RightBracket,+            VirtualKeyCode::Semicolon => Key::Semicolon,+            VirtualKeyCode::Slash => Key::Slash,+            VirtualKeyCode::Tab => Key::Tab,              // Unsupported keys (could be changed in the future)-            Snapshot |-            Scroll |-            Pause |-            Insert |-            Compose |-            Caret |-            Numlock |-            AbntC1 |-            AbntC2 |-            Apps |-            Ax |-            Calculator |-            Capital |-            Convert |-            Kana |-            Kanji |-            LAlt |-            LControl |-            LShift |-            LWin |-            Mail |-            MediaSelect |-            MediaStop |-            Mute |-            MyComputer |-            NavigateForward |-            NavigateBackward |-            NextTrack |-            NoConvert |-            OEM102 |-            PlayPause |-            Power |-            PrevTrack |-            RAlt |-            RControl |-            RShift |-            RWin |-            Sleep |-            Stop |-            Sysrq |-            Underline |-            Unlabeled |-            VolumeDown |-            VolumeUp |-            Wake |-            WebBack |-            WebFavorites |-            WebForward |-            WebHome |-            WebRefresh |-            WebSearch |-            WebStop |-            Yen |-            Copy |-            Paste |-            Cut => return None,+            _ => return None,

Could you change this back to the way it was? The reason we didn't use a wildcard here initially was so that new variants added to VirtualKeyCode would cause a compilation error (because the match would not be exhaustive). This is important to make sure we know whenever that happens and can update the code accordingly.

PaulDance

comment created time in 18 days

Pull request review commentsunjay/turtle

Fix #205: update glutin

 pub enum Key {  impl Key {     #[cfg_attr(any(feature = "test", test), allow(dead_code))]-    fn from_keycode(key: glutin_event::VirtualKeyCode) -> Option<Self> {-        use glutin_event::VirtualKeyCode::*;+    fn from_keycode(key: VirtualKeyCode) -> Option<Self> {         Some(match key {
        #[deny(unreachable_patterns, unused_variables)]
        Some(match key {

Could you change this line to include this attribute instead of prefixing every variant with the enum name? This fixes the lack of compilation errors without forcing us to repeat that name on every line.

PaulDance

comment created time in 18 days

PullRequestReviewEvent
PullRequestReviewEvent

delete branch sunjay/turtle

delete branch : dependabot/cargo/cfg-if-1.0

delete time in 18 days

push eventsunjay/turtle

dependabot-preview[bot]

commit sha cf1575deda8414ca96f3d90488e3204a926c67ee

Update cfg-if requirement from 0.1 to 1.0 Updates the requirements on [cfg-if](https://github.com/alexcrichton/cfg-if) to permit the latest version. - [Release notes](https://github.com/alexcrichton/cfg-if/releases) - [Commits](https://github.com/alexcrichton/cfg-if/compare/0.1.1...1.0.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

view details

push time in 18 days

PR merged sunjay/turtle

Update cfg-if requirement from 0.1 to 1.0 dependencies

Updates the requirements on cfg-if to permit the latest version. <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/alexcrichton/cfg-if/commit/e60fa1efeab0ec6e90c50d93ec526e1410459c23"><code>e60fa1e</code></a> Bump to 1.0.0</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/7daa598424eb304a2685dff0374c14d3494e3d24"><code>7daa598</code></a> Prohibit multiple predicates (<a href="https://github-redirect.dependabot.com/alexcrichton/cfg-if/issues/37">#37</a>)</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/f71bf60f212312faddee7da525fcf47daac66499"><code>f71bf60</code></a> Another attempt at gh-pages</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/f779d28bba34868ad4b79582a4c27f3b56e6eca6"><code>f779d28</code></a> Change push username for gh-pages</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/4484a6faf816ff8058088ad857b0c6bb2f4b02b2"><code>4484a6f</code></a> Bump to 0.1.10</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/a625fbe0ac2a29200de6c670aabb44d6c8af298d"><code>a625fbe</code></a> Add a test for the body of an <code>impl</code></li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/33a8869d16d3e8ef9b5c5a0347c9b2602dd31c1d"><code>33a8869</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/alexcrichton/cfg-if/issues/28">#28</a> from Lokathor/token-trees</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/571a28d359e6e2e3e8fd02651601c4f4d7de3a2a"><code>571a28d</code></a> remove the __apply internal macro</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/75e817fa2cdd9d3cb2c558fa91ba3dacdbfa8d73"><code>75e817f</code></a> adjust the test</li> <li><a href="https://github.com/alexcrichton/cfg-if/commit/3e9d4876b81b342704bfaca6c2abdc0f2b1265aa"><code>3e9d487</code></a> notes fix</li> <li>Additional commits viewable in <a href="https://github.com/alexcrichton/cfg-if/compare/0.1.1...1.0.0">compare view</a></li> </ul> </details> <br />

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
  • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot dashboard:

  • Update frequency (including time of day and day of week)
  • Pull request limits (per update run and/or open at any time)
  • Automerge options (never/patch/minor, and dev/runtime dependencies)
  • Out-of-range updates (receive only lockfile updates, if desired)
  • Security updates (receive only security updates, if desired)

</details>

+1 -1

1 comment

1 changed file

dependabot-preview[bot]

pr closed time in 18 days

PullRequestReviewEvent

issue commentsunjay/turtle

How should the speed levels in the turtle crate work?

Thanks for providing your thoughts @PaulDance. I definitely see the logic behind your proposals and I share your concerns about overcomplicating this API.

Overall, I am okay with making breaking changes here. We don't need to have integer speed levels. LOGO has no concept of speed (lines are drawn instantaneously). This was a concept added by the Python implementation. It's better to make these kinds of changes now. I'm glad we're discussing it.

Here's a proposal that merges both of our ideas, but makes it far less flexible in an attempt to keep it simple:

  • We change set_speed to take one of three types:
    • f64 - a positive (> 0) value with an unspecified unit (must be normal)
    • "slow", "normal", "fast", "faster", etc. - map to reasonable arbitrary values that we choose (and are unspecified in the documentation)
    • "instant" or Speed::instant() - for the "instant" speed
  • Passing an integer will now produce a compilation error (helpful for people updating from the previous speed levels)
  • The Speed type will still be opaque and it will be impossible to get a value out of it (other than checking is_instant)
    • I am open to changing my mind about this, but it is probably better to be overly conservative in the beginning and add more flexibility later if we need it

Leaving things unspecified gives us some opportunity to change the inner implementation details as long as we don't change any of the behaviour of the resulting program. Having only one value but not specifying its unit allows us to choose a reasonable mapping to both translation speed and rotation speed.

I don't think most users will want to care about specifying precise/different values for translation and rotation speed. If they do, this API leaves the option open for us to provide another type later that allows them to do that. e.g. a SpeedLevels {translation: f64, rotation: f64} type could implement Into<Speed>.

As for the question of how we decide the mapping between speed value and translation/rotation speed: the goal should be for the translation and rotation speed to "feel" roughly the same. That is, if I set the speed to 100.0, the turtle should not move significantly faster than it rotates. To that end, I propose:

  • The speed value provided to set_speed should be scaled so the user doesn't have to provide an extremely large value just to get the turtle moving at a reasonable speed
  • Translation Speed: The scaled value maps to 1 px/sec where px is a logical pixel (as opposed to a physical pixel)
  • Rotation Speed: The scaled value maps to x rad/sec where x is the number of radians it takes to rotate the tip of the turtle's shell by 1 px (circumference)

This creates a notion of "moving by 1 px" and "rotating by 1 px" which I am hoping will turn out to be quite intuitive and fulfill the goal stated above. We can always figure out something else if this doesn't work.


Unfortunately, the speed API is so important that we don't have the luxury of marking set_speed as unstable and experimenting with it. Whatever we choose up until the v1.0 release will get stabilized and end up being the API for the considerable future. Thanks for taking the time to think about this with me!

sunjay

comment created time in 20 days

issue commentsunjay/turtle

Add arc method to Turtle

@PaulDance The instructions are updated now. 🎉

sunjay

comment created time in 20 days

issue openedsunjay/turtle

Update to latest glutin version

See #204

The latest version of glutin (and winit) make several breaking changes that affect our code. Luckily, we don't depend on the library for any of our public interface. We should be able to update to the latest version without having to make any breaking changes in turtle.

Mentoring Instructions

  1. Change the version of glutin to the latest version (see #204)
  2. Fix all of the compilation errors
  3. Read the changelog of glutin and winit for the versions since our current version and make sure we didn't miss anything
  4. Try running a few examples to make sure turtle still works
  5. Open a PR and make sure to mention any breaking change that isn't visible in the code but that we should still be aware of

created time in 20 days

push eventsunjay/pea

Sunjay Varma

commit sha 18b7d9cf65f4626fb41a01469d8b9286d7599d66

Defining a package of external functions/types and setting up to populate prelude

view details

push time in 24 days

push eventsunjay/pea

Sunjay Varma

commit sha 30279ac2c3fbc98debb1b4e29ee7607aefc4811e

Compiler no longer initializes interpreter and consts can now be initialized outside the compiler

view details

push time in 24 days

push eventsunjay/pea

Sunjay Varma

commit sha 11334836b67cd75a25be78757d4c4d137d2505ad

Split module and program such that module is the decls + scope and program is the root module + metadata collected throughout compilation

view details

push time in 24 days

push eventsunjay/website

Sunjay Varma

commit sha b9d4f1bbb64e9227f57fbe5d47e4e0f9d34f663e

Fixed typo, improved grammar

view details

push time in 24 days

fork sunjay/website

The Ristretto Group Website

https://ristretto.group

fork in 24 days

push eventsunjay/pea

Sunjay Varma

commit sha ca1ac64f5f0bb70d0257605f8dbe736182df9e13

Added a native function value

view details

push time in 24 days

issue closedsunjay/pea

Byte literals

We have byte strings, but we should also have byte literals b'a' that produce a value of type u8.

closed time in 24 days

sunjay

pull request commentrust-lang/docs.rs

Extend coverage feature

I strongly agree with what Manish said. I am also very against putting this in the search results for every crate.

A proposal I could get on board with:

  • Make this into a badge that people can add to their README and/or Cargo.toml
  • Display badges in the search results

That way people can have the metric and choose where they want it to be displayed. It's a win-win.

Overall, I don't think this is a bad feature. It makes sense to provide metrics like this just like it makes sense to provide people with the ability to generate code coverage reports. I just think that people shouldn't be forced into having to care about a number that they might not care about and that doesn't even accurately represent the quality of their crate. Putting this number in the search results would definitely be overstating its importance.

I think Manish put it perfectly when he said:

I do not think we should engineer a race-for-metrics via some coverage number.

I completely agree with this.

GuillaumeGomez

comment created time in 24 days

push eventsunjay/pea

Sunjay Varma

commit sha a1b4faf7b2c84b01b05f9df9966128f4aebd909e

Adding `Send` and `Sync` impls for Gc<T>

view details

push time in 25 days

more