| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Runtime.Serialization; |
| | | using System.Security.Permissions; |
| | | using System.Text; |
| | | |
| | | namespace Hydro.Model |
| | | { |
| | | [DataContract] |
| | | public class Point2d : ICloneable |
| | | public class Point2d : ICloneable |
| | | { |
| | | [DataMember] |
| | | public double X { get { return x; } set { x = value; } } |
| | | [DataMember] |
| | | public double Y { get { return y; } set { y = value; } } |
| | | |
| | | |
| | | |
| | | protected double x; |
| | | protected double y; |
| | | protected double y; |
| | | |
| | | #region 构造函数 |
| | | public Point2d() { } |
| | | |
| | | |
| | | |
| | | |
| | | public Point2d(double x, double y) |
| | | { |
| | |
| | | this.x = Convert.ToDouble(x); |
| | | this.y = Convert.ToDouble(y); |
| | | } |
| | | public Point2d(Point rhs) |
| | | public Point2d(Point rhs) |
| | | { |
| | | this.X = rhs.X; |
| | | this.Y = rhs.Y; |
| | |
| | | public Point2d(Point2d rhs) |
| | | { |
| | | this.X = rhs.X; |
| | | this.Y = rhs.Y; |
| | | this.Y = rhs.Y; |
| | | } |
| | | public Point2d(string strPara) |
| | | { |
| | |
| | | if (strPara_split_array.Count() < 2) |
| | | return; |
| | | X = Convert.ToDouble(strPara_split_array[0]); |
| | | Y = Convert.ToDouble(strPara_split_array[1]); |
| | | Y = Convert.ToDouble(strPara_split_array[1]); |
| | | } |
| | | public static Point2d ToParameter(string strPara) |
| | | { |
| | |
| | | return null; |
| | | Point2d pt = new Point2d(); |
| | | pt.X = Convert.ToDouble(strPara_split_array[0]); |
| | | pt.Y = Convert.ToDouble(strPara_split_array[1]); |
| | | pt.Y = Convert.ToDouble(strPara_split_array[1]); |
| | | return pt; |
| | | } |
| | | |
| | |
| | | #region ToString |
| | | public override string ToString() |
| | | { |
| | | return string.Format("X:{0},Y:{1}", X, Y ); |
| | | return string.Format("X:{0},Y:{1}", X, Y); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region Clone |
| | |
| | | return new Point2d(this.x + x, this.y + y); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// Return the HashCode from the base class. |
| | |
| | | |
| | | protected Point2d(SerializationInfo info, StreamingContext context) |
| | | { |
| | | |
| | | |
| | | X = info.GetDouble("X"); |
| | | Y = info.GetDouble("Y"); |
| | | } |
| | |
| | | { |
| | | info.AddValue("schema", schema); |
| | | info.AddValue("X", X); |
| | | info.AddValue("Y", Y); |
| | | info.AddValue("Y", Y); |
| | | } |
| | | public string ToDsString() |
| | | { |
| | |
| | | |
| | | public static string ToDsString(Point2d point) |
| | | { |
| | | return string.Format("{0},{1}", point.X, point.Y ); |
| | | return string.Format("{0},{1}", point.X, point.Y); |
| | | } |
| | | |
| | | |
| | |
| | | /// <returns>true if either value is missing</returns> |
| | | public bool IsMissing() |
| | | { |
| | | return this.X == Point2d.Missing || this.Y == Point2d.Missing ; |
| | | return this.X == Point2d.Missing || this.Y == Point2d.Missing; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public bool IsInvalid() |
| | | { |
| | | return this.X == Point2d.Missing || |
| | | this.Y == Point2d.Missing || |
| | | this.Y == Point2d.Missing || |
| | | Double.IsInfinity(this.X) || |
| | | Double.IsInfinity(this.Y) || |
| | | Double.IsInfinity(this.Y) || |
| | | Double.IsNaN(this.X) || |
| | | Double.IsNaN(this.Y) ; |
| | | Double.IsNaN(this.Y); |
| | | |
| | | } |
| | | public bool IsZeroPt() |
| | | { |
| | | if ((Math.Abs(x) < 0.00001) && (Math.Abs(y) < 0.00001) ) |
| | | if ((Math.Abs(x) < 0.00001) && (Math.Abs(y) < 0.00001)) |
| | | return true; |
| | | else |
| | | return false; |
| | |
| | | public enum eSortType |
| | | { |
| | | X, |
| | | Y |
| | | Y |
| | | } |
| | | public enum eCompareType |
| | | { |
| | | X, |
| | | Y, |
| | | Y, |
| | | ALL |
| | | } |
| | | |
| | |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | |
| | | else |
| | | { |
| | | if (Math.Abs(obj1.Y - obj2.Y) < 0.00001) |
| | |
| | | case eCompareType.Y: |
| | | if (Math.Abs(lhs.Y - rhs.Y) < ignoreDis) |
| | | return true; |
| | | break; |
| | | break; |
| | | case eCompareType.ALL: |
| | | if (Math.Abs(lhs.X - rhs.X) < ignoreDis && Math.Abs(lhs.Y - rhs.Y) < ignoreDis ) |
| | | if (Math.Abs(lhs.X - rhs.X) < ignoreDis && Math.Abs(lhs.Y - rhs.Y) < ignoreDis) |
| | | return true; |
| | | break; |
| | | } |
| | |
| | | //距离 |
| | | public double Distance(Point2d pt) |
| | | { |
| | | return Math.Sqrt((pt.X - this.X) * (pt.X - this.X) |
| | | return Math.Sqrt((pt.X - this.X) * (pt.X - this.X) |
| | | + (pt.Y - this.Y) * (pt.Y - this.Y) |
| | | |
| | | |
| | | ); |
| | | } |
| | | } |