CatherineH / python-embroidery

python code for generating embroidery designs
MIT License
22 stars 4 forks source link

Discontinious paths #2

Closed styloInt closed 5 years ago

styloInt commented 5 years ago

Hi Catherine,

First, I want to say that you did an amazing job with this framework.

Now, I'm trying to implement a way which works even for discontinuous paths. Did you already think about how to do this?

What I am thinking :

What do you think ? is it doable?

CatherineH commented 5 years ago

Hey @styloInt ,

I need to update the example in the readme - if the paths don't intersect, the digitizer is fine - I just digitize every discontinous path individually. However it's still a problem if one path is contained within another - like a donut. In which case, you're right, that's how you would need to test whether one path is within another. svgpathtools has already implemented this: https://github.com/mathandy/svgpathtools/blob/master/examples/determine-if-svg-path-is-contained-in-other-path-example.py#L12 , and their method is kind of similar to what you've described.

Once the paths have been determined to intersecting, I would prefer to carve up the shape into smaller shapes without interior regions, e.g. turning the donut into to two crescents, as the fill algorithm that looks best is the scanlines fill, and that only works with rectangular-ish shapes.

In practice, I haven't worked on this because I haven't had many projects that had intersecting paths. But I imagine it will become a big deal once people start using any old SVG, since most SVGs implement negative regions by just stacking shapes on top of other shapes.

But I'm always open to contributions!

styloInt commented 5 years ago

Thanks for you answer.

One thing I don't understand in the function path1_is_contained_in_path2 :

assert path2.isclosed()  # This question isn't well-defined otherwise

Why when the path is closed, the question isn't defined ? For example, in a donut, we have one closed shape inside another closed shape.

The "intersect" function does not work in this case, but I don't understand why ... (I'm new to the area of vector images so there are certainly things that I don't get)

CatherineH commented 5 years ago

We're checking to make sure that path2 is closed. In the donut, path2 would be closed. If the path were open, how would we define what counts as "inside"?

styloInt commented 5 years ago

Thanks for your answer.

Actually I'm having trouble implementing the "donut case".

My image example is this one : img

As you can see this image contains a lot of donuts example. What I'm having trouble doing is following the curves. I'm thinking by sampling some points along the curves and then following them. What do you think about this idea ?

CatherineH commented 5 years ago

If I were you, I'd open the image in inkscape, and trace individual segments into polygons without donuts with the pencil tool. It's something you're probably going to need to do anyway as the png-to-embroidery pattern functionality of this library is extremely experimental.

styloInt commented 5 years ago

Thanks for the advice, but I'm trying to have an end to end solution without the need of manual manipulation. ^^

In the way that this website does when you decide to personalize the t-shirt: https://www.promotique.com/product/port-authority-tall-stain-resistant-polo/P00W27413

I completely understand that the functionality is extremely experimental but it's a good base to start :)