You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
7.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeoSigmaDrawLib
{
/// <summary>
/// Rect 类这个是屏幕坐标系bottom 比 top 要大
/// </summary>
[Serializable]
public struct RectangleD
{
public static readonly RectangleD Empty;
private double x;
private double y;
private double width;
private double height;
[Browsable(false)]
public PointD Location
{
get
{
return new PointD(X, Y);
}
set
{
X = value.X;
Y = value.Y;
}
}
[Browsable(false)]
public SizeD Size
{
get
{
return new SizeD(Width, Height);
}
set
{
Width = value.Width;
Height = value.Height;
}
}
public double X
{
get
{
return x;
}
set
{
x = value;
}
}
public double Y
{
get
{
return y;
}
set
{
y = value;
}
}
public double Width
{
get
{
return width;
}
set
{
width = value;
}
}
public double Height
{
get
{
return height;
}
set
{
height = value;
}
}
[Browsable(false)]
public double Left => X;
[Browsable(false)]
public double Top => Y;
[Browsable(false)]
public double Right => X + Width;
[Browsable(false)]
public double Bottom => Y + Height;
[Browsable(false)]
public bool IsEmpty
{
get
{
if (!(Width <= 0f))
{
return Height <= 0f;
}
return true;
}
}
public RectangleD(double x, double y, double width, double height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public RectangleD(PointD location, SizeD size)
{
x = location.X;
y = location.Y;
width = size.Width;
height = size.Height;
}
public static RectangleD FromLTRB(double left, double top, double right, double bottom)
{
return new RectangleD(left, top, right - left, bottom - top);
}
public override bool Equals(object obj)
{
if (!(obj is RectangleD))
{
return false;
}
RectangleD rectangleD = (RectangleD)obj;
if (rectangleD.X == X && rectangleD.Y == Y && rectangleD.Width == Width)
{
return rectangleD.Height == Height;
}
return false;
}
public static bool operator ==(RectangleD left, RectangleD right)
{
if (left.X == right.X && left.Y == right.Y && left.Width == right.Width)
{
return left.Height == right.Height;
}
return false;
}
public static bool operator !=(RectangleD left, RectangleD right)
{
return !(left == right);
}
public bool Contains(double x, double y)
{
if (X <= x && x < X + Width && Y <= y)
{
return y < Y + Height;
}
return false;
}
public bool Contains(PointD pt)
{
return Contains(pt.X, pt.Y);
}
public bool Contains(RectangleD rect)
{
if (X <= rect.X && rect.X + rect.Width <= X + Width && Y <= rect.Y)
{
return rect.Y + rect.Height <= Y + Height;
}
return false;
}
public override int GetHashCode()
{
return (int)((uint)X ^ (((uint)Y << 13) | ((uint)Y >> 19)) ^ (((uint)Width << 26) | ((uint)Width >> 6)) ^ (((uint)Height << 7) | ((uint)Height >> 25)));
}
public void Inflate(double x, double y)
{
X -= x;
Y -= y;
Width += 2f * x;
Height += 2f * y;
}
public void Inflate(SizeD size)
{
Inflate(size.Width, size.Height);
}
public static RectangleD Inflate(RectangleD rect, float x, float y)
{
RectangleD result = rect;
result.Inflate(x, y);
return result;
}
public void Intersect(RectangleD rect)
{
RectangleD rectangleF = Intersect(rect, this);
X = rectangleF.X;
Y = rectangleF.Y;
Width = rectangleF.Width;
Height = rectangleF.Height;
}
public static RectangleD Intersect(RectangleD a, RectangleD b)
{
double num = Math.Max(a.X, b.X);
double num2 = Math.Min(a.X + a.Width, b.X + b.Width);
double num3 = Math.Max(a.Y, b.Y);
double num4 = Math.Min(a.Y + a.Height, b.Y + b.Height);
if (num2 >= num && num4 >= num3)
{
return new RectangleD(num, num3, num2 - num, num4 - num3);
}
return Empty;
}
public bool IntersectsWith(RectangleD rect)
{
if (rect.X < X + Width && X < rect.X + rect.Width && rect.Y < Y + Height)
{
return Y < rect.Y + rect.Height;
}
return false;
}
public static RectangleD Union(RectangleD a, RectangleD b)
{
double num = Math.Min(a.X, b.X);
double num2 = Math.Max(a.X + a.Width, b.X + b.Width);
double num3 = Math.Min(a.Y, b.Y);
double num4 = Math.Max(a.Y + a.Height, b.Y + b.Height);
return new RectangleD(num, num3, num2 - num, num4 - num3);
}
public void Offset(PointD pos)
{
Offset(pos.X, pos.Y);
}
public void Offset(double x, double y)
{
X += x;
Y += y;
}
//internal GPRECTF ToGPRECTF()
//{
// return new GPRECTF(X, Y, Width, Height);
//}
//public static implicit operator RectangleD(Rectangle r)
//{
// return new RectangleD(r.X, r.Y, r.Width, r.Height);
//}
public override string ToString()
{
return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) + ",Width=" + Width.ToString(CultureInfo.CurrentCulture) + ",Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
}
}
}