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


C# Coordinate.CompareTo方法代码示例

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


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

示例1: Intersects

        /// <summary>
        /// Tests whether the query rectangle intersects a given line segment.
        /// </summary>
        /// <param name="p0">The first endpoint of the segment</param>
        /// <param name="p1">The second endpoint of the segment</param>
        /// <returns><c>true</c> if the rectangle intersects the segment</returns>
        public bool Intersects(Coordinate p0, Coordinate p1)
        {
            // TODO: confirm that checking envelopes first is faster

            /**
             * If the segment envelope is disjoint from the
             * rectangle envelope, there is no intersection
             */
            var segEnv = new Envelope(p0, p1);
            if (!_rectEnv.Intersects(segEnv))
                return false;

            /**
             * If either segment endpoint lies in the rectangle,
             * there is an intersection.
             */
            if (_rectEnv.Intersects(p0)) return true;
            if (_rectEnv.Intersects(p1)) return true;

            /**
             * Normalize segment.
             * This makes p0 less than p1,
             * so that the segment runs to the right,
             * or vertically upwards.
             */
            if (p0.CompareTo(p1) > 0)
            {
                var tmp = p0;
                p0 = p1;
                p1 = tmp;
            }
            /**
             * Compute angle of segment.
             * Since the segment is normalized to run left to right,
             * it is sufficient to simply test the Y ordinate.
             * "Upwards" means relative to the left end of the segment.
             */
            var isSegUpwards = p1.Y > p0.Y;

            /**
             * Since we now know that neither segment endpoint
             * lies in the rectangle, there are two possible 
             * situations:
             * 1) the segment is disjoint to the rectangle
             * 2) the segment crosses the rectangle completely.
             * 
             * In the case of a crossing, the segment must intersect 
             * a diagonal of the rectangle.
             * 
             * To distinguish these two cases, it is sufficient 
             * to test intersection with 
             * a single diagonal of the rectangle,
             * namely the one with slope "opposite" to the slope
             * of the segment.
             * (Note that if the segment is axis-parallel,
             * it must intersect both diagonals, so this is
             * still sufficient.)  
             */
            if (isSegUpwards)
            {
                _li.ComputeIntersection(p0, p1, _diagDown0, _diagDown1);
            }
            else
            {
                _li.ComputeIntersection(p0, p1, _diagUp0, _diagUp1);
            }
            if (_li.HasIntersection)
                return true;
            return false;


        }
开发者ID:Walt-D-Cat,项目名称:NetTopologySuite,代码行数:78,代码来源:RectangleLineIntersector.cs


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