using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Deltares.DamPiping.ExitPointDeterminator { public class Point2D { public const double Epsilon = 1E-10; public double X { get; set; } public double Y { get; set; } public Point2D() { this.X = 0.0; this.Y = 0.0; } public Point2D(double aX, double aY) { this.X = aX; this.Y = aY; } public Point2D(double aValue1, Point2D aPoint1, double aValue2, Point2D aPoint2) { this.X = aValue1 * aPoint1.X + aValue2 * aPoint2.X; this.Y = aValue1 * aPoint1.Y + aValue2 * aPoint2.Y; } public Point2D(double aValue1, Point2D aPoint1, double aValue2, Point2D aPoint2, double aValue3, Point2D aPoint3, double aValue4, Point2D aPoint4) { this.X = aValue1 * aPoint1.X + aValue2 * aPoint2.X + aValue3 * aPoint3.X + aValue4 * aPoint4.X; this.Y = aValue1 * aPoint1.Y + aValue2 * aPoint2.Y + aValue3 * aPoint3.Y + aValue4 * aPoint4.Y; } public Point2D(Point2D aPoint) { this.X = aPoint.X; this.Y = aPoint.Y; } public static Point2D operator -(Point2D aPoint) { return new Point2D(-aPoint.X, -aPoint.Y); } public static Point2D operator +(Point2D aPoint2, Point2D aPoint1) { return new Point2D(aPoint2.X + aPoint1.X, aPoint2.Y + aPoint1.Y); } public static Point2D operator -(Point2D aPoint2, Point2D aPoint1) { return new Point2D(aPoint2.X - aPoint1.X, aPoint2.Y - aPoint1.Y); } public static Point2D operator *(double aValue1, Point2D aPoint1) { return new Point2D(aValue1 * aPoint1.X, aValue1 * aPoint1.Y); } public static Point2D operator *(Point2D aPoint1, double aValue1) { return new Point2D(aValue1 * aPoint1.X, aValue1 * aPoint1.Y); } public void Init(double aX, double aY) { this.X = aX; this.Y = aY; } public void Init(Point2D aPoint) { this.X = aPoint.X; this.Y = aPoint.Y; } public Point2D Add(Point2D aPoint) { this.X += aPoint.X; this.Y += aPoint.Y; return this; } public bool FromString(string aString, params char[] aSeparator) { string[] strArray = aString.Split(aSeparator); if (strArray.Length != 2) return false; this.X = Convert.ToDouble(strArray[0]); this.Y = Convert.ToDouble(strArray[1]); return true; } public override bool Equals(object obj) { Point2D point2D = obj as Point2D; if (point2D != null && Helper.AlmostEquals(X, point2D.X, 1E-10)) return Helper.AlmostEquals(Y, point2D.Y, 1E-10); return false; } public override int GetHashCode() { return this.GetType().GetHashCode() + 11 * (int)Math.Round(this.X * 1000000000) + 29 * (int)Math.Round(this.Y * 1000000000); } public override string ToString() { return this.X.ToString("F3") + ", " + this.Y.ToString("F3"); } } }