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

clip() using lines or boxes does not return an output #289

Closed
KCanner opened this issue Dec 2, 2023 · 2 comments
Closed

clip() using lines or boxes does not return an output #289

KCanner opened this issue Dec 2, 2023 · 2 comments

Comments

@KCanner
Copy link

KCanner commented Dec 2, 2023

I want to clip using lines and arcs, but when I clip using lines nothing is returned.
This also seems to also be an issue when using box() but functions correctly using circle()

@draw begin
line(Point(100,0),Point(0,100))
line(Point(0,100),Point(-100,0))
line(Point(-100,0),Point(0,-100))
line(Point(0,-100),Point(100,0))
clip()
circle(O, 90, :fill)
end

@cormullion
Copy link
Member

cormullion commented Dec 2, 2023

Hi!

A good way to see what's going on is to use fillpath() or storepath() rather than clip() to see the path before using it for clipping.

What you've made with your code is a path with four separate subpaths each with a single line, rather than a path with one subpath with four lines.

Path([
 PathMove(Point(100.0, 0.0)),
 PathLine(Point(0.0, 100.0)),
 PathMove(Point(0.0, 100.0)),
 PathLine(Point(-100.0, 0.0)),
 PathMove(Point(-100.0, 0.0)),
 PathLine(Point(0.0, -100.0)),
 PathMove(Point(0.0, -100.0)),
 PathLine(Point(100.0, 0.0))
])

and single line segments, whether on their own or stored in a sequence, can't do clipping.

What you probably want is:

    move(Point(100, 0))
    line(Point(0, 100)) 
    line(Point(-100, 0))
    line(Point(0, -100))
    closepath()

    clip()

which creates a single path with one subpath with four line segments.

Or perhaps:

    pts = [
        Point(100, 0),
        Point(0, 100),
        Point(-100, 0),
        Point(0, -100)
    ]
   poly(pts, :clip)
...

@KCanner
Copy link
Author

KCanner commented Dec 4, 2023

Thank you for taking the time to explain this, it makes perfect sense now.

@KCanner KCanner closed this as completed Dec 4, 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