235 lines
5.4 KiB
C#
235 lines
5.4 KiB
C#
using System.Xml.Serialization;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges.LandXMLData
|
|
{
|
|
[XmlType("Point2D")]
|
|
[Serializable]
|
|
public class Point2D
|
|
{
|
|
public Point2D()
|
|
{
|
|
X = 0.0;
|
|
Y = 0.0;
|
|
}
|
|
|
|
public Point2D(Point2D source)
|
|
{
|
|
X = source.X;
|
|
Y = source.Y;
|
|
}
|
|
|
|
public Point2D(double x, double y = 0.0)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
public Point2D(Point2D source, double dx, double dy = 0.0)
|
|
{
|
|
X = source.X + dx;
|
|
Y = source.Y + dy;
|
|
}
|
|
|
|
public const double Pi = 3.1415926535897931;
|
|
|
|
[XmlIgnore]
|
|
public static double precision = 1E-12;
|
|
|
|
public static double precision2 = precision * precision;
|
|
|
|
[XmlIgnore]
|
|
public double Gamma
|
|
{
|
|
get
|
|
{
|
|
double num =
|
|
Y != 0.0
|
|
? X != 0.0
|
|
? Math.Asin(Y / Length2D)
|
|
: Math.Sign(Y) * 3.1415926535897931 * 0.5
|
|
: 0.0;
|
|
if (X >= 0.0)
|
|
{
|
|
return num;
|
|
}
|
|
|
|
return 3.1415926535897931 - num;
|
|
}
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public double Length => Math.Sqrt(LengthSquared);
|
|
|
|
[XmlIgnore]
|
|
public double Length2D => Math.Sqrt(LengthSquared2D);
|
|
|
|
[XmlIgnore]
|
|
public virtual double LengthSquared => LengthSquared2D;
|
|
|
|
[XmlIgnore]
|
|
public double LengthSquared2D => X * X + Y * Y;
|
|
|
|
[XmlIgnore]
|
|
public double SinGamma
|
|
{
|
|
get
|
|
{
|
|
if (Y == 0.0)
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
if (X == 0.0)
|
|
{
|
|
return 1.0;
|
|
}
|
|
|
|
return Y / Length2D;
|
|
}
|
|
}
|
|
|
|
[XmlAttribute("x")]
|
|
public double X { get; set; }
|
|
|
|
[XmlAttribute("y")]
|
|
public double Y { get; set; }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return Equals(obj as Point2D);
|
|
}
|
|
|
|
public bool Equals(Point2D p2d)
|
|
{
|
|
return !ReferenceEquals(p2d, null) && ValuesEqual(this, p2d);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
public static Point2D operator +(Point2D p1, Point2D p2)
|
|
{
|
|
if (p1 != null)
|
|
{
|
|
if (p2 != null)
|
|
{
|
|
return new Point2D { X = p1.X + p2.X, Y = p1.Y + p2.Y };
|
|
}
|
|
|
|
return p1;
|
|
}
|
|
|
|
if (p2 != null)
|
|
{
|
|
return p2;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static Point2D operator /(Point2D p1, double f)
|
|
{
|
|
if (p1 == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (f != 0.0)
|
|
{
|
|
return new Point2D { X = p1.X / f, Y = p1.Y / f };
|
|
}
|
|
|
|
throw new ArgumentException();
|
|
}
|
|
|
|
public static bool operator ==(Point2D p1, Point2D p2)
|
|
{
|
|
return ReferenceEquals(p1, p2) || (!ReferenceEquals(p1, null) && !ReferenceEquals(p2, null) && ValuesEqual(p1, p2));
|
|
}
|
|
|
|
public static Point3D operator ^(Point2D p1, Point2D p2)
|
|
{
|
|
if (p1 == null)
|
|
{
|
|
return new Point3D();
|
|
}
|
|
|
|
if (p2 != null)
|
|
{
|
|
return new Point3D { Z = p1.X * p2.Y - p1.Y * p2.X };
|
|
}
|
|
|
|
return new Point3D();
|
|
}
|
|
|
|
public static bool operator !=(Point2D p1, Point2D p2)
|
|
{
|
|
return !ReferenceEquals(p1, p2) && (ReferenceEquals(p1, null) || ReferenceEquals(p2, null) || !ValuesEqual(p1, p2));
|
|
}
|
|
|
|
public static double operator *(Point2D p1, Point2D p2)
|
|
{
|
|
if (p1 == null)
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
if (p2 != null)
|
|
{
|
|
return p1.X * p2.X + p1.Y * p2.Y;
|
|
}
|
|
|
|
return 0.0;
|
|
}
|
|
|
|
public static Point2D operator *(Point2D p1, double f)
|
|
{
|
|
if (p1 == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (f != 0.0)
|
|
{
|
|
return new Point2D { X = p1.X * f, Y = p1.Y * f };
|
|
}
|
|
|
|
return new Point2D();
|
|
}
|
|
|
|
public static Point2D operator -(Point2D p1, Point2D p2)
|
|
{
|
|
if (p1 != null)
|
|
{
|
|
if (p2 != null)
|
|
{
|
|
return new Point2D { X = p1.X - p2.X, Y = p1.Y - p2.Y };
|
|
}
|
|
|
|
return p1;
|
|
}
|
|
|
|
if (p2 != null)
|
|
{
|
|
return new Point2D { X = -p2.X, Y = -p2.Y };
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static bool ValuesEqual(Point2D p1, Point2D p2)
|
|
{
|
|
double num = (Math.Abs(p1.X) > Math.Abs(p2.X) ? Math.Abs(p1.X) : Math.Abs(p2.X)) * precision;
|
|
if (Math.Abs(p1.X - p2.X) <= num)
|
|
{
|
|
double num2 = (Math.Abs(p1.Y) > Math.Abs(p2.Y) ? Math.Abs(p1.Y) : Math.Abs(p2.Y)) * precision;
|
|
return Math.Abs(p1.Y - p2.Y) <= num2;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|