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


C# Polygon.IsConvexPolygon方法代码示例

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


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

示例1: BuildNode

        private static RooBSPItem BuildNode(List<RooWall> Walls, Polygon Polygon, int Sector)
        {
            if (Polygon.Count == 0 || (Walls.Count == 0 && Sector == 0))
                return null;

            Polygon.RemoveZeroEdges();

            if (!Polygon.IsConvexPolygon())
            {
                if (FoundNonConvexPolygon != null)
                    FoundNonConvexPolygon(null, new PolygonEventArgs(Polygon));

                //return null; // WTF ?
            }

            // No walls left ==> leaf
            if (Walls.Count == 0)
            {
                RooSubSector leaf = new RooSubSector(RooFile.VERSIONHIGHRESGRID, (ushort)Sector, Polygon);

                // fills in sector reference
                leaf.ResolveIndices(room);
                
                return leaf;
            }

            // get best splitter of remaining walls
            RooWall splitter = ChooseSplitter(Walls);

            if (splitter == null)
                return null; // WTF ?

            // split up walls into right/left
            Tuple<List<RooWall>, List<RooWall>> splitWalls = 
                SplitWalls(Walls, splitter);
            
            // split up polygon into right/left
            Tuple<Polygon, Polygon> splitPolygons = 
                Polygon.SplitConvexPolygon(splitter.P1, splitter.P2);

            Real a, b, c;
            GetLineEquation2DCoefficients(splitter.P1, splitter.P2,
                out a, out b, out c);

            // create new splitter node
            RooPartitionLine node = new RooPartitionLine(RooFile.VERSIONHIGHRESGRID,
                Polygon.GetBoundingBox(), a, b, c, 0, 0, (ushort)splitter.Num);

            // fills in wall reference
            node.Wall = splitter;

            // recursively descend to children
            node.LeftChild = BuildNode(splitWalls.Item1, splitPolygons.Item1, splitter.LeftSectorNum);
            node.RightChild  = BuildNode(splitWalls.Item2, splitPolygons.Item2, splitter.RightSectorNum);

            return node;
        }
开发者ID:GJiin,项目名称:meridian59-dotnet,代码行数:57,代码来源:BSPBuilder.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


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