elmcraft / core-extra

Utility functions for an improved experience with elm/core
https://package.elm-lang.org/packages/elmcraft/core-extra/latest/
Other
22 stars 10 forks source link

Triple.Extra #52

Closed gampleman closed 3 months ago

gampleman commented 3 months ago

This adds a library for dealing with Triples (fixes #21).

I think the most controversial idea here are the swizzles. I'm happy to delete them for now if the other maintainers have qualms.

miniBill commented 3 months ago

triple, first, second, third are obviously good

The swizzles I'd avoid having in core-extra

The other functions feel... weird? Like, is doing the product of three numbers in a triple a common operation at all? Or sorting them?

gampleman commented 3 months ago

Hm I tend to agree with some of these sentiments. The functions I added are just stuff we have in Tuple.Extra. But perhaps it's better to be more conservative to begin with.

I'll probably like to keep the sorting functions (or at least sortWith) since they're somewhat challenging to implement correctly.

lydell commented 3 months ago

I’m curious about the swizzles. Is that something you came up with yourself, or something you’ve seen somewhere else? Also just for curiosity, what could they be used for?

gampleman commented 3 months ago

I’m curious about the swizzles. Is that something you came up with yourself, or something you’ve seen somewhere else? Also just for curiosity, what could they be used for?

They're a common feature of GPU oriented languages like GLSL. I always found them super fun, but perhaps the reason they'd be useful in those contexts is that those languages generally compute around fix length vectors, whereas actually triples are fairly rare in Elm (and we don't actually particularly want to promote them).

So you can do things like:


vec4 opaque = vec4(color.rgb, 1.0);

vec3 mirrored = position.yxz;

vec3 onlyRed = color.rrr;

and so on