public void CorrectNumberOfTops()
        {
            // 3 top layers and no bottom layers
            {
                // A simple cube that should have enough bottom layers
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       inset0Outline       = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(inset0Outline, numLayers);
                GenerateLayers(extruder, 400, 0, 3, 0);
                for (int i = 0; i < 7; i++)
                {
                    Assert.IsTrue(extruder.OnlyHasInfill(i));
                }
                Assert.IsTrue(extruder.OnlyHasFirstTop(7));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(8));
                Assert.IsTrue(extruder.OnlyHasTop(9));
            }

            // 3 bottom layers and 1 top layer
            {
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       inset0Outline       = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(inset0Outline, numLayers);
                GenerateLayers(extruder, 400, 3, 1, 0);
                Assert.IsTrue(extruder.OnlyHasBottom(0));
                for (int i = 1; i < 3; i++)
                {
                    Assert.IsTrue(extruder.OnlyHasSolidInfill(i));
                }
                for (int i = 3; i < 9; i++)
                {
                    Assert.IsTrue(extruder.OnlyHasInfill(i));
                }
                Assert.IsTrue(extruder.OnlyHasTop(9));
            }

            // 3 top layers and 3 bottom layers
            {
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       inset0Outline       = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(inset0Outline, numLayers);
                GenerateLayers(extruder, 400, 3, 3, 0);
                Assert.IsTrue(extruder.OnlyHasBottom(0));
                for (int i = 1; i < 3; i++)
                {
                    Assert.IsTrue(extruder.OnlyHasSolidInfill(i));
                }
                for (int i = 3; i < 7; i++)
                {
                    Assert.IsTrue(extruder.OnlyHasInfill(i));
                }
                Assert.IsTrue(extruder.OnlyHasFirstTop(7));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(8));
                Assert.IsTrue(extruder.OnlyHasTop(9));
            }
        }
예제 #2
0
        public void SeemOnPolygon()
        {
            return;

            var polygon1String = "x:-9.85, y:-11.85,x:-9.64, y:-11.82,x:-9.16, y:-11.62,x:-8.9, y:-11.53,x:-8.17, y:-11.51,x:-7.89, y:-11.46,x:-7.7, y:-11.38,x:-7.48, y:-11.2,x:-7.27, y:-11.07,x:-7.04, y:-11.02,x:-1.18, y:-10.97,x:6.86, y:-11.01,x:7.13, y:-11.03,x:7.37, y:-11.11,x:7.66, y:-11.35,x:7.85, y:-11.45,x:8.08, y:-11.5,x:8.91, y:-11.53,x:9.17, y:-11.62,x:9.64, y:-11.82,x:9.85, y:-11.85,x:10, y:-11.82,x:10.15, y:-11.74,x:10.25, y:-11.66,x:10.31, y:-11.56,x:10.62, y:-10.95,x:10.79, y:-10.75,x:12.01, y:-9.86,x:12.48, y:-9.43,x:12.91, y:-8.97,x:13.29, y:-8.49,x:13.6, y:-8.03,x:13.92, y:-7.45,x:14.24, y:-6.75,x:14.44, y:-6.14,x:14.6, y:-5.49,x:14.71, y:-4.84,x:14.76, y:-4.18,x:14.76, y:-3.61,x:14.71, y:-2.94,x:14.58, y:-2.19,x:14.4, y:-1.53,x:14.16, y:-0.88,x:13.88, y:-0.26,x:13.46, y:0.44,x:13.05, y:1,x:12.62, y:1.49,x:12.14, y:1.94,x:11.63, y:2.35,x:11.08, y:2.71,x:10.5, y:3.03,x:9.89, y:3.29,x:9.18, y:3.54,x:9.04, y:3.78,x:8.76, y:4.2,x:8.36, y:4.44,x:7.79, y:4.7,x:7.2, y:4.9,x:6.68, y:5.01,x:6.16, y:5.05,x:-5.99, y:5.06,x:-6.39, y:5.04,x:-6.84, y:4.98,x:-7.21, y:4.9,x:-7.66, y:4.75,x:-8.09, y:4.57,x:-8.75, y:4.2,x:-8.87, y:4.04,x:-9.17, y:3.53,x:-9.5, y:3.43,x:-10.2, y:3.16,x:-10.79, y:2.88,x:-11.35, y:2.54,x:-11.89, y:2.15,x:-12.38, y:1.72,x:-12.84, y:1.24,x:-13.23, y:0.76,x:-13.57, y:0.26,x:-13.9, y:-0.32,x:-14.2, y:-0.98,x:-14.42, y:-1.61,x:-14.59, y:-2.27,x:-14.7, y:-2.93,x:-14.75, y:-3.61,x:-14.75, y:-4.18,x:-14.7, y:-4.84,x:-14.57, y:-5.61,x:-14.4, y:-6.26,x:-14.16, y:-6.91,x:-13.86, y:-7.55,x:-13.5, y:-8.18,x:-13.11, y:-8.71,x:-12.69, y:-9.21,x:-12.24, y:-9.65,x:-11.75, y:-10.06,x:-10.78, y:-10.76,x:-10.6, y:-10.96,x:-10.32, y:-11.55,|";
            var polygon1       = CLPolygonsExtensions.CreateFromString(polygon1String, 1000)[0];
            var index          = polygon1.FindGreatestTurnIndex(400, 0, SEAM_PLACEMENT.FURTHEST_BACK, default(IntPoint));

            SavePolygonToImage(polygon1, "C:\\temp\\polygon.jpg", 640, (g, t) =>
            {
                var circle = new Ellipse(polygon1[0].X, polygon1[0].Y, 2, 2);
                g.Render(new VertexSourceApplyTransform(new Stroke(circle, 1000), t), Color.Blue);
                circle = new Ellipse(polygon1[index].X, polygon1[index].Y, 2, 2);
                g.Render(new VertexSourceApplyTransform(new Stroke(circle, 1000), t), Color.Red);
            });
        }
