當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。