Ancestors

Toot

Written by cybervegan on 2025-01-06 at 01:54

@inkscape I'm writing an Inkscape extension using Python Inkex, and I need to know if the contour of two vectors overlap. I'm very much a beginner with Inkex, so I've been using the bounding boxes so far, and it works after a fashion, but of course this produces weird results when a smaller shape is within the bounding-box of a larger shape, but they don't actually overlap. So I need to work out if they really DO overlap, so I can then deal with them appropriately. Can anyone tell me if it's possible to either ascertain if two vectors overlap via the API, or short of that, how to get a raster of pixels of a vector rendered (at any resolution) so I can convert that to a set, and can then check for intersection?

Sorry, I don't even know if this question makes sense, so for context, I'm trying to change the z-order of shapes that are enclosed by larger shapes so that they are lower than the enclosing shape(s), because I use Inkscape to design SVGs for #LaserCutting, and you need to cut internal vectors before their enclosing vectors. Lasers on laser cutters have a focal length, and you have to set the focus before you cut; when the laser has completed a closed cut, the material is apt to drop down by a few millimetres, and the laser is then no longer focused properly on it, so any internal vectors cut after this has happened will be out of focus and may not cut through properly.

=> More informations about this toot | More toots from cybervegan@autistics.life

Descendants

Written by cybervegan on 2025-01-11 at 19:55

@inkscape Update 3. Inkscape shell mode is a bit weird, but I've figured out enough to test for overlap: the "path-intersection" action will leave the inner object if it is enclosed by a larger one, or a new object if they only partially overlap. The weird bit is all of the state management you have to do to be able to repeat this test for n objects. Well, I've cracked that: it's essentially:

select-by-id:obj1,obj2

duplicate

path-intersection

select-list

select-clear

You have to duplicate the objects because the path-intersection operation is destructive, and if you want to test obj1 or obj2 against another object, you need to save it. select-list will show you the object(s) remaining after the path-intersection operation - one (or more) object means they intersected; nothing listed means not intersection. I use select-clear to get a clean slate for the next comparison.

Around this, I've built another Python POC that uses Inkscape shell mode via a subprocess, and parses the output to ascertain overlap status. It uses a totally naive approach at the moment where it simply checks every object against every other object (twice, because it will test obja,objb and objb,obja because I CBA to make it smarter), and although it works, it chokes (i.e. never completes) on SVGs of 300+ objects. This shouldn't be a problem when I add this into the Inkscape plugin, as that already knows which objects might be overlapping (because it has compared their bounding boxes) so I can dramatically reduce the number of tests, and of course avoid doing all checks twice.

Shell mode works, but API calls would be better, and more efficient, as I wouldn't have to create a script and parse the response. But if this is all we've got, it'll do.

=> More informations about this toot | More toots from cybervegan@autistics.life

Written by cybervegan on 2025-01-14 at 00:09

@inkscape Update 4. It's now working properly: it always places enclosed shapes - defined by the enclosed shape's contour being within the continuous contour of the enclosing shape - lower in z-order than their enclosing shape; it also orders multiple contained shapes by proximity, recursively, in an attempt to minimise laser head zig-zagging. I now need to tidy it up and refactor it, and remove all of the debugging output!

It calls inkscape in shell mode to determine the contour overlaps (builds a script, pipes it into Inkscape, then parses the output). Inkscape is only called in this way ONCE per invocation of the plugin.

Thanks for all the valuable pointers - it all helped.

=> More informations about this toot | More toots from cybervegan@autistics.life

Written by Inkscape on 2025-01-13 at 16:30

@cybervegan This sounds a lot like you are trying to replicate

https://inkscape.org/~Moini/%E2%98%85multiple-boolean-operations-with-inx-pathops ?

=> More informations about this toot | More toots from inkscape@mastodon.art

Written by cybervegan on 2025-01-13 at 18:16

@inkscape To an extent, yes. I've looked at the Pathops code, and the way it re-entrantly calls Inkscape shell to delegate operations to it inspired my current approach. I'm producing a script to test for all of the overlaps I need to resolve, and I'm then parsing the responses to answer the questions I need answered. I'm nearly there now with a more solid POC, but I'm sure it can be improved.

=> More informations about this toot | More toots from cybervegan@autistics.life

Written by Inkscape on 2025-01-15 at 22:49

@cybervegan Congrats! 🎉

=> More informations about this toot | More toots from inkscape@mastodon.art

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113778913597277018
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
376.08508 milliseconds
Gemini-to-HTML Time
2.073082 milliseconds

This content has been proxied by September (ba2dc).