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


C# Rectangle.RelateXRange方法代码示例

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


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

示例1: RelateRectanglePhase2

        /// <summary>
        /// Called after bounding box is intersected.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="bboxSect">INTERSECTS or CONTAINS from enclosingBox's intersection</param>
        /// <returns>DISJOINT, CONTAINS, or INTERSECTS (not WITHIN)</returns>
        protected override SpatialRelation RelateRectanglePhase2(Rectangle r, SpatialRelation bboxSect)
        {
            //Rectangle wraps around the world longitudinally creating a solid band; there are no corners to test intersection
            if (r.GetWidth() == 360)
            {
                return SpatialRelation.INTERSECTS;
            }

            if (inverseCircle != null)
            {
                return inverseCircle.Relate(r).Inverse();
            }

            //if a pole is wrapped, we have a separate algorithm
            if (enclosingBox.GetWidth() == 360)
            {
                return RelateRectangleCircleWrapsPole(r, ctx);
            }

            //This is an optimization path for when there are no dateline or pole issues.
            if (!enclosingBox.GetCrossesDateLine() && !r.GetCrossesDateLine())
            {
                return base.RelateRectanglePhase2(r, bboxSect);
            }

            //do quick check to see if all corners are within this circle for CONTAINS
            int cornersIntersect = NumCornersIntersect(r);
            if (cornersIntersect == 4)
            {
                //ensure r's x axis is within c's.  If it doesn't, r sneaks around the globe to touch the other side (intersect).
                SpatialRelation xIntersect = r.RelateXRange(enclosingBox.GetMinX(), enclosingBox.GetMaxX());
                if (xIntersect == SpatialRelation.WITHIN)
                    return SpatialRelation.CONTAINS;
                return SpatialRelation.INTERSECTS;
            }

            //INTERSECT or DISJOINT ?
            if (cornersIntersect > 0)
                return SpatialRelation.INTERSECTS;

            //Now we check if one of the axis of the circle intersect with r.  If so we have
            // intersection.

            /* x axis intersects  */
            if (r.RelateYRange(GetYAxis(), GetYAxis()).Intersects() // at y vertical
                  && r.RelateXRange(enclosingBox.GetMinX(), enclosingBox.GetMaxX()).Intersects())
                return SpatialRelation.INTERSECTS;

            /* y axis intersects */
            if (r.RelateXRange(GetXAxis(), GetXAxis()).Intersects())
            { // at x horizontal
                double yTop = GetCenter().GetY() + radiusDEG;
                Debug.Assert(yTop <= 90);
                double yBot = GetCenter().GetY() - radiusDEG;
                Debug.Assert(yBot >= -90);
                if (r.RelateYRange(yBot, yTop).Intersects())//back bottom
                    return SpatialRelation.INTERSECTS;
            }

            return SpatialRelation.DISJOINT;
        }
开发者ID:h0st1le,项目名称:Spatial4n,代码行数:67,代码来源:GeoCircle.cs

示例2: RelateRectangleCircleWrapsPole

        private SpatialRelation RelateRectangleCircleWrapsPole(Rectangle r, SpatialContext ctx)
        {
            //This method handles the case where the circle wraps ONE pole, but not both.  For both,
            // there is the inverseCircle case handled before now.  The only exception is for the case where
            // the circle covers the entire globe, and we'll check that first.
            if (radiusDEG == 180)//whole globe
                return SpatialRelation.CONTAINS;

            //Check if r is within the pole wrap region:
            double yTop = GetCenter().GetY() + radiusDEG;
            if (yTop > 90)
            {
                double yTopOverlap = yTop - 90;
                Debug.Assert(yTopOverlap <= 90, "yTopOverlap: " + yTopOverlap);
                if (r.GetMinY() >= 90 - yTopOverlap)
                    return SpatialRelation.CONTAINS;
            }
            else
            {
                double yBot = point.GetY() - radiusDEG;
                if (yBot < -90)
                {
                    double yBotOverlap = -90 - yBot;
                    Debug.Assert(yBotOverlap <= 90);
                    if (r.GetMaxY() <= -90 + yBotOverlap)
                        return SpatialRelation.CONTAINS;
                }
                else
                {
                    //This point is probably not reachable ??
                    Debug.Assert(yTop == 90 || yBot == -90);//we simply touch a pole
                    //continue
                }
            }

            //If there are no corners to check intersection because r wraps completely...
            if (r.GetWidth() == 360)
                return SpatialRelation.INTERSECTS;

            //Check corners:
            int cornersIntersect = NumCornersIntersect(r);
            // (It might be possible to reduce contains() calls within nCI() to exactly two, but this intersection
            //  code is complicated enough as it is.)
            double frontX = GetCenter().GetX();
            if (cornersIntersect == 4)
            {//all
                double backX = frontX <= 0 ? frontX + 180 : frontX - 180;
                if (r.RelateXRange(backX, backX).Intersects())
                    return SpatialRelation.INTERSECTS;
                else
                    return SpatialRelation.CONTAINS;
            }
            else if (cornersIntersect == 0)
            {//none
                if (r.RelateXRange(frontX, frontX).Intersects())
                    return SpatialRelation.INTERSECTS;
                else
                    return SpatialRelation.DISJOINT;
            }
            else//partial
                return SpatialRelation.INTERSECTS;
        }
开发者ID:h0st1le,项目名称:Spatial4n,代码行数:62,代码来源:GeoCircle.cs


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