Code Monkey home page Code Monkey logo

nest4j's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nest4j's Issues

Shapes are placed within other shapes when there is not a hole.

I've tested the code with the x10 scaled testset SHAPES2 and a bin size of 20 000 x 150 (simulating an open ended plate).

main.java
        NestPath bin = new NestPath();
        double binWidth = 20000;
        double binHeight = 150;
        bin.add(0, 0);
        bin.add(binWidth, 0);
        bin.add(binWidth, binHeight);
        bin.add(0, binHeight);

        List<NestPath> polygons = transferSvgIntoPolygons();

        Config config = new Config();
        config.SPACING = 0;
        config.POPULATION_SIZE = 5;
        config.USE_HOLE = false;

        Nest nest = new Nest(bin, polygons, config, 10);
        List<List<Placement>> appliedPlacement = nest.startNest();

        List<String> strings = SvgUtil.svgGenerator(polygons, appliedPlacement, binWidth, binHeight);
        saveSvgFile(strings);
SHAPES2.xml
<root>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<polygon points="500,500 520,490 540,500 540,530 520,540 500,530 " />
<polygon points="500,1500 520,1490 540,1500 540,1530 520,1540 500,1530 " />
<polygon points="500,3500 520,3490 540,3500 540,3530 520,3540 500,3530 " />
<polygon points="500,6500 520,6490 540,6500 540,6530 520,6540 500,6530 " />
<polygon points="1500,500 1530,500 1520,520 1530,540 1530,550 1510,550 1490,530 1490,510 " />
<polygon points="1500,1500 1530,1500 1520,1520 1530,1540 1530,1550 1510,1550 1490,1530 1490,1510 " />
<polygon points="1500,3500 1530,3500 1520,3520 1530,3540 1530,3550 1510,3550 1490,3530 1490,3510 " />
<polygon points="1500,6500 1530,6500 1520,6520 1530,6540 1530,6550 1510,6550 1490,6530 1490,6510 " />
<polygon points="2500,500 2520,500 2530,510 2530,530 2520,540 2500,540 2490,530 2490,510 " />
<polygon points="2500,1500 2520,1500 2530,1510 2530,1530 2520,1540 2500,1540 2490,1530 2490,1510 " />
<polygon points="2500,3500 2520,3500 2530,3510 2530,3530 2520,3540 2500,3540 2490,3530 2490,3510 " />
<polygon points="2500,6500 2520,6500 2530,6510 2530,6530 2520,6540 2500,6540 2490,6530 2490,6510 " />
<polygon points="3500,500 3520,510 3540,500 3530,520 3540,550 3520,540 3500,550 3510,530 " />
<polygon points="3500,1500 3520,1510 3540,1500 3530,1520 3540,1550 3520,1540 3500,1550 3510,1530 " />
<polygon points="3500,3500 3520,3510 3540,3500 3530,3520 3540,3550 3520,3540 3500,3550 3510,3530 " />
<polygon points="3500,6500 3520,6510 3540,6500 3530,6520 3540,6550 3520,6540 3500,6550 3510,6530 " />
<polygon points="4500,500 4550,500 4550,550 4540,550 4530,530 4520,520 4500,510 " />
<polygon points="4500,1500 4550,1500 4550,1550 4540,1550 4530,1530 4520,1520 4500,1510 " />
<polygon points="4500,3500 4550,3500 4550,3550 4540,3550 4530,3530 4520,3520 4500,3510 " />
<polygon points="4500,6500 4550,6500 4550,6550 4540,6550 4530,6530 4520,6520 4500,6510 " />
<polygon points="5500,500 5520,530 5480,530 " />
<polygon points="5500,1500 5520,1530 5480,1530 " />
<polygon points="5500,3500 5520,3530 5480,3530 " />
<polygon points="5500,6500 5520,6530 5480,6530 " />
<polygon points="6500,500 6520,500 6520,520 6500,520 " />
<polygon points="6500,1500 6520,1500 6520,1520 6500,1520 " />
<polygon points="6500,3500 6520,3500 6520,3520 6500,3520 " />
<polygon points="6500,6500 6520,6500 6520,6520 6500,6520 " />
</root>
SHAPES2.svg
<!DOCTYPE html>
<html>
<body>

