Stream: show and tell

Topic: Units and Geometry


view this post on Zulip Wolfgang Schuster (Sep 16 2022 at 19:57):

I've been a huge fan of @Ian Mackenzie 's packages in Elm. I use a bunch of them for a space simulation thing I've been building and they've helped me to not mix numbers with different units (which there are lot of in space). Even more so with making sure things are scaled properly! So I started playing porting them to Roc. Not sure how far I'll get (there's a lot of work) but it's a fun way to learn Roc Screen-Shot-2022-09-16-at-2.56.56-PM.png

view this post on Zulip Wolfgang Schuster (Sep 16 2022 at 19:58):

Currently taking the Breakout example app and wrapping values

view this post on Zulip Wolfgang Schuster (Sep 16 2022 at 21:40):

I love that I can have Bounds and Rect implicitly convert from/to Rust f32 and a wrapped Roc Quantity F32 Pixels. Makes it so the platform gives and takes pixels.

view this post on Zulip jan kili (Sep 16 2022 at 22:49):

This is satisfying :)

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:05):

Trying to migrate the existing Rect to a shapes like those in elm-geometry and struggling with getting a Point3d to work. Some of it is definitely me trying to write Elm in Roc :sweat_smile:

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:09):

Trying to figure out how to be able to set a Point3d a units coordinates := { x : a, y : a, z : a } in my Model. Wondering if I need to be more constrained with my a :thinking:

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:10):

I mean. You might want Num a, but that shouldn't be an error

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:11):

What error are you getting with that struct?

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:12):

I keep getting thread '<unnamed>' panicked at 'called Result::unwrap() on an Err value: Erroneous', crates/compiler/mono/src/ir.rs:3228:18 when I have

Model : {
    ballPosition : Point3d Pixels ScreenSpace,
}
Model : {
    ballPosition : Point3d Pixels ScreenSpace,
}

init ...
{ ballPosition: Point3d.pixels
(width |> Quantity.scaleBy 0.5 |> Pixels.inPixels)
(height |> Quantity.scaleBy 0.4 |> Pixels.inPixels)
(0),
}


view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:12):

width |> Quantity.scaleBy 0.5 |> Pixels.inPixels and give an a, which I think should be an F32 in this case

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:15):

Same error with ballPosition: Point3d.pixels 5.0f32 10.0f32 0.0f32, (trying to eliminate other causes)

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:16):

Maybe I need to be defining Point3d in the Rust part of the platform?

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:21):

Shouldn't point3d take 3 values, not 2? At least based on the definition

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:22):

Also, not sure it will give you a better error, but make sure to try roc check if you hit compiler errors. It tends to give better errors and not crash.

view this post on Zulip Wolfgang Schuster (Sep 17 2022 at 16:25):

Thanks @Brendan Hansknecht ! Running check found the issue. I'd only written imports [ pf.Point3d ] and not pf.Point3d.{Point3d} :face_palm:

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:28):

Ah

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:28):

Cool

view this post on Zulip Brendan Hansknecht (Sep 17 2022 at 16:28):

Glad to help

view this post on Zulip Wolfgang Schuster (Sep 19 2022 at 19:53):

I've found it easier to catch these simple mistakes by using http://eradman.com/entrproject/, running it like find ./examples/roc-geometry/**/*.roc | entr -s 'cargo run check examples/roc-geometry/breakout-2.roc'

view this post on Zulip Wolfgang Schuster (Sep 19 2022 at 21:05):

I don't know what I did, but my branch https://github.com/wolfadex/roc/tree/wolfadex/roc-geometry just hangs when running cargo run check examples/roc-geometry/breakout-2.roc and cargo run run examples/roc-geometry/breakout-2.roc. Even inserting a bad value like carl = 5 * "steve" at the top doesn't get it to fail

view this post on Zulip Wolfgang Schuster (Sep 19 2022 at 21:35):

I think it was a circular import. Vector3d imported Direection3d, which imported Vector3d (bad copy paste)

view this post on Zulip Brendan Hansknecht (Sep 19 2022 at 22:23):

Can you file an issue with a minimal repro. Would be good to print a proper error on something like this.

view this post on Zulip Wolfgang Schuster (Sep 19 2022 at 22:24):

Already did, should have linked it here, https://github.com/roc-lang/roc/issues/4075


Last updated: Jul 06 2025 at 12:14 UTC