/// <summary> /// rectから0より小さい領域を切り取ったRectangleを返す. /// </summary> public static Rectangle EnsureNoNegative(Rectangle rect) { var size = new Size( rect.Left < 0? rect.Width + rect.Left: rect.Width, rect.Top < 0? rect.Height + rect.Top: rect.Height ); return(new Rectangle( PointUtil.EnsureNotNegative(rect.Location), size )); }
public void TestMiddlePoint() { Assert.AreEqual( new Point(10, 10), PointUtil.MiddlePoint(new Point(0, 0), new Point(20, 20)) ); Assert.AreEqual( new Point(10, 10), PointUtil.MiddlePoint(new Point(20, 20), new Point(0, 0)) ); Assert.AreEqual( new Point(10, 10), PointUtil.MiddlePoint(new Point(20, 0), new Point(0, 20)) ); Assert.AreEqual( new Point(10, 10), PointUtil.MiddlePoint(new Point(0, 20), new Point(20, 0)) ); }
public void TestScaleWithCircumscribeRect() { var pts = new Point[] { new Point(10, 10), new Point(20, 10), new Point(20, 20), new Point(10, 20), }; PointUtil.ScaleWithCircumscribeRect(pts, new SizeF(0.5f, 2)); Assert.AreEqual(new Point(10, 10), pts[0]); Assert.AreEqual(new Point(15, 10), pts[1]); Assert.AreEqual(new Point(15, 30), pts[2]); Assert.AreEqual(new Point(10, 30), pts[3]); PointUtil.ScaleWithCircumscribeRect(pts, new SizeF(2, 0.5f)); Assert.AreEqual(new Point(10, 10), pts[0]); Assert.AreEqual(new Point(20, 10), pts[1]); Assert.AreEqual(new Point(20, 20), pts[2]); Assert.AreEqual(new Point(10, 20), pts[3]); }
/// <summary> /// rectの中心点に対してptがどの方向にあるかを返す. /// 答えは Left や Up や None のように重なりがない。 /// </summary> public static Directions GetDirectionStraightlyFromCenter(Rectangle rect, Point pt) { return(PointUtil.GetDirectionStraightly(GetCenter(rect), pt)); }