<svg height="8000" width="8000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink"><polygon points="500,1500 520,1490 540,1500 540,1530 520,1540 500,1530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="500,2500 520,2490 540,2500 540,2530 520,2540 500,2530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="500,3500 520,3490 540,3500 540,3530 520,3540 500,3530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="500,4500 520,4490 540,4500 540,4530 520,4540 500,4530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="1500,1500 1530,1500 1520,1520 1530,1540 1530,1550 1510,1550 1490,1530 1490,1510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="1500,2500 1530,2500 1520,2520 1530,2540 1530,2550 1510,2550 1490,2530 1490,2510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="1500,3500 1530,3500 1520,3520 1530,3540 1530,3550 1510,3550 1490,3530 1490,3510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="1500,4500 1530,4500 1520,4520 1530,4540 1530,4550 1510,4550 1490,4530 1490,4510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="2500,1500 2520,1500 2530,1510 2530,1530 2520,1540 2500,1540 2490,1530 2490,1510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="2500,2500 2520,2500 2530,2510 2530,2530 2520,2540 2500,2540 2490,2530 2490,2510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="2500,3500 2520,3500 2530,3510 2530,3530 2520,3540 2500,3540 2490,3530 2490,3510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="2500,4500 2520,4500 2530,4510 2530,4530 2520,4540 2500,4540 2490,4530 2490,4510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="3500,1500 3520,1510 3540,1500 3530,1520 3540,1550 3520,1540 3500,1550 3510,1530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="3500,2500 3520,2510 3540,2500 3530,2520 3540,2550 3520,2540 3500,2550 3510,2530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="3500,3500 3520,3510 3540,3500 3530,3520 3540,3550 3520,3540 3500,3550 3510,3530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="3500,4500 3520,4510 3540,4500 3530,4520 3540,4550 3520,4540 3500,4550 3510,4530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="4500,1500 4550,1500 4550,1550 4540,1550 4530,1530 4520,1520 4500,1510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="4500,2500 4550,2500 4550,2550 4540,2550 4530,2530 4520,2520 4500,2510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="4500,3500 4550,3500 4550,3550 4540,3550 4530,3530 4520,3520 4500,3510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="4500,4500 4550,4500 4550,4550 4540,4550 4530,4530 4520,4520 4500,4510 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="5500,1500 5520,1530 5480,1530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="5500,2500 5520,2530 5480,2530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="5500,3500 5520,3530 5480,3530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="5500,4500 5520,4530 5480,4530 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="6500,1500 6520,1500 6520,1520 6500,1520 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="6500,2500 6520,2500 6520,2520 6500,2520 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="6500,3500 6520,3500 6520,3520 6500,3520 " style="fill:lime;stroke:purple;stroke-width:1" />
<polygon points="6500,4500 6520,4500 6520,4520 6500,4520 " style="fill:lime;stroke:purple;stroke-width:1" />
</svg>

</body>
</html>

Some squares are added within the octagons when they obviously shouldn't.

image

result.svg
<?xml version="1.0" standalone="no"?>

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg">
 <g transform="translate(10  0)">
    <rect x="0" y="0" width="20000.0" height="150.0"  fill="none" stroke="#010101" stroke-width="1" />