예제 #3
0
        private static double GetAngleForData(string islandToFillString, string layerSupportingIslandString, string debugName)
        {
            Polygons islandToFill = CLPolygonsExtensions.CreateFromString(islandToFillString);

            SliceLayer prevLayer = new SliceLayer();

            prevLayer.Islands = new List <LayerIsland>();
            LayerIsland part = new LayerIsland();

            part.IslandOutline = CLPolygonsExtensions.CreateFromString(layerSupportingIslandString);
            prevLayer.Islands.Add(part);
            prevLayer.Islands[0].BoundingBox.Calculate(prevLayer.Islands[0].IslandOutline);

            double bridgeAngle;
            bool   foundBridgeAngle = prevLayer.BridgeAngle(islandToFill, out bridgeAngle, debugName);

            return(bridgeAngle);
        }
예제 #4
0
        public void CorrectNumberOfBottoms()
        {
            // 3 bottom layers and no top layers
            {
                // A simple cube that should have enough bottom layers
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       partOutline         = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(partOutline, numLayers);
                GenerateLayers(extruder, 400, 3, 0, 0);
                Assert.IsTrue(extruder.OnlyHasBottom(0));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(1));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(2));
                Assert.IsTrue(extruder.OnlyHasInfill(3));
            }

            // 3 bottom layers and 1 top layer
            {
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       inset0Outline       = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(inset0Outline, numLayers);
                GenerateLayers(extruder, 400, 3, 1, 0);
                Assert.IsTrue(extruder.OnlyHasBottom(0));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(1));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(2));
                Assert.IsTrue(extruder.OnlyHasInfill(3));
            }

            // 3 bottom layers and 3 top layers
            {
                string         inset0OutlineString = "x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|";
                Polygons       inset0Outline       = CLPolygonsExtensions.CreateFromString(inset0OutlineString);
                int            numLayers           = 10;
                ExtruderLayers extruder            = CreateLayerData(inset0Outline, numLayers);
                GenerateLayers(extruder, 400, 3, 3, 0);
                Assert.IsTrue(extruder.OnlyHasBottom(0));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(1));
                Assert.IsTrue(extruder.OnlyHasSolidInfill(2));
                Assert.IsTrue(extruder.OnlyHasInfill(3));
            }
        }
