using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Model.Repair
|
{
|
/// <summary>
|
/// 点
|
/// </summary>
|
public class Point : JsonList<Point>, System.ICloneable
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public Point() { }
|
|
/// <summary>
|
///
|
/// </summary>
|
public Point(double x, double y)
|
{
|
this.X = x;
|
this.Y = y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
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;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public Point(Point rhs)
|
{
|
this.X = rhs.X;
|
this.Y = rhs.Y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
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;
|
}
|
}
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public Point(System.Drawing.Point p)
|
{
|
this.X = p.X;
|
this.Y = p.Y;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public Point(System.Drawing.PointF p)
|
{
|
this.X = p.X;
|
this.Y = p.Y;
|
}
|
|
/// <summary>
|
/// X 经度
|
/// </summary>
|
public double X { get; set; }
|
|
/// <summary>
|
/// Y 纬度
|
/// </summary>
|
public double Y { get; set; }
|
|
/// <summary>
|
/// 显示字符串
|
/// </summary>
|
public string ToDispString()
|
{
|
return $"{X},{Y}";
|
}
|
|
/// <summary>
|
/// 字符转换
|
/// </summary>
|
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;
|
}
|
|
/// <summary>
|
/// 从显示列表中获取
|
/// </summary>
|
public static List<Point> 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<Point>();
|
foreach (var item in list)
|
{
|
var vm = new Point(item);
|
vm_list.Add(vm);
|
}
|
return vm_list;
|
}
|
catch
|
{
|
return default;
|
}
|
}
|
|
/// <summary>
|
/// 转化为显示列表
|
/// </summary>
|
public static string ToDispList(List<Point> dispList)
|
{
|
if (dispList == null || dispList.Count < 1)
|
return default;
|
var list = dispList.Select(x => x.ToDispString()).ToList();
|
return string.Join("|", list);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public Point Clone()
|
{
|
return (Point)this.MemberwiseClone();
|
}
|
|
object ICloneable.Clone()
|
{
|
return this.MemberwiseClone();
|
}
|
|
|
}
|
}
|