<g transform="translate(-500.010 -490.00) rotate(0.0)"> 
<path d="M500.0 500.0 L520.0 490.0 L540.0 500.0 L540.0 530.0 L520.0 540.0 L500.0 530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-500.010 -1440.00) rotate(0.0)"> 
<path d="M500.0 1500.0 L520.0 1490.0 L540.0 1500.0 L540.0 1530.0 L520.0 1540.0 L500.0 1530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(540.010 3640.00) rotate(180.0)"> 
<path d="M500.0 3500.0 L520.0 3490.0 L540.0 3500.0 L540.0 3530.0 L520.0 3540.0 L500.0 3530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(580.010 6640.00) rotate(180.0)"> 
<path d="M500.0 6500.0 L520.0 6490.0 L540.0 6500.0 L540.0 6530.0 L520.0 6540.0 L500.0 6530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-1450.010 -450.00) rotate(0.0)"> 
<path d="M1500.0 500.0 L1530.0 500.0 L1520.0 520.0 L1530.0 540.0 L1530.0 550.0 L1510.0 550.0 L1490.0 530.0 L1490.0 510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-1430.010 -1500.00) rotate(0.0)"> 
<path d="M1500.0 1500.0 L1530.0 1500.0 L1520.0 1520.0 L1530.0 1540.0 L1530.0 1550.0 L1510.0 1550.0 L1490.0 1530.0 L1490.0 1510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-1415.010 -3450.00) rotate(0.0)"> 
<path d="M1500.0 3500.0 L1530.0 3500.0 L1520.0 3520.0 L1530.0 3540.0 L1530.0 3550.0 L1510.0 3550.0 L1490.0 3530.0 L1490.0 3510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-1395.010 -6500.00) rotate(0.0)"> 
<path d="M1500.0 6500.0 L1530.0 6500.0 L1520.0 6520.0 L1530.0 6540.0 L1530.0 6550.0 L1510.0 6550.0 L1490.0 6530.0 L1490.0 6510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(4630.010 649.99990) rotate(180.0)"> 
<path d="M4500.0 500.0 L4550.0 500.0 L4550.0 550.0 L4540.0 550.0 L4530.0 530.0 L4520.0 520.0 L4500.0 510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(4665.010 1632.49990) rotate(180.0)"> 
<path d="M4500.0 1500.0 L4550.0 1500.0 L4550.0 1550.0 L4540.0 1550.0 L4530.0 1530.0 L4520.0 1520.0 L4500.0 1510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-4392.010 -3435.99990) rotate(0.0)"> 
<path d="M4500.0 3500.0 L4550.0 3500.0 L4550.0 3550.0 L4540.0 3550.0 L4530.0 3530.0 L4520.0 3520.0 L4500.0 3510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(2660.010 539.99990) rotate(180.0)"> 
<path d="M2500.0 500.0 L2520.0 500.0 L2530.0 510.0 L2530.0 530.0 L2520.0 540.0 L2500.0 540.0 L2490.0 530.0 L2490.0 510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(4708.010 6619.00) rotate(180.0)"> 
<path d="M4500.0 6500.0 L4550.0 6500.0 L4550.0 6550.0 L4540.0 6550.0 L4530.0 6530.0 L4520.0 6520.0 L4500.0 6510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-2330.510 -1469.49990) rotate(0.0)"> 
<path d="M2500.0 1500.0 L2520.0 1500.0 L2530.0 1510.0 L2530.0 1530.0 L2520.0 1540.0 L2500.0 1540.0 L2490.0 1530.0 L2490.0 1510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(2716.666610 3603.33330) rotate(180.0)"> 
<path d="M2500.0 3500.0 L2520.0 3500.0 L2530.0 3510.0 L2530.0 3530.0 L2520.0 3540.0 L2500.0 3540.0 L2490.0 3530.0 L2490.0 3510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(2718.999810 6540.00) rotate(180.0)"> 
<path d="M2500.0 6500.0 L2520.0 6500.0 L2530.0 6510.0 L2530.0 6530.0 L2520.0 6540.0 L2500.0 6540.0 L2490.0 6530.0 L2490.0 6510.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(3760.010 649.99990) rotate(180.0)"> 
<path d="M3500.0 500.0 L3520.0 510.0 L3540.0 500.0 L3530.0 520.0 L3540.0 550.0 L3520.0 540.0 L3500.0 550.0 L3510.0 530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-3277.333410 -3448.66660) rotate(0.0)"> 
<path d="M3500.0 3500.0 L3520.0 3510.0 L3540.0 3500.0 L3530.0 3520.0 L3540.0 3550.0 L3520.0 3540.0 L3500.0 3550.0 L3510.0 3530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-3274.333510 -1500.00) rotate(0.0)"> 
<path d="M3500.0 1500.0 L3520.0 1510.0 L3540.0 1500.0 L3530.0 1520.0 L3540.0 1550.0 L3520.0 1540.0 L3500.0 1550.0 L3510.0 1530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(3792.666610 6621.33340) rotate(180.0)"> 
<path d="M3500.0 6500.0 L3520.0 6510.0 L3540.0 6500.0 L3530.0 6520.0 L3540.0 6550.0 L3520.0 6540.0 L3500.0 6550.0 L3510.0 6530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(5682.666710 649.00) rotate(180.0)"> 
<path d="M5500.0 500.0 L5520.0 530.0 L5480.0 530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(5775.666510 1549.99980) rotate(180.0)"> 
<path d="M5500.0 1500.0 L5520.0 1530.0 L5480.0 1530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-5222.010 -3385.99990) rotate(0.0)"> 
<path d="M5500.0 3500.0 L5520.0 3530.0 L5480.0 3530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-5218.555810 -6458.66650) rotate(0.0)"> 
<path d="M5500.0 6500.0 L5520.0 6530.0 L5480.0 6530.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-6370.010 -490.00) rotate(0.0)"> 
<path d="M6500.0 500.0 L6520.0 500.0 L6520.0 520.0 L6500.0 520.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(6655.010 3564.00) rotate(180.0)"> 
<path d="M6500.0 3500.0 L6520.0 3500.0 L6520.0 3520.0 L6500.0 3520.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(-6340.510 -1459.49990) rotate(0.0)"> 
<path d="M6500.0 1500.0 L6520.0 1500.0 L6520.0 1520.0 L6500.0 1520.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
<g transform="translate(6715.333410 6649.99990) rotate(180.0)"> 
<path d="M6500.0 6500.0 L6520.0 6500.0 L6520.0 6520.0 L6500.0 6520.0 Z" fill="#8498d1" stroke="#010101" stroke-width="1" /> 
</g> 
</g> 
</svg>

