JuliaGraphics / Luxor.jl

Simple drawings using vector graphics; Cairo "for tourists!"
http://juliagraphics.github.io/Luxor.jl/
Other
588 stars 71 forks source link

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

Closed KCanner closed 10 months ago

KCanner commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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