using System;
namespace PdfOxide.Geometry
{
public struct Rect : IEquatable<Rect>
{
public float X { get; }
public float Y { get; }
public float Width { get; }
public float Height { get; }
public Rect(float x, float y, float width, float height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public float Right => X + Width;
public float Bottom => Y + Height;
public float Area => Width * Height;
public bool Contains(Point point) =>
point.X >= X && point.X <= Right &&
point.Y >= Y && point.Y <= Bottom;
public bool Intersects(Rect other) =>
!(Right < other.X || X > other.Right ||
Bottom < other.Y || Y > other.Bottom);
public override bool Equals(object? obj) => obj is Rect rect && Equals(rect);
public bool Equals(Rect other) =>
X == other.X && Y == other.Y && Width == other.Width && Height == other.Height;
public override int GetHashCode()
{
unchecked
{
int hash = 17;
hash = hash * 31 + X.GetHashCode();
hash = hash * 31 + Y.GetHashCode();
hash = hash * 31 + Width.GetHashCode();
hash = hash * 31 + Height.GetHashCode();
return hash;
}
}
public override string ToString() =>
$"Rect(X={X}, Y={Y}, Width={Width}, Height={Height})";
public static bool operator ==(Rect left, Rect right) => left.Equals(right);
public static bool operator !=(Rect left, Rect right) => !left.Equals(right);
}
}