public Range(Position startPosition, int width, int height) { upperLeft = startPosition; lowerRight = new Position(startPosition.X + width, startPosition.Y + height); toString = String.Empty; UpdateToString(); }
public Range(Position upperLeft, Position lowerRight) { this.upperLeft = upperLeft; this.lowerRight = lowerRight; toString = String.Empty; UpdateToString(); }
public static double Distance(Position a, Position b) { return Math.Sqrt(Math.Pow(a.x - b.x, 2) + Math.Pow(a.y - b.y, 2)); }
public bool Contains(Position position) { return position.X >= upperLeft.X && position.Y < lowerRight.Y && position.X < lowerRight.X && position.Y >= upperLeft.Y; }
public static Position Clamp(Position value, Position min, Position max) { Position newValue = value; if (newValue.x > max.x) newValue.x = max.x; else if (newValue.x < min.x) newValue.x = min.x; if (newValue.y > max.y) newValue.y = max.y; else if (newValue.y < min.y) newValue.y = min.y; return newValue; }