예제 #5
0
        private static double GetAngleForData(string islandToFillString, string layerSupportingIslandString, string debugName)
        {
            var islandToFill = CLPolygonsExtensions.CreateFromString(islandToFillString);

            var prevLayer = new SliceLayer
            {
                Islands = new List <LayerIsland>()
            };
            var part = new LayerIsland
            {
                IslandOutline = CLPolygonsExtensions.CreateFromString(layerSupportingIslandString)
            };

            prevLayer.Islands.Add(part);
            prevLayer.Islands[0].BoundingBox.Calculate(prevLayer.Islands[0].IslandOutline);

            prevLayer.BridgeAngle(islandToFill, 0, out double bridgeAngle, null, debugName);

            return(bridgeAngle);
        }
예제 #6
0
        public void CorrectPolygonOrder()
        {
            //                  |
            //     2       1    |    1       2
            //                  |
            //                  |
            //     3       0    |    0       3
            // _________________|__________________
            //                  |
            //     3       0    |    0       3
            //                  |
            //                  |
            //     2       1    |    1       2
            //                  |

            string polyQ1String = "x:5, y:5,x:5, y:10,x:10, y:10,x:10, y:5,|";
            var    polyQ1       = CLPolygonsExtensions.CreateFromString(polyQ1String)[0];

            string polyQ2String = "x:-5, y:5,x:-5, y:10,x:-10, y:10,x:-10, y:5,|";
            var    polyQ2       = CLPolygonsExtensions.CreateFromString(polyQ2String)[0];

            string polyQ3String = "x:-5, y:-5,x:-5, y:-10,x:-10, y:-10,x:-10, y:-5,|";
            var    polyQ3       = CLPolygonsExtensions.CreateFromString(polyQ3String)[0];

            string polyQ4String = "x:5, y:-5,x:5, y:-10,x:10, y:-10,x:10, y:-5,|";
            var    polyQ4       = CLPolygonsExtensions.CreateFromString(polyQ4String)[0];

            var settings = new ConfigSettings();

            // test simple finding
            {
                var pPathOrderOptimizer = new PathOrderOptimizer(settings);
                pPathOrderOptimizer.AddPolygon(polyQ1, 0);
                pPathOrderOptimizer.AddPolygon(polyQ2, 1);

                // starting at low far right
                pPathOrderOptimizer.Optimize(new IntPoint(20, 0), null, 0, false, null);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths.Count);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[0].SourcePolyIndex);
                Assert.AreEqual(3, pPathOrderOptimizer.OptimizedPaths[0].PointIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].SourcePolyIndex);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[1].PointIndex);

                // starting at high far right
                pPathOrderOptimizer.Optimize(new IntPoint(20, 20), null, 0, false, null);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths.Count);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[0].SourcePolyIndex);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths[0].PointIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].SourcePolyIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].PointIndex);

                // starting at high far left
                pPathOrderOptimizer.Optimize(new IntPoint(-20, 20), null, 0, false, null);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths.Count);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[0].SourcePolyIndex);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths[0].PointIndex);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[1].SourcePolyIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].PointIndex);
            }

            // test that single lines connect correctly
            {
                var pPathOrderOptimizer = new PathOrderOptimizer(settings);
                pPathOrderOptimizer.AddPolygons(
                    CLPolygonsExtensions.CreateFromString(
                        "x:0, y:0,x:500, y:0,|x:0, y:100,x:500, y:100,|x:0, y:200,x:500, y:200,|x:0, y:300,x:500, y:300,|"));

                // starting at low far right
                pPathOrderOptimizer.Optimize(new IntPoint(0, 0), null, 0, false, null);
                Assert.AreEqual(4, pPathOrderOptimizer.OptimizedPaths.Count);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[0].SourcePolyIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].SourcePolyIndex);
                Assert.AreEqual(2, pPathOrderOptimizer.OptimizedPaths[2].SourcePolyIndex);
                Assert.AreEqual(3, pPathOrderOptimizer.OptimizedPaths[3].SourcePolyIndex);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[0].PointIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].PointIndex);
                Assert.AreEqual(0, pPathOrderOptimizer.OptimizedPaths[0].PointIndex);
                Assert.AreEqual(1, pPathOrderOptimizer.OptimizedPaths[1].PointIndex);
            }
        }
