BOSL2 icon indicating copy to clipboard operation
BOSL2 copied to clipboard

proposal: vector_name() function

Open lijon opened this issue 4 months ago • 0 comments

Is your feature request related to a problem? Please describe. For debugging purposes it's useful to get a string representation of a directional vector such as an anchor, orientation, face, edge, corner etc.

Describe the solution you'd like I suggest adding this to the library. The name could be changed of course:

function vector_name(v) =
    assert(is_vector(v))
    let(
        a = ["LEFT","FRONT","BOTTOM"],
        b = ["RIGHT","BACK","TOP"],
        l = [for(i = idx(v)) if(v[i]!=0) v[i] < 0 ? a[i] : b[i]]
    )
    len(l) ? str_join(l, "+") : "CENTER";

Example Code

echo(vector_name(TOP+RIGHT)); // prints "RIGHT+TOP"

lijon avatar Feb 07 '24 14:02 lijon