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


C# Vector2.Count方法代码示例

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


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

示例1: ResetBoundingRect

        // Get ready to start.
        private void ResetBoundingRect(Vector2[] vertices)
        {
            _numPoints = vertices.Count();
            // Find the minimum and maximum points
            // in all four directions.
            double minx = vertices[0].X;
            double maxx = minx;
            double miny = vertices[0].Y;
            double maxy = miny;
            double minxi = 0;
            double maxxi = 0;
            double minyi = 0;
            double maxyi = 0;
            for (int i = 1; i < _numPoints; i++)
            {
                if (minx > vertices[i].X)
                {
                    minx = vertices[i].X;
                    minxi = i;
                }
                if (maxx < vertices[i].X)
                {
                    maxx = vertices[i].X;
                    maxxi = i;
                }
                if (miny > vertices[i].Y)
                {
                    miny = vertices[i].Y;
                    minyi = i;
                }
                if (maxy < vertices[i].Y)
                {
                    maxy = vertices[i].Y;
                    maxyi = i;
                }
            }
            _controlPoints[0] = (int)minxi;
            _controlPoints[1] = (int)maxyi;
            _controlPoints[2] = (int)maxxi;
            _controlPoints[3] = (int)minyi;
            _currentControlPoint = -1;
            // Reset the current and best bounding rectangle.
            _currentRectangle = new Vector2[]
            {
            new Vector2(minx, miny),
            new Vector2(maxx, miny),
            new Vector2(maxx, maxy),
            new Vector2(minx, maxy),
            };

            var currentArea = (maxx - minx) * (maxy - miny);
            _bestRectangle = _currentRectangle;
            _bestArea = currentArea;
            // So far we have not checked any edges.
            _edgeChecked = new bool[_numPoints];
            for (int i = 0; i < _numPoints; i++)
            {
                _edgeChecked[i] = false;
            }
        }
开发者ID:ElderByte-,项目名称:Archimedes.Geometry,代码行数:61,代码来源:PolygonSmallestBoundingBoxAlgorythm.cs

示例2: Rectangle2

        public Rectangle2(Vector2[] vertices)
        {
            if (vertices == null) throw new ArgumentNullException("vertices");
            if (vertices.Count() != 4) throw new ArgumentException("You must submit 4 vertices!");

            if (!IsRectangle(vertices))
            {
                throw new ArgumentOutOfRangeException("vertices", "The given vertices must form a rectangle in 2D space!");
            }
            
            _rect = new Polygon2(vertices);
        }
开发者ID:ElderByte-,项目名称:Archimedes.Geometry,代码行数:12,代码来源:Rectangle2.cs

示例3: IsRectangle

        /// <summary>
        /// Checks if the given 4 vertices form a rectangle
        /// </summary>
        /// <param name="vertices"></param>
        /// <returns></returns>
        public static bool IsRectangle(Vector2[] vertices, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            if (vertices == null) throw new ArgumentNullException("vertices");
            if (vertices.Count() != 4) throw new ArgumentException("You must submit 4 vertices!");

            var topLine = new LineSegment2(vertices[0], vertices[1]).ToVector();
            var rightLine = new LineSegment2(vertices[1], vertices[2]).ToVector();
            var bottomLine = new LineSegment2(vertices[2], vertices[3]).ToVector();
            var leftLine = new LineSegment2(vertices[3], vertices[0]).ToVector();

            // Check that two lines have equal length

            if (Math.Abs(topLine.Length - bottomLine.Length) < tolerance
                && Math.Abs(rightLine.Length - leftLine.Length) < tolerance)
            {
                // Now ensure that the lines are orthogonal on each other
                bool isRect = topLine.IsPerpendicularTo(rightLine, tolerance);
                isRect &= rightLine.IsPerpendicularTo(bottomLine, tolerance);
                isRect &= bottomLine.IsPerpendicularTo(leftLine, tolerance);

                return isRect;
            }

            return false;
        }
开发者ID:ElderByte-,项目名称:Archimedes.Geometry,代码行数:30,代码来源:Rectangle2.cs


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