예제 #7
0
        public void MergeLinesWorks()
        {
            // connected up
            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 0), new IntPoint(0, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 205), new IntPoint(0, 300)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments(6);
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 300), merged[0][1]);
            }

            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 0), new IntPoint(0, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 50), new IntPoint(0, 300)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments();
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 300), merged[0][1]);
            }

            // connected up swapped
            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 0), new IntPoint(0, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 300), new IntPoint(0, 205)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments();
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 300), merged[0][1]);
            }

            // connected down
            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 200), new IntPoint(0, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 205), new IntPoint(0, 300)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments();
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 300), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][1]);
            }

            // connected down swapped
            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 200), new IntPoint(0, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 300), new IntPoint(0, 205)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments();
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 300), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][1]);
            }

            // connected down swapped
            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 200), new IntPoint(0, 300)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 600)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 300), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 200)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments();
                Assert.AreEqual(1, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 600), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][1]);
            }

            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 200), new IntPoint(0, 300)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 600)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 300), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 100), new IntPoint(30, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 200), new IntPoint(30, 300)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 500), new IntPoint(30, 600)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 300), new IntPoint(30, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 500), new IntPoint(30, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 100), new IntPoint(30, 200)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments(20, 10);
                Assert.AreEqual(2, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 600), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][1]);
                Assert.AreEqual(2, merged[1].Count);
                Assert.AreEqual(new IntPoint(30, 600), merged[1][0]);
                Assert.AreEqual(new IntPoint(30, 0), merged[1][1]);
            }

            {
                var lineSegments = new Polygons()
                {
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 500), new IntPoint(30, 600)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 600)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 200), new IntPoint(30, 300)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 100), new IntPoint(0, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 100), new IntPoint(30, 200)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 300), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 200), new IntPoint(0, 300)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 500), new IntPoint(30, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(0, 500), new IntPoint(0, 400)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 100), new IntPoint(30, 0)
                    },
                    new Polygon()
                    {
                        new IntPoint(30, 300), new IntPoint(30, 400)
                    },
                };

                var merged = lineSegments.MergeColinearLineSegments(20, 10);
                Assert.AreEqual(2, merged.Count);
                Assert.AreEqual(2, merged[0].Count);
                Assert.AreEqual(new IntPoint(0, 600), merged[0][0]);
                Assert.AreEqual(new IntPoint(0, 0), merged[0][1]);
                Assert.AreEqual(2, merged[1].Count);
                // reversed, but don't know why
                Assert.AreEqual(new IntPoint(30, 600), merged[1][0]);
                Assert.AreEqual(new IntPoint(30, 0), merged[1][1]);
            }

            {
                var polygonString = @"x:10753, y:3599,x:11186, y:3599,|x:10746, y:3199,x:11182, y:3199,|x:11042, y:3999,x:11135, y:3999,|x:10738, y:2799,x:10938, y:2799,|x:7119, y:2399,x:9111, y:2399,|x:7120, y:1999,x:9111, y:1999,|x:7120, y:1599,x:9111, y:1599,|x:31710, y:3599,x:32138, y:3599,|x:31711, y:3199,x:32138, y:3199,|x:31768, y:3999,x:31855, y:3999,|x:33788, y:2399,x:35779, y:2399,|x:33788, y:1999,x:35779, y:1999,|x:33788, y:1599,x:35779, y:1599,|x:2887, y:1599,x:4879, y:1599,|x:2887, y:1999,x:4879, y:1999,|x:2887, y:2399,x:4878, y:2399,|x:38020, y:1599,x:40011, y:1599,|x:38020, y:1999,x:40011, y:1999,|x:38020, y:2399,x:40011, y:2399,|x:38000, y:2693,x:38000, y:1302,|x:37600, y:2694,x:37600, y:1302,|x:37200, y:2694,x:37200, y:1303,|x:36800, y:2695,x:36800, y:1303,|x:36400, y:2695,x:36400, y:1303,|x:36000, y:2696,x:36000, y:1304,|x:6800, y:2696,x:6800, y:1307,|x:6400, y:2695,x:6400, y:1307,|x:6000, y:2695,x:6000, y:1307,|x:5600, y:2695,x:5600, y:1307,|x:5200, y:2694,x:5200, y:1307,|";
                var polygons      = CLPolygonsExtensions.CreateFromString(polygonString);
                var merged        = polygons.MergeColinearLineSegments(400, 100);

                var longMerges = merged.Where(p => p.PolygonLength() > 20000);
                Assert.AreEqual(0, longMerges.Count());
                Assert.AreEqual(polygons.Count(), merged.Count());
            }
        }
