コード例 #1
0
        public void ClosestBoundaryPointTest()
        {
            int Constrain(int location, int lowerBound, int upperBound)
            {
                if (location < lowerBound)
                {
                    return(lowerBound);
                }
                else if (location < upperBound)
                {
                    return(location);
                }
                else
                {
                    return(upperBound - 1);
                }
            }

            var rect = new Rectangle(100, 200, 300, 400);

            for (var x = rect.Left - 200; x < rect.Right + 200; x++)
            {
                var xExpected = Constrain(x, rect.Left, rect.Right);

                for (var y = rect.Top - 200; y < rect.Bottom + 200; y++)
                {
                    var p         = new Point(x, y);
                    var actual    = GeometryUtil.ClosestBoundaryPoint(rect, p);
                    var yExpected = Constrain(y, rect.Top, rect.Bottom);

                    Assert.AreEqual(new Point(xExpected, yExpected), actual, $"{x}, {y}");
                }
            }
        }