CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

NaN's in the optimizer... #23

Closed golanlevin closed 4 years ago

golanlevin commented 4 years ago

The following code is in PEmbroider_bitmap_image_1.pde, rendering the broken heart image:

  // Draw fat parallel stroke only; no fill.   
  E.noFill(); 
  E.stroke(0, 0, 0); 
  E.setStitch(2, 30, 1.0);
  E.strokeWeight(16); 
  E.strokeSpacing(4);
  E.strokeMode(PEmbroiderGraphics.PERPENDICULAR);
  E.image(myImage, 500, 250);

This code is producing the following worrisome output in the optimizer:

[PEmbroider Optimize] Input:NaN
[PEmbroider Optimize] Trial:0   NN:Infinity 2-Opt:2224.5767
[PEmbroider Optimize] Trial:1   NN:Infinity 2-Opt:2224.5767
[PEmbroider Optimize] Trial:2   NN:Infinity 2-Opt:2247.809
[PEmbroider Optimize] Trial:3   NN:Infinity 2-Opt:2275.2676
[PEmbroider Optimize] Trial:4   NN:Infinity 2-Opt:2301.788
[PEmbroider Optimize] Final:2224.5767
[PEmbroider Writer] BASENAME :/Users/golan/Desktop/PEmbroider-Uber/PEmbroider/examples/PEmbroider_bitmap_image_1/PEmbroider_bitmap_image_1
[PEmbroider Writer] EXTENSION:vp3
[PEmbroider Writer] Color count: 1
[PEmbroider Writer] Written!
LingDong- commented 4 years ago

Hi @golanlevin

Now fixed: 43a5b3209e940a558b8981d4988ca136d7470bc2

Turns out the fencepost error I solved yesterday created a zero division error.

Pretty cool that my TSP is resilient against NaNs! The average algorithm will pollute everything with NaN upon getting one, but this one actually gets rid of it automatically!

golanlevin commented 4 years ago

Thanks, @LingDong- , I had the same concern about NaNs. Glad this is resolved.