using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.Model.Repair { /// /// 点 /// public class Point : JsonList, System.ICloneable { /// /// /// public Point() { } /// /// /// public Point(double x, double y) { this.X = x; this.Y = y; } /// /// /// public Point(string x, string y) { if (double.TryParse(x, out double rx)) this.X = rx; if (double.TryParse(y, out double ry)) this.Y = ry; } /// /// /// public Point(Point rhs) { this.X = rhs.X; this.Y = rhs.Y; } /// /// /// public Point(string split_str) { if (!string.IsNullOrEmpty(split_str)) { var list = split_str.Split(','); if (list.Length == 2) { if (double.TryParse(list[0], out double rx)) this.X = rx; if (double.TryParse(list[1], out double ry)) this.Y = ry; } } } /// /// /// public Point(System.Drawing.Point p) { this.X = p.X; this.Y = p.Y; } /// /// /// public Point(System.Drawing.PointF p) { this.X = p.X; this.Y = p.Y; } /// /// X 经度 /// public double X { get; set; } /// /// Y 纬度 /// public double Y { get; set; } /// /// 显示字符串 /// public string ToDispString() { return $"{X},{Y}"; } /// /// 字符转换 /// public static Point FromDispString(string dispString) { Point map = null; if (!string.IsNullOrEmpty(dispString)) { var list = dispString.Split(','); if (list.Length == 2) if (double.TryParse(list[0], out double rx) && double.TryParse(list[1], out double ry)) map = new Point() { X = rx, Y = ry }; } return map; } /// /// 从显示列表中获取 /// public static List FromDispList(string dispList, char delimiter = '|') { if (string.IsNullOrEmpty(dispList)) return default; var list = dispList.Split(delimiter); if (list.Length < 1) return default; try { var vm_list = new List(); foreach (var item in list) { var vm = new Point(item); vm_list.Add(vm); } return vm_list; } catch { return default; } } /// /// 转化为显示列表 /// public static string ToDispList(List dispList) { if (dispList == null || dispList.Count < 1) return default; var list = dispList.Select(x => x.ToDispString()).ToList(); return string.Join("|", list); } /// /// /// public Point Clone() { return (Point)this.MemberwiseClone(); } object ICloneable.Clone() { return this.MemberwiseClone(); } } }