CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
465 stars 27 forks source link

Satin error combines shapes in BSG #69

Open tatyanade opened 4 years ago

tatyanade commented 4 years ago

2020-06-27_20h29_29 2020-06-27_20h29_17

Running BSG with satin stitch, and it adds a line connecting some of the shapes(you can see in the picture above) while parallel stitch leaves them seperate

Running basically the code from BooleanOps animated does this

import processing.embroider.*;

PEmbroiderGraphics E;

void setup(){
  size(600,600);
  smooth();
  E = new PEmbroiderGraphics(this);
  E.setPath(sketchPath("bsg_test.vp3"));
  //E.noStroke();
  E.fill(0);
  //E.hatchMode(E.PARALLEL);
  E.hatchMode(E.SATIN);
  noLoop();

  PEmbroiderBooleanShapeGraphics BSG = new PEmbroiderBooleanShapeGraphics(width,height);

  BSG.rect(300,200,100,100);
  BSG.operator(PEmbroiderBooleanShapeGraphics.AND);
  BSG.circle(400,200,100);

  BSG.operator(PEmbroiderBooleanShapeGraphics.OR);

  BSG.circle(100,100,100);
  BSG.operator(PEmbroiderBooleanShapeGraphics.XOR);
  BSG.circle(150,100,100);

  BSG.operator(PEmbroiderBooleanShapeGraphics.OR);

  BSG.circle(100,250,100);
  BSG.circle(150,250,100);

  BSG.rect(300,50,100,100);
  BSG.operator(PEmbroiderBooleanShapeGraphics.DIFFERENCE);
  BSG.circle(400,50,100);

  E.image(BSG,0,0);

  E.optimize();
  E.visualize();
  E.endDraw();
  save("PEmbroider_satin_booleanOps_visAnim.png");
}
golanlevin commented 4 years ago

Definitely a bug. @LingDong- , could you kindly check this out.

LingDong- commented 4 years ago

So the algorithm can sometimes process multiple shapes in one pass (making a jump in-between), so the jump ends up being part of the design. One solution would be to create multiple masks for each shape, and run the algorithm on each mask. However this will be quite inefficient. To create the multiple masks we either need to use flood fill yet again (pretty slow), or first trace contours and re-render (probably taster, but more complicated and more prone to degenerate cases). Wonder if there's a better solution.