예제 #8
0
        public void TestBottomLayerAirGap()
        {
            // test the supports for a cube that is 1/2 width just under the main part
            {
                ConfigSettings config = new ConfigSettings();
                config.SupportInterfaceLayers      = 2;
                config.LayerThickness              = .5;
                config.SupportXYDistanceFromObject = .1;

                // 14      XXXXXXXXXX
                // 13      XXXXXXXXXX
                // 12      XXXXXXXXXX
                // 11      XXXXXXXXXX
                // 10      XXXXXXXXXX  <- at air gap height
                // 9                        <- interface layer
                // 8                        <- interface layer
                // 7            ^ - requires support
                // 6
                // 5                        <- at air gap height
                // 4  XXXXXXXXXXXXXXXXXXXX
                // 3  XXXXXXXXXXXXXXXXXXXX
                // 1  XXXXXXXXXXXXXXXXXXXX
                // 1  XXXXXXXXXXXXXXXXXXXX
                // 0  XXXXXXXXXXXXXXXXXXXX

                List <Polygons> partOutlines             = new List <Polygons>();
                List <Polygons> supportOutlines          = new List <Polygons>();
                Polygons        bottomCubeOutline        = CLPolygonsExtensions.CreateFromString("x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|");
                Polygons        bottomCubeOutlineResults = bottomCubeOutline.Offset(-200);
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(bottomCubeOutline);
                    supportOutlines.Add(new Polygons());
                }

                Polygons topCubeOutline = CLPolygonsExtensions.CreateFromString("x:2500, y:2500,x:7500, y:2500,x:7500, y:7500,x:2500, y:7500,|");
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(new Polygons());
                    supportOutlines.Add(topCubeOutline);
                }

                Polygons topCubeOutlineResults = topCubeOutline.Offset(-200);
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(topCubeOutline);
                    supportOutlines.Add(new Polygons());
                }

                var            outputs          = CreateLayerData(config, partOutlines, supportOutlines);
                ExtruderLayers layerData        = outputs.Item1;
                NewSupport     supportGenerator = outputs.Item2;

                // check the all part outlines
                {
                    List <int> polygonsCounts = new List <int> {
                        1, 1, 1, 1, 1,
                        0, 0, 0, 0, 0,
                        1, 1, 1, 1, 1,
                    };
                    List <int> polygon0Counts = new List <int> {
                        4, 4, 4, 4, 4,
                        0, 0, 0, 0, 0,
                        4, 4, 4, 4, 4,
                    };
                    List <Polygons> poly0Paths = new List <Polygons>()
                    {
                        bottomCubeOutlineResults, bottomCubeOutlineResults, bottomCubeOutlineResults, bottomCubeOutlineResults, bottomCubeOutlineResults,
                        null, null, null, null, null,
                        topCubeOutlineResults, topCubeOutlineResults, topCubeOutlineResults, topCubeOutlineResults, topCubeOutlineResults,
                    };
                    CheckLayers(supportGenerator._InsetPartOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                }

                {
                    Polygons expectedSupportOutlines = topCubeOutlineResults.Offset(200);
                    // check the air gapped bottom support outlines (only 5)
                    {
                        List <int> polygonsCounts = new List <int> {
                            0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <int> polygon0Counts = new List <int> {
                            0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <Polygons> poly0Paths = new List <Polygons>()
                        {
                            null, null, null, null, null, expectedSupportOutlines, null, null, null, null, null, null
                        };
                        CheckLayers(supportGenerator.AirGappedBottomOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                    }

                    // check the generated support outlines (only 6 and 7)
                    {
                        List <int> polygonsCounts = new List <int> {
                            0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <int> polygon0Counts = new List <int> {
                            0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <Polygons> poly0Paths = new List <Polygons>()
                        {
                            null, null, null, null, null, null, expectedSupportOutlines, expectedSupportOutlines, null, null, null, null
                        };
                        CheckLayers(supportGenerator.SparseSupportOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                    }

                    // check the interface support outlines (8 and 9)
                    {
                        List <int> polygonsCounts = new List <int> {
                            0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
                        };
                        List <int> polygon0Counts = new List <int> {
                            0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,
                        };
                        List <Polygons> poly0Paths = new List <Polygons>()
                        {
                            null, null, null, null, null, null, null, null, expectedSupportOutlines, expectedSupportOutlines, null, null, null, null, null,
                        };
                        CheckLayers(supportGenerator.InterfaceLayers, polygonsCounts, polygon0Counts, poly0Paths);
                    }
                }
            }
        }
예제 #9
0
        public void TestCorrectSupportLayer()
        {
            // test the supports for a simple cube in the air
            {
                ConfigSettings config = new ConfigSettings();
                config.LayerThickness = .5;
                config.SupportXYDistanceFromObject = 0;
                config.SupportInterfaceLayers      = 0;

                Polygons cubeOutline = CLPolygonsExtensions.CreateFromString("x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|");

                List <Polygons> partOutlines    = new List <Polygons>();
                List <Polygons> supportOutlines = new List <Polygons>();
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(new Polygons());
                    supportOutlines.Add(cubeOutline);
                }

                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(cubeOutline);
                    supportOutlines.Add(new Polygons());
                }

                var            outputs          = CreateLayerData(config, partOutlines, supportOutlines);
                ExtruderLayers layerData        = outputs.Item1;
                NewSupport     supportGenerator = outputs.Item2;

                Polygons cubeOutlineResults = CLPolygonsExtensions.CreateFromString("x:200, y:200,x:9800, y:200,x:9800, y:9800,x:200, y:9800,|");
                Polygons cubeInfillResults  = CLPolygonsExtensions.CreateFromString("x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|");

                // check the all part outlines
                {
                    List <int> polygonsCounts = new List <int> {
                        0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
                    };
                    List <int> polygon0Counts = new List <int> {
                        0, 0, 0, 0, 0, 4, 4, 4, 4, 4,
                    };
                    List <Polygons> poly0Paths = new List <Polygons>()
                    {
                        null, null, null, null, null, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults,
                    };
                    CheckLayers(supportGenerator._InsetPartOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                }

                // check the generated support outlines
                {
                    List <int> polygonsCounts = new List <int> {
                        1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
                    };
                    List <int> polygon0Counts = new List <int> {
                        4, 4, 4, 4, 4, 0, 0, 0, 0, 0,
                    };
                    List <Polygons> poly0Paths = new List <Polygons>()
                    {
                        cubeInfillResults, cubeInfillResults, cubeInfillResults, cubeInfillResults, cubeInfillResults, null, null, null, null, null
                    };
                    CheckLayers(supportGenerator.SparseSupportOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                }

                // check the interface support outlines
                {
                    List <int> polygonsCounts = new List <int> {
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    };
                    List <int> polygon0Counts = new List <int> {
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    };
                    List <Polygons> poly0Paths = new List <Polygons>()
                    {
                        null, null, null, null, null, null, null, null, null, null
                    };
                    CheckLayers(supportGenerator.InterfaceLayers, polygonsCounts, polygon0Counts, poly0Paths);
                }
            }

            // test the supports for a cube that is 1/2 width just under the main part
            {
                ConfigSettings config = new ConfigSettings();
                config.SupportInterfaceLayers      = 0;
                config.LayerThickness              = .5;
                config.SupportXYDistanceFromObject = .1;

                // 14 XXXXXXXXXXXXXXXXXXXX
                // 13 XXXXXXXXXXXXXXXXXXXX
                // 12 XXXXXXXXXXXXXXXXXXXX
                // 11 XXXXXXXXXXXXXXXXXXXX
                // 10 XXXXXXXXXXXXXXXXXXXX
                // 9  XXXXXXXXXX           <- interface layer
                // 8  XXXXXXXXXX           <- interface layer
                // 7  XXXXXXXXXX     ^ - requires support
                // 6  XXXXXXXXXX
                // 5  XXXXXXXXXX
                // 4             <- interface layer
                // 3             <- interface layer
                // 2      ^ - requires support
                // 1
                // 0

                Polygons halfCubeOutline = CLPolygonsExtensions.CreateFromString("x:0, y:0,x:5000, y:0,x:5000, y:10000,x:0, y:10000,|");
                Polygons cubeOutline     = CLPolygonsExtensions.CreateFromString("x:0, y:0,x:10000, y:0,x:10000, y:10000,x:0, y:10000,|");

                List <Polygons> supportOutlines = new List <Polygons>();
                List <Polygons> partOutlines    = new List <Polygons>();
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(new Polygons());
                    supportOutlines.Add(cubeOutline);
                }

                Polygons halfCubeOutlineResults = halfCubeOutline.Offset(-200);
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(halfCubeOutline);
                    supportOutlines.Add(cubeOutline);
                }

                Polygons cubeOutlineResults = cubeOutline.Offset(-200);
                for (int i = 0; i < 5; i++)
                {
                    partOutlines.Add(cubeOutline);
                }

                var            outputs          = CreateLayerData(config, partOutlines, supportOutlines);
                ExtruderLayers layerData        = outputs.Item1;
                NewSupport     supportGenerator = outputs.Item2;

                // check the all part outlines
                {
                    List <int> polygonsCounts = new List <int> {
                        0, 0, 0, 0, 0,
                        1, 1, 1, 1, 1,
                        1, 1, 1, 1, 1,
                    };
                    List <int> polygon0Counts = new List <int> {
                        0, 0, 0, 0, 0,
                        4, 4, 4, 4, 4,
                        4, 4, 4, 4, 4,
                    };
                    List <Polygons> poly0Paths = new List <Polygons>()
                    {
                        null, null, null, null, null,
                        halfCubeOutlineResults, halfCubeOutlineResults, halfCubeOutlineResults, halfCubeOutlineResults, halfCubeOutlineResults,
                        cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults,
                    };
                    CheckLayers(supportGenerator._InsetPartOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                }

                Polygons layer9Support = CLPolygonsExtensions.CreateFromString("x:5000, y:200,x:9800, y:200,x:9800, y:9800,x:5000, y:9800,|");

                if (false)
                {
                    // check the generated support outlines
                    {
                        List <int> polygonsCounts = new List <int> {
                            1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <int> polygon0Counts = new List <int> {
                            4, 4, 4, 4, 4, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <Polygons> poly0Paths = new List <Polygons>()
                        {
                            cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, cubeOutlineResults, null, null, null, null, null
                        };
                        CheckLayers(supportGenerator.SparseSupportOutlines, polygonsCounts, polygon0Counts, poly0Paths);
                    }

                    // check the interface support outlines
                    {
                        List <int> polygonsCounts = new List <int> {
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <int> polygon0Counts = new List <int> {
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        };
                        List <Polygons> poly0Paths = new List <Polygons>()
                        {
                            null, null, null, null, null, null, null, null, null, null
                        };
                        CheckLayers(supportGenerator.InterfaceLayers, polygonsCounts, polygon0Counts, poly0Paths);
                    }
                }
            }
        }