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

Ellipse mode radius changes behavior of radius labelled argument #352

Open
R4chel opened this issue Feb 2, 2023 · 5 comments
Open

Ellipse mode radius changes behavior of radius labelled argument #352

R4chel opened this issue Feb 2, 2023 · 5 comments

Comments

@R4chel
Copy link
Contributor

R4chel commented Feb 2, 2023

I would expect that these two lines of code would produce the same output
vsk.circle(0,0,radius=5) vsk.circle(0,0,radius=5, mode="radius")
but was suprised to find that
vsk.circle(0,0,radius=5, mode="radius")
draws a circle with radius 10!

I created a repo to write a test and explore this outside the context of the complex code where I had come across it: https://github.com/R4chel/vsketch-circle-mode-debugging
And here is an output image from that showing the problem. The lines are drawn from the center of the circle to a point distance radius away.
image

@R4chel
Copy link
Contributor Author

R4chel commented Feb 10, 2023

Another issue with vsk.circle if the radius / diameter is a negative number it draws a triangle!
vsk.circle(0,0,-1)
Screenshot 2023-02-09 at 9 54 02 PM

@R4chel
Copy link
Contributor Author

R4chel commented Feb 13, 2023

vsk.rect() with negative values also does strange things

@R4chel
Copy link
Contributor Author

R4chel commented Feb 13, 2023

I found the line responsible for drawing triangles when the radius is negative.

https://github.com/abey79/vpype/blob/15ae8110eac724226d1050ea88f4f9301a39cbec/vpype/primitives.py#L131
n = max(3, math.ceil((stop - start) / 180 * math.pi * max(rw, rh) / quantization))

if radius (rw and rh) are negative the whole right side will be negative and n will be 3.

@R4chel
Copy link
Contributor Author

R4chel commented Feb 14, 2023

I think it's not immediately obvious what vsk.cricle(0,0,-1) should draw. Here is a start of potential answers

  • Reject, invalid input
  • In polar coordinates, $(-r, \theta)=(r,\theta+\pi)$
  • Im not sure about the implementation details, in p5.js negative values for width and height of rect are drawn inverted (going up instead in down) and circles appear to be drawn with the absolute value but I haven't explored this too deeply. Here is an p5.js discussing this error when ellipse has negative width and height processing/p5.js#413

@abey79
Copy link
Owner

abey79 commented Feb 15, 2023

I think the clean way would be to draw with the absolute value and invert the circle rotation direction. This latter point would be completely pointless in the current situation IMO, so I'd drop it. I'm actually thinking of the future of vpype/vsketch data model, with first class support for arcs, bezier, etc. When/if that happens, it'll be easy (and more meaningful) to do the "right thing".

This was referenced Mar 2, 2023
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