当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.Clear方法代码示例

本文整理汇总了C#中Polygon.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.Clear方法的具体用法?C# Polygon.Clear怎么用?C# Polygon.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon的用法示例。


在下文中一共展示了Polygon.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SplitConvexPolygon

        public void SplitConvexPolygon()
        {
            Polygon poly = new Polygon();
            Polygon expectedLeft = new Polygon();
            Polygon expectedRight = new Polygon();
            V2 p1, p2;

            Tuple<Polygon, Polygon> returned;
            
            // --- TEST ---
            // 4 points, valid clockwise rectangle ABCD
            // intersect nothing from south to north
            //                  |
            //   B----------C   |
            //   |          |   |
            //   |          |   |
            //   |          |   |
            //   A----------D   |
            //                  |
            p1 = new V2(20.5f, -15f);
            p2 = new V2(20.5f, 15);
            poly.Clear();
            expectedLeft.Clear();
            expectedRight.Clear();
            poly.Add(new V2(0.0f, 0.0f)); // A
            poly.Add(new V2(0.0f, 5.0f)); // B
            poly.Add(new V2(5.0f, 5.0f)); // C
            poly.Add(new V2(5.0f, 0.0f)); // D
            // right empty
            // left = old
            expectedLeft.Add(new V2(0.0f, 0.0f));
            expectedLeft.Add(new V2(0.0f, 5.0f));
            expectedLeft.Add(new V2(5.0f, 5.0f));
            expectedLeft.Add(new V2(5.0f, 0.0f));

            returned = poly.SplitConvexPolygon(p1, p2);

            Assert.AreEqual(returned.Item1.IsIdentical(expectedRight), true);
            Assert.AreEqual(returned.Item2.IsIdentical(expectedLeft), true);

            // --- TEST ---
            // 4 points, valid clockwise rectangle ABCD
            // intersect nothing from north to south
            //                  |
            //   B----------C   |
            //   |          |   |
            //   |          |   |
            //   |          |   |
            //   A----------D   |
            //                  |
            p1 = new V2(20.5f, 15f);
            p2 = new V2(20.5f, -15);
            poly.Clear();
            expectedLeft.Clear();
            expectedRight.Clear();
            poly.Add(new V2(0.0f, 0.0f)); // A
            poly.Add(new V2(0.0f, 5.0f)); // B
            poly.Add(new V2(5.0f, 5.0f)); // C
            poly.Add(new V2(5.0f, 0.0f)); // D
            // right = old
            expectedRight.Add(new V2(0.0f, 0.0f));
            expectedRight.Add(new V2(0.0f, 5.0f));
            expectedRight.Add(new V2(5.0f, 5.0f));
            expectedRight.Add(new V2(5.0f, 0.0f));
            // left empty

            returned = poly.SplitConvexPolygon(p1, p2);

            Assert.AreEqual(returned.Item1.IsIdentical(expectedRight), true);
            Assert.AreEqual(returned.Item2.IsIdentical(expectedLeft), true);

            // --- TEST ---
            // 4 points, valid clockwise rectangle ABCD
            // intersect edges BC, DA from south to north
            //        |
            //   B----I1----C
            //   |    |     |
            //   |    |     |
            //   |    |     |
            //   A----I2----D
            //        |
            p1 = new V2(2.5f, -10f);
            p2 = new V2(2.5f, 10);
            poly.Clear();
            expectedLeft.Clear();
            expectedRight.Clear();           
            poly.Add(new V2(0.0f, 0.0f)); // A
            poly.Add(new V2(0.0f, 5.0f)); // B
            poly.Add(new V2(5.0f, 5.0f)); // C
            poly.Add(new V2(5.0f, 0.0f)); // D
            expectedRight.Add(new V2(2.5f, 5.0f));
            expectedRight.Add(new V2(5.0f, 5.0f));
            expectedRight.Add(new V2(5.0f, 0.0f));
            expectedRight.Add(new V2(2.5f, 0.0f));
            expectedLeft.Add(new V2(2.5f, 0.0f));
            expectedLeft.Add(new V2(0.0f, 0.0f));
            expectedLeft.Add(new V2(0.0f, 5.0f));
            expectedLeft.Add(new V2(2.5f, 5.0f));

            returned = poly.SplitConvexPolygon(p1, p2);
//.........这里部分代码省略.........
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:101,代码来源:PolygonTest.cs

示例2: IsConvexPolygon

        public void IsConvexPolygon()
        {
            Polygon poly = new Polygon();

            bool expected;
            bool returned;

            // --- TEST ---
            // 3 points, valid triangle
            poly.Clear();
            poly.Add(new V2(10.0f, 10.0f));
            poly.Add(new V2(5.0f, 0.0f));
            poly.Add(new V2(10.0f, -10.0f));

            expected = true;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 4 points, valid rectangle
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(0.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 0.0f));

            expected = true;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 5 points, rectangle, but two points not of first three in on same coords
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(0.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 0.0f));
            poly.Add(new V2(5.0f, 0.0f));

            expected = true;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 4 points, no rectangle ordered, not convex
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(0.0f, 5.0f));
            poly.Add(new V2(5.0f, 0.0f));

            expected = false;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // n points, concave polygon
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(10.0f, 0.0f));
            poly.Add(new V2(10.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 10.0f));
            poly.Add(new V2(10.0f, 10.0f));
            poly.Add(new V2(10.0f, 15.0f));
            poly.Add(new V2(0.0f, 15.0f));

            expected = false;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 5 points, convex
            poly.Clear();
            poly.Add(new V2(2512.0f, 5490.0f));
            poly.Add(new V2(2304.0f, 5568.0f));
            poly.Add(new V2(2304.0f, 5376.0f));
            poly.Add(new V2(2304.0f, 5120.0f));
            poly.Add(new V2(2512.0f, 5120.0f));

            expected = true;
            returned = poly.IsConvexPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 6 points, convex
            poly.Clear();
            poly.Add(new V2(5376f, 6032f));
            poly.Add(new V2(5376f, 7936f));
            poly.Add(new V2(5376f, 8192f));
            poly.Add(new V2(5136f, 8192f));
            poly.Add(new V2(4752f, 6656f));
            poly.Add(new V2(4940.339f, 6467.661f));