Any idea why this could be the case?

Overlapping shapes in the nesting output

Hi, I was testing your very interesting work with a sample case. The following file contains all the polygons, each one in a different line (skip the first too lines though).
Shapes.txt

And the output I get contains several instances of overlapping polygons.
image
Even some polygons are reaching outside of the rectangular bin. The full output as zipped SVG is below.
output.svg.zip

Previous test with a single bin worked ok. The relevant code setting up the nesting for this example is pasted below:

  NestPath binPolygon = new NestPath();
  double width = 2000;
  double height = 1200;
  binPolygon.add(0, 0);
  binPolygon.add(0, height);
  binPolygon.add(width, height);
  binPolygon.add(width, 0);
  int i=0;
  List<NestPath> list = new ArrayList<NestPath>();
  for (Vector<PVector> out : shapes) {
    NestPath s = new NestPath();
    for (PVector p : out) s.add(p.x, p.y);
    s.bid=i++; 
    list.add(s); 
  }
  Config config = new Config();
  config.USE_HOLE = true;
  Nest nest = new Nest(binPolygon, list, config, 1);
  List<List<Placement>> appliedPlacement = nest.startNest();

The only thing that I suspect is that though I set USE_HOLE to true, I failed to provide parts with holes. Not sure if that could trigger this result... ?

currently "path" is not supported in test.xml

