using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Island.StandardLib.Math { /// /// 表示一个二维矩形 /// public class Rect2 { /// /// 矩形的最小X坐标 /// public float X { get; set; } /// /// 矩形的最小Y坐标 /// public float Y { get; set; } /// /// 矩形的宽度 /// public float SizeX { get; set; } /// /// 矩形的高度 /// public float SizeY { get; set; } public Rect2(Vector2 start, Vector2 size) { X = start.X; Y = start.Y; SizeX = size.X; SizeY = size.Y; } public Rect2(float x, float y, float sizeX, float sizeY) { X = x; Y = y; SizeX = sizeX; SizeY = sizeY; } /// /// 选定点是否在此矩形内 /// /// 选定的点 /// public bool Contains(Vector2 point) { return X < point.X && X + SizeX > point.X && Y < point.Y && Y + SizeY > point.Y; } /// /// 获取矩形的中间点 /// /// public Vector2 GetNormalVector() { return new Vector2(X + (SizeX / 2), Y + (SizeY / 2)); } } }