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


C# Point.SquareDistance方法代码示例

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


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

示例1: CheckXYInBoxBounds

        internal bool CheckXYInBoxBounds(int boxnum, Point p)
        {
            // Since this method is called by many other methods that take params
            // from e.g. script opcodes, but do not validate the boxnum, we
            // make a check here to filter out invalid boxes.
            // See also bug #1599113.
            if (boxnum < 0 || boxnum == InvalidBox)
                return false;

            var box = GetBoxCoordinates(boxnum);

            // Quick check: If the x (resp. y) coordinate of the point is
            // strictly smaller (bigger) than the x (y) coordinates of all
            // corners of the quadrangle, then it certainly is *not* contained
            // inside the quadrangle.
            if (p.X < box.UpperLeft.X && p.X < box.UpperRight.X && p.X < box.LowerRight.X && p.X < box.LowerLeft.X)
                return false;

            if (p.X > box.UpperLeft.X && p.X > box.UpperRight.X && p.X > box.LowerRight.X && p.X > box.LowerLeft.X)
                return false;

            if (p.Y < box.UpperLeft.Y && p.Y < box.UpperRight.Y && p.Y < box.LowerRight.Y && p.Y < box.LowerLeft.Y)
                return false;

            if (p.Y > box.UpperLeft.Y && p.Y > box.UpperRight.Y && p.Y > box.LowerRight.Y && p.Y > box.LowerLeft.Y)
                return false;

            // Corner case: If the box is a simple line segment, we consider the
            // point to be contained "in" (or rather, lying on) the line if it
            // is very close to its projection to the line segment.
            if ((box.UpperLeft == box.UpperRight && box.LowerRight == box.LowerLeft) ||
                (box.UpperLeft == box.LowerLeft && box.UpperRight == box.LowerRight))
            {
                Point tmp;
                tmp = ScummMath.ClosestPtOnLine(box.UpperLeft, box.LowerRight, p);
                if (p.SquareDistance(tmp) <= 4)
                    return true;
            }

            // Finally, fall back to the classic algorithm to compute containment
            // in a convex polygon: For each (oriented) side of the polygon
            // (quadrangle in this case), compute whether p is "left" or "right"
            // from it.

            if (!ScummMath.CompareSlope(box.UpperLeft, box.UpperRight, p))
                return false;

            if (!ScummMath.CompareSlope(box.UpperRight, box.LowerRight, p))
                return false;

            if (!ScummMath.CompareSlope(box.LowerRight, box.LowerLeft, p))
                return false;

            if (!ScummMath.CompareSlope(box.LowerLeft, box.UpperLeft, p))
                return false;

            return true;
        }
开发者ID:scemino,项目名称:nscumm,代码行数:58,代码来源:ScummEngine_Box.cs

示例2: GetClosestPtOnBox

        public static uint GetClosestPtOnBox(BoxCoords box, Point pIn, out Point pOut)
        {
            Point tmp;
            uint dist;
            uint bestdist = 0xFFFFFF;
            pOut = new Point();

            tmp = ScummMath.ClosestPtOnLine(box.UpperLeft, box.UpperRight, pIn);
            dist = pIn.SquareDistance(tmp);
            if (dist < bestdist)
            {
                bestdist = dist;
                pOut = tmp;
            }

            tmp = ScummMath.ClosestPtOnLine(box.UpperRight, box.LowerRight, pIn);
            dist = pIn.SquareDistance(tmp);
            if (dist < bestdist)
            {
                bestdist = dist;
                pOut = tmp;
            }

            tmp = ScummMath.ClosestPtOnLine(box.LowerRight, box.LowerLeft, pIn);
            dist = pIn.SquareDistance(tmp);
            if (dist < bestdist)
            {
                bestdist = dist;
                pOut = tmp;
            }

            tmp = ScummMath.ClosestPtOnLine(box.LowerLeft, box.UpperLeft, pIn);
            dist = pIn.SquareDistance(tmp);
            if (dist < bestdist)
            {
                bestdist = dist;
                pOut = tmp;
            }

            return bestdist;
        }
开发者ID:scemino,项目名称:nscumm,代码行数:41,代码来源:ScummMath.cs


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