Yisaer / Nest4J

an open source nest algorithm by java based on SVGNest
MIT License
75 stars 35 forks source link

Some shapes are placed wrong when using rotations and holes. #11

Open Thejipppp opened 4 years ago

Thejipppp commented 4 years ago

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?