//.........这里部分代码省略.........
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:101,代码来源:PolygonTest.cs

示例3: IsPolygon

        public void IsPolygon()
        {
            Polygon poly = new Polygon();

            bool expected;
            bool returned;

            // --- TEST ---
            // no points
            poly.Clear();

            expected = false;
            returned = poly.IsPolygon();
            
            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 1 point
            poly.Clear();
            poly.Add(new V2(35.0f, 2.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 2 points
            poly.Clear();
            poly.Add(new V2(35.0f, 2.0f));
            poly.Add(new V2(365.0f, 23.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points all equal
            poly.Clear();
            poly.Add(new V2(35.0f, 2.0f));
            poly.Add(new V2(35.0f, 2.0f));
            poly.Add(new V2(35.0f, 2.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points, 1&3 equal
            poly.Clear();
            poly.Add(new V2(35.0f, 2.0f));
            poly.Add(new V2(3.0f, 6.0f));
            poly.Add(new V2(35.0f, 2.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points, 1&2 equal
            poly.Clear();
            poly.Add(new V2(3.0f, 6.0f));
            poly.Add(new V2(3.0f, 6.0f));
            poly.Add(new V2(35.0f, 2.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points, 2&3 equal
            poly.Clear();
            poly.Add(new V2(35.0f, 2.0f));
            poly.Add(new V2(3.0f, 6.0f));
            poly.Add(new V2(3.0f, 6.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points on same line
            poly.Clear();
            poly.Add(new V2(5.0f, 7.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 10.0f));

            expected = false;
            returned = poly.IsPolygon();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 3 points, valid triangle
            poly.Clear();
//.........这里部分代码省略.........
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:101,代码来源:PolygonTest.cs

示例4: RemoveZeroEdges

        public void RemoveZeroEdges()
        {
            Polygon poly = new Polygon();

            int expected;
            int returned;

            // --- TEST ---
            // 5 points, rectangle, but two points not of first three in on same coords
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(0.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 0.0f));
            poly.Add(new V2(5.0f, 0.0f));

            expected = 1;
            returned = poly.RemoveZeroEdges();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // 5 points, rectangle, but two points not of first three in on same coords
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(0.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 0.0f));
            poly.Add(new V2(5.0f, 0.0f));

            expected = 1;
            returned = poly.RemoveZeroEdges();

            Assert.AreEqual(expected, returned);

            // --- TEST ---
            // n points, concave polygon
            poly.Clear();
            poly.Add(new V2(0.0f, 0.0f));
            poly.Add(new V2(10.0f, 0.0f));
            poly.Add(new V2(10.0f, 5.0f));
            poly.Add(new V2(5.0f, 5.0f));
            poly.Add(new V2(5.0f, 10.0f));
            poly.Add(new V2(10.0f, 10.0f));
            poly.Add(new V2(10.0f, 15.0f));
            poly.Add(new V2(0.0f, 15.0f));

            expected = 0;
            returned = poly.RemoveZeroEdges();

            Assert.AreEqual(expected, returned);
        }
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:52,代码来源:PolygonTest.cs


注:本文中的Polygon.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。