Hi,
are you working on "path" shape also?
<path id="abc" d="M509.9996533203125 339.33300030231476 L528.1977066802979 379.51503002643585 L530.892187576294 384.59039318561554 L534.0756611633301 389.37422955036163 L537.7168793487549 393.8195801973343 L539.7484917449951 395.8511964082718 L541.7801041412354 397.88280498981476 L546.2254528808594 401.5240250825882 L551.0092892456055 404.7074967622757 L556.0846524047852 407.4019776582718 L596.2666821289063 425.60004436969757 L819.0818371582031 383.1807633638382 L823.7404675292969 381.70978558063507 L828.0861096191406 379.4776841402054 L831.9953503417969 376.5477830171585 L835.3573498535156 373.00324261188507 L838.0766491699219 368.9446564912796 L840.0760388183594 364.4871903657913 L841.29884765625 359.75733959674835 L841.7103466796875 354.88935101032257 L841.29884765625 350.0213586091995 L840.0760388183594 345.2915154695511 L838.0766491699219 340.83404552936554 L835.3573498535156 336.7754555940628 L831.9953503417969 333.23091518878937 L828.0861096191406 330.30101788043976 L823.7404675292969 328.06890881061554 L819.0818371582031 326.59793865680695 L588.0992855834961 290.8003200292587 L578.9446835327149 290.39995563030243 L569.8256993103028 291.30063396692276 L560.9263119506836 293.484197974205 L552.4260639953613 296.9065924882889 L512.7022619056702 336.6303902864456 Z" width="331.71" height="135.2" stroke-width="1.5" stroke="#000" fill="#fff"/>

Final transformation results

First off, I wanted to say this is a brilliant tool you've written here. It's works amazingly well, easy to use and understand.

I just wanted some help understanding the final transformations. I'm using Nest4J as a command line jar and I'm passing it the list of polygon vertices in a file. To make sure the polygons do not overlap I just add 1000 to the x-coordinate of the previous model.

void readFile(String filePath) throws IOException{
	File file = new File(filePath);
	BufferedReader br = new BufferedReader(new FileReader(file));
	
	binWidth = Double.parseDouble(br.readLine().trim());
	binHeight = Double.parseDouble(br.readLine().trim());
	spacingBetweenModels = Double.parseDouble(br.readLine().trim());
	
	bin = new NestPath();
	bin.add(0, 0);
    bin.add(binWidth, 0);
    bin.add(binWidth, binHeight);
    bin.add(0, binHeight);
    bin.bid = 0;
	
	String line;
	int count = 1;
	while ((line = br.readLine()) != null) {
		NestPath model = new NestPath();
	    String[] input = line.split(",");
	    for(int i = 0; i < input.length; i = i + 2){
	    	model.add(Double.parseDouble(input[i]) + count * 1000, Double.parseDouble(input[i+1]));
	    }
	    model.bid = count++;
	    model.setRotation(360);
	    listOfModels.add(model);
	  } 
	
	br.close();
}

So, it keeps adding 1000 to the x-coordinate off the previous model, so nothing ends up overlapping. I tested it out by writing an SVG file and it works perfectly!

My question is about the final Placement output. What does translate refer to with respect to the original point? Also, is rotation after translation and is it with the original point as the center of rotation? I wanted to reproduce the output in my application so I wanted a way to use the placement results in my application after removing the +1000 x coordinate addition I made to not make them overlap.

Translating to C#

Hi,

I am .NET user.
I would like to translate SVGNet library to C# language.

I noticed that you javascript version is more readable.
Are there any elements in the code that are very specific to javascript? Or do you think it is totally doable to translate into C# since those two languages are very similar?

Some shapes are placed wrong when using rotations and holes.

Hello.

Massive thanks for this code contribution.
I was playing around with the use_holes option and got some very strange results.

I used this code. It adds 2 big squares, a square hole in one of them and 4 little squares that should fit into the hole.

NestPath bin = new NestPath();
double binWidth = 500;
double binHeight = 200;
bin.add(0, 0);
bin.add(binWidth, 0);
bin.add(binWidth, binHeight);
bin.add(0, binHeight);

double mins[] = {0,60,101,300,310,320,330};
double maxs[] = {100,81,200,310,320,330,340};

List<NestPath> polygons = new ArrayList<NestPath>();
for(int i = 0; i < 7; i++){
	NestPath p = new NestPath();
	p.add(mins[i], mins[i]);
	p.add(mins[i], maxs[i]);
	p.add(maxs[i], maxs[i]);
	p.add(maxs[i], mins[i]);
	p.bid = i;
	p.setRotation(4);
	polygons.add(p);
}

Config config = new Config();
config.SPACING = 0;
config.POPULATION_SIZE = 5;
config.USE_HOLE = true;

Nest nest = new Nest(bin, polygons, config, 2);
List<List<Placement>> appliedPlacement = nest.startNest();

List<String> strings = SvgUtil.svgGenerator(polygons, appliedPlacement, binWidth, binHeight);
saveSvgFile(strings);

And I got the following result. Note that the hole is normally below the polygon in which it belongs, but I brought it up and colored it red.

image

It seems that some polygons try to use the hole with an OuterNFP instead of an innerNFP. I searched a little bit, but I did not find what could be possibly wrong.

When the polygons have no rotations, everything goes like expected and the hole is filled properly.

Do you have any idea what could be the issue or what I am doing wrong?

it occurs error, if null returned.

public static int toTree(List list , int idstart)
{
// I changed the code below;
Boolean isInside = GeometryUtil.pointInPolygon(p.getSegments().get(0) , list.get(j));
if( isInside != null && isInside == true ){
list.get(j).getChildren().add(p);
p.setParent(list.get(j));
isChild = true;
break;
}
}

Hollow Polygon

Hi there,
we found an issue regarding the placing of hollow polygons with USE_HOLE = false. In particular we expect that using this parameter we'll never have a polygon inside another.

However, running the following code, we have the same result both with USE_HOLE = false and USE_HOLE = true.

    NestPath binPolygon = new NestPath();
    double width = 400;
    double height = 400;
    binPolygon.add(0, 0);
    binPolygon.add(0, height);
    binPolygon.add(width, height);
    binPolygon.add(width, 0);

    List<NestPath> list = new ArrayList<NestPath>();
    NestPath outer = new NestPath();
    outer.add(600, 0);
    outer.add(600, 200);
    outer.add(800, 200);
    outer.add(800, 0);
    outer.setRotation(0);
    outer.bid = 1;
    list.add(outer);
    NestPath inner = new NestPath();
    inner.add(650, 50);
    inner.add(650, 150);
    inner.add(750, 150);
    inner.add(750, 50);
    inner.bid = 2;
    list.add(inner);

    Config config = new Config();
    config.SPACING = 0;
    config.USE_HOLE = false;
    Nest nest = new Nest(binPolygon, list, config, 2);
    List<List<Placement>> appliedPlacement = nest.startNest();

The result is the follow: as you can see, the second polygon is placed inside the first one.
schermata 2018-07-16 alle 12 17 56

Can you confirm that this is not the expected behavior?
Thanks

README en_us version is coming soon.

Recently I m busy with my studies and works, so I only wrote a README in zh_cn version.

And I will post an README en_us Version before next week. I think this may help those who need a server-side Nest.

ways to calculate Multi bin?

Hi @Yisaer, thanks a lot for this amazing tool.

I personally do not have much knowledge about nesting algorithms. But I wonder if it is possible to extend the nesting to support multiple formats of bin?

For instance we now have Nest nest = new Nest(bin, polygons, config, 2);

How can we achieve Nest nest = new Nest(bins, polygons, config, 2); where bins is a list of bin or course.

Would be grateful if you give some insights. Thanks!

Help needed please

Hi,

I am new to java and I am battling to get Nest4J to run. If I try to run it with java, javaw I get error "Could not find or load main class in nest.java - java version 1.8.0_221 and the same with java, javac and javaw with java version 1.8.0_162

I would appreciate it if you could please let me know how to get Nest4J to run. What is the command line syntax?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.