Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers for converting [x, y] tuples to [x, y, r] tuples and back #27

Open
echo-bravo-yahoo opened this issue May 28, 2021 · 2 comments

Comments

@echo-bravo-yahoo
Copy link

One of the consistent API pain points I have is moving between an [x, y] and [x, y, r] coordinate lists. I frequently find I want to start with a polygon in [x, y] space while developing iteratively, and only later move it to an [x, y, r] polygon. Additionally, I've wanted to use translateRadiiPoints for regular [x, y] polygons before. Here are two (dumb, simple) helper functions that I frequently use; I think Round-Anything could benefit from similar (better-named) functions.

function rless(list) = [for (i=[0:len(list)-1]) [list[i][0], list[i][1]]] ;
function rish(list, r) = [for (i=[0:len(list)-1]) [list[i][0], list[i][1], r]] ;

Example where rless is helpful:

portWidth = 5;
portHeight = 12.50;
points = [
    [0,         0,           2],
    [0,         portHeight,  2],
    [portWidth, portHeight,  2],
    [portWidth, 0,           2],
];

polygon(rless(points));

And for rish:

portWidth = 5;
portHeight = 12.50;
points = [
    [0,         0],
    [0,         portHeight],
    [portWidth, portHeight],
    [portWidth, 0],
];

polygon(rless(translateRadiiPoints(rish(points, 0)));
@echo-bravo-yahoo
Copy link
Author

I understand if you think this doesn't meet the bar for inclusion, but I find openSCAD's functions to be incredibly painful to write. My usual approach when writing in unfamiliar languages is to be verbose and split things into more operations with well-named variables as intermediate steps, and openSCAD's function syntax seems actively hostile to that.

@Irev-Dev
Copy link
Owner

It's a good point @Trial-In-Error. I already have a rless equivalent
function getpoints(p)=[for(i=[0:len(p)-1])[p[i].x,p[i].y]];// gets [x,y]list of[x,y,r]list
but not rish.
Plus getpoints is not documented.
I'll leave this open and try and do something about it soon, but prod me if it's been a couple weeks and I haven't got around to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants