Exemple #1
0
        public void CorrectSeamPlacement()
        {
            // coincident points return 0 angle
            {
                IntPoint p1 = new IntPoint(10, 0);
                IntPoint p2 = new IntPoint(0, 0);
                IntPoint p3 = new IntPoint(0, 0);
                Assert.IsTrue(IslandOrderOptimizer.GetTurnAmount(p1, p2, p3) == 0);
            }

            // no turn returns a 0 angle
            {
                IntPoint p1 = new IntPoint(10, 0);
                IntPoint p2 = new IntPoint(0, 0);
                IntPoint p3 = new IntPoint(-10, 0);
                Assert.IsTrue(IslandOrderOptimizer.GetTurnAmount(p1, p2, p3) == 0);
            }

            // 90 turn works
            {
                IntPoint p1 = new IntPoint(0, 0);
                IntPoint p2 = new IntPoint(10, 0);
                IntPoint p3 = new IntPoint(10, 10);
                Assert.AreEqual(IslandOrderOptimizer.GetTurnAmount(p1, p2, p3), Math.PI / 2, .001);

                IntPoint p4 = new IntPoint(0, 10);
                IntPoint p5 = new IntPoint(0, 0);
                IntPoint p6 = new IntPoint(10, 0);
                Assert.AreEqual(IslandOrderOptimizer.GetTurnAmount(p4, p5, p6), Math.PI / 2, .001);
            }

            // -90 turn works
            {
                IntPoint p1 = new IntPoint(0, 0);
                IntPoint p2 = new IntPoint(10, 0);
                IntPoint p3 = new IntPoint(10, -10);
                Assert.AreEqual(IslandOrderOptimizer.GetTurnAmount(p1, p2, p3), -Math.PI / 2, .001);
            }

            // 45 turn works
            {
                IntPoint p1 = new IntPoint(0, 0);
                IntPoint p2 = new IntPoint(10, 0);
                IntPoint p3 = new IntPoint(15, 5);
                Assert.AreEqual(Math.PI / 4, IslandOrderOptimizer.GetTurnAmount(p1, p2, p3), .001);

                IntPoint p4 = new IntPoint(0, 0);
                IntPoint p5 = new IntPoint(-10, 0);
                IntPoint p6 = new IntPoint(-15, -5);
                Assert.AreEqual(Math.PI / 4, IslandOrderOptimizer.GetTurnAmount(p4, p5, p6), .001);
            }

            // -45 turn works
            {
                IntPoint p1 = new IntPoint(0, 0);
                IntPoint p2 = new IntPoint(10, 0);
                IntPoint p3 = new IntPoint(15, -5);
                Assert.AreEqual(-Math.PI / 4, IslandOrderOptimizer.GetTurnAmount(p1, p2, p3), .001);
            }

            // find the right point wound ccw
            {
                // 4________3
                // |       /
                // |      /2
                // |      \
                // |0______\1
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(70, 50), new IntPoint(100, 100), new IntPoint(0, 100)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 2);
            }

            // find the right point wound ccw
            {
                // 3________2
                // |       |
                // |       |
                // |       |
                // |0______|1
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(100, 100), new IntPoint(0, 100)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 3);
            }

            // find the right point wound ccw
            {
                // 1________0
                // |       |
                // |       |
                // |       |
                // |2______|3
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(0, 0), new IntPoint(100, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 1);
            }

            // find the right point wound cw
            {
                // 1________2
                // |       |
                // |       |
                // |       |
                // |0______|3
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(100, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 1);
            }

            // find the right point wound cw
            {
                // 0________1
                // |       |
                // |       |
                // |       |
                // |3______|2
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(100, 0), new IntPoint(0, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 0);
            }

            // find the right point wound ccw
            {
                // 4________3
                // |       /
                // |      /2
                // |      \
                // |0______\1
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 0), new IntPoint(1000, 0), new IntPoint(900, 500), new IntPoint(1000, 1000), new IntPoint(0, 1000)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 2);
            }

            // ccw
            {
                // 2________1
                // |       /
                // |      /0
                // |      \
                // |3______\4
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(0, 0), new IntPoint(100, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 0);
            }

            // ccw
            {
                // 2________1
                //  \      /
                //   \3   /0
                //   /    \
                //  /4_____\5
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100), new IntPoint(10, 50), new IntPoint(0, 0), new IntPoint(100, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 3);
            }

            // ccw
            {
                // 5________4
                //  \      /
                //   \0   /3
                //   /    \
                //  /1_____\2
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(10, 50), new IntPoint(0, 0), new IntPoint(100, 0), new IntPoint(90, 50), new IntPoint(100, 100), new IntPoint(0, 100),
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 0);
            }

            // find the right point wound cw (inside hole loops)
            {
                // 1________2
                // |       /
                // |      /3
                // |      \
                // |0______\4
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50), new IntPoint(100, 0)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 2);
            }

            // find the right point wound cw
            {
                // 2________3
                // |       /
                // |      /4
                // |      \
                // |1______\0
                List <IntPoint> testPoints = new List <IntPoint> {
                    new IntPoint(100, 0), new IntPoint(0, 0), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 3);
            }

            // cw
            {
                // 4________5
                //  \      /
                //   \3   /0
                //   /    \
                //  /2_____\1
                List <IntPoint> testPoints = new List <IntPoint>
                {
                    new IntPoint(90, 50), new IntPoint(100, 0), new IntPoint(0, 0), new IntPoint(10, 50), new IntPoint(0, 100), new IntPoint(100, 100)
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 4);
            }

            // cw
            {
                // 1________2
                //  \      /
                //   \0   /3
                //   /    \
                //  /5_____\4
                List <IntPoint> testPoints = new List <IntPoint>
                {
                    new IntPoint(10, 50), new IntPoint(0, 100), new IntPoint(100, 100), new IntPoint(90, 50), new IntPoint(100, 0), new IntPoint(0, 0),
                };
                int bestPoint = IslandOrderOptimizer.GetBestEdgeIndex(testPoints);
                Assert.IsTrue(bestPoint == 1);
            }
        }