CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
443 stars 28 forks source link

Stroke Alignment Request #76

Closed tatyanade closed 3 years ago

tatyanade commented 4 years ago

Can there be a call for strokes to only be external? useful for outlining i.e. #73 ; if you have a lot of different shapes at once and want your full embroidery outlined without interfering with the inside this would be great to have - useful for many designs and things like patches

ie E.strokeAlignment( CENTER | EXTERNAL | INTERNAL); with thickness of the purple corresponding to E.strokeWeight image

or even the same thing with float input where internal corresponds to 1, center to 0, and internal to -1 which would provide more control depending on how precise someone wants to be with their stroke placement

golanlevin commented 4 years ago

Hm, "alignment" isn't quite the right term, since that suggests an orientation. Photoshop calls this attribute "location":

Screen Shot 2020-06-30 at 6 20 30 PM

I do think this is a good idea, and @tatyanade, I like your -1...0...1 suggestion. @LingDong- , I think having precise control over the location of the stroke would be helpful. Is this possible?

Also, @tatyanade, having variable control over the strokeLocation() is one thing, but if you just want it on the outside, I guess you have already seen #73 , https://github.com/CreativeInquiry/PEmbroider/issues/73 ...

LingDong- commented 4 years ago

ok! I can add that feature. With TANGENT mode it's easier (by rendering the Processing raster with some extra tricks). With PERPENDICULAR it is a lot more complicated but still doable.

tatyanade commented 4 years ago

@golan I think either I'm missing something or we are using the word outside differently; I'm meaning on the outside as in the first of these 2 images, and 73 does outside as in encircling all the shapes but still overlapping with the inner fill (2nd image), which is what i'm assuming you mean by outside?

image

golanlevin commented 4 years ago

@tatyanade you're correct; #73 would require some fuckery with booleanGraphics in order to achieve what I was talking about, which was a pure outside outline.

@LingDong- , my proposed API is

E.strokeLocation(PEmbroiderGraphics.OUTSIDE); 
E.strokeLocation(1.0); // same as above

E.strokeLocation(PEmbroiderGraphics.CENTER);
E.strokeLocation(0.0); // same as above

E.strokeLocation(PEmbroiderGraphics.INSIDE);
E.strokeLocation(-1.0); // same as above

with other fractions possible. For sanity's sake I propose clamp the fractions to -1...1, we shouldn't have to think about what it means if someone does E.strokeLocation(-3.0);

tatyanade commented 4 years ago

can also be achieved by culling all shapes from the outline of the union of the shapes, but stroke location simplifies this & yes! nice to be able to finesse the exact value (ie .33, .75) and a limit seems reasonable - guessing values of above that and below that would look something like this which does make sense as long as they don't go too negative lol - over 1 makes sense and might be usefull to some but i dont really thing anyone would need to go lower = if anyone needs to do something weird like that it is still possible through a combination of culling & outlines (stroke purple , actual shape in red) image

LingDong- commented 4 years ago

image

CENTER==3 :/

golanlevin commented 4 years ago

@LingDong- — It's OK, don't sweat it. just make new constants:

STROKE_OUTSIDE = 1.0; 
STROKE_CENTER = 0.0; 
STROKE_INSIDE = -1.0; 
LingDong- commented 4 years ago

Nah I fixed it with method overloading:


    static public final int INSIDE = -1;
    static public final int OUTSIDE = 1;
    static public final int CENTER = 3; // because Processing says so

    public float STROKE_LOCATION = 0.0f;

    public void strokeLocation(float x) {
        STROKE_LOCATION = PApplet.min(PApplet.max(-1,x),1);
    }

    public void strokeLocation(int mode) {
        if (mode == CENTER) {
            strokeLocation(0.0f);
        }else {
            strokeLocation((float)mode);
        }
    }

I already knew how to hack it, just thought it was funny so I posted sorry

LingDong- commented 4 years ago
Screen Shot 2020-07-01 at 12 56 05 AM

Hi @golanlevin @tatyanade

Feature added: 6e08f475e14d04cfd464f0544dafc28e437d8400

Also added an example: examples/PEmbroider_strokeLocation. Use mouseX to control strokeLocation interactively

However there's one problem: if the shape has a really skinny part (or a skinny gap) that's smaller than half of stroke weight, the erosion/dilation will devour it