LoicGoulefert / occult

vpype plug-in to remove occulted lines in SVG files
MIT License
67 stars 6 forks source link

Line Removal Failing When Using -k flag #26

Closed lewi0622 closed 6 months ago

lewi0622 commented 6 months ago

I'm using Vpype version 1.14.0 and Occult version 0.4.0

Using the Demo.svg file attached, I'm looking to use occult with the -k flag to keep the lines within the mountain shape.

When simply performing Occult across layers, it removes the lines inside the mountain shape; using this command:

vpype read -a id --no-crop 'Demo.svg' occult -i write 'Demo_occult.svg'

But when the -k flag is added, it fails to remove any lines at all, using this command:

vpype read -a id --no-crop 'Demo.svg' occult -i -k write 'Demo_occult.svg'

Demo

LoicGoulefert commented 6 months ago

Hey, thanks for the issue.

vpype read -a id --no-crop 'Demo.svg' occult -i -k show puts the removed lines in a new layer, in this case layer 280. When you separate layers by id attribute (vpype read -a id), for some reason the resulting file keeps the same stroke color for the lines in layer 280.

Separating layers by stroke attribute (vpype read -a stroke --no-crop Demo.svg occult -i -k show) will show the removed lines (in this case, layer 3) in a different color.

lewi0622 commented 6 months ago

Is there a max number of layers the -k will work with and output to a new layer/color?

Using the below file works fine by reading in by -a id. I'm struggling to find a small file where it fails like one above.

Demo1

lewi0622 commented 6 months ago

This one worked correctly as well and I can't seem to figure out why one works and the other doesn't. image

lewi0622 commented 6 months ago

Alright, I figured it out. Depending on the number of the layer the -k get's put on, it changes the color. Below the number of layers in each drawing goes 100, 101, 102 image

So it sounds like I need to manually specify the layer color of the -k lines

lewi0622 commented 6 months ago

Here's my workaround. I perform a check to see if the number of layers has increased, which in this case means that the -k did indeed store lines in a new layer. Then I set that layer color to 'pink'. In my script implementation, instead of pink, I'll randomly generate a color and double check it's not already in use in the file.

vpype read -a id --no-crop 'Demo1.svg' \
eval "%last_color='pink'%" \
forlayer eval "%num_layers=_n%" end \
occult -i -k \
forlayer \
eval "%new_num_layers=_n%" \
eval "%if(new_num_layers<=num_layers):last_color=_color%" \
end \
color -l %new_num_layers% %last_color% \
show