using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace RichCreator.Utility.Structs
|
{
|
/// <summary>
|
/// 路径信息
|
/// </summary>
|
public class FindPathInfo
|
{
|
public FindPathInfo()
|
{
|
Vertexs = new List<VertexInfo>();
|
Edges = new List<EdgeInfo>();
|
Positions = new List<PointSerialize>();
|
}
|
|
public FindPathInfo(Int32 width,Int32 height,Int32 rowcount,Int32 colcount):this()
|
{
|
this.Width = width;
|
this.Height = height;
|
this.RowCount = rowcount;
|
this.ColCount = colcount;
|
}
|
|
|
|
/// <summary>
|
/// 宽
|
/// </summary>
|
public int Width { get; set; }
|
|
/// <summary>
|
/// 高
|
/// </summary>
|
public int Height { get; set; }
|
|
/// <summary>
|
/// 行数量
|
/// </summary>
|
public int RowCount { get; set; }
|
|
/// <summary>
|
/// 列数量
|
/// </summary>
|
public int ColCount { get; set; }
|
|
|
/// <summary>
|
/// 顶点列表,顶点x_index,y_index
|
/// </summary>
|
public List<VertexInfo> Vertexs { get; set; }
|
|
/// <summary>
|
/// 顶点连接信息,线信息ZTPoint是index ->index
|
/// </summary>
|
public List<EdgeInfo> Edges { get; set; }
|
|
/// <summary>
|
/// 定位信息
|
/// </summary>
|
public List<PointSerialize> Positions { get; set; }
|
|
/// <summary>
|
/// 添加靠近点
|
/// </summary>
|
/// <param name="vertex"></param>
|
public void AddVertex(Int32 index,Int32 vertexType,Int32 nearVetexIndex)
|
{
|
VertexInfo vertex = new VertexInfo() { Index = index, VertexType = vertexType, NearVertexIndex = nearVetexIndex };
|
AddVertex(vertex);
|
}
|
|
|
/// <summary>
|
/// 添加靠近点
|
/// </summary>
|
/// <param name="vertex"></param>
|
public void AddVertex(VertexInfo vertex)
|
{
|
for (int i = 0; i < Vertexs.Count; i++)
|
{
|
if (Vertexs[i].Index ==vertex.Index)
|
{
|
this.Vertexs[i] = vertex;
|
return;
|
}
|
}
|
|
this.Vertexs.Add(vertex);
|
}
|
|
|
|
|
|
/// <summary>
|
/// 是否存在顶点
|
/// </summary>
|
/// <param name="index"></param>
|
/// <returns></returns>
|
public bool VertexCanAddEdge(Int32 index)
|
{
|
for (int i = 0; i < this.Vertexs.Count; i++)
|
{
|
if (this.Vertexs[i].Index==index)
|
{
|
if (this.Vertexs[i].VertexType != 1)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 得到顶点的行列
|
/// </summary>
|
/// <param name="index"></param>
|
/// <returns></returns>
|
public void GetVertexRowColumn(out Int32 row,out Int32 col,int index)
|
{
|
row = index / this.ColCount;
|
col = index % this.ColCount;
|
}
|
|
/// <summary>
|
/// 获取json
|
/// </summary>
|
/// <returns></returns>
|
public string ToJsonString()
|
{
|
string json = ZTImage.Json.JsonBuilder.ToJsonString(this);
|
return json;
|
}
|
|
/// <summary>
|
/// 从json字符串生成对象
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public static FindPathInfo FromJsonString(string json)
|
{
|
return ZTImage.Json.JsonParser.ToObject<FindPathInfo>(json);
|
}
|
|
|
/// <summary>
|
/// 顶点信息
|
/// </summary>
|
public class VertexInfo
|
{
|
/// <summary>
|
/// 顶点索引
|
/// </summary>
|
public Int32 Index { get; set; }
|
|
/// <summary>
|
/// 顶点类型,0:普通顶点,1:依附顶点,2:起点,3:终点
|
/// </summary>
|
public Int32 VertexType { get; set; }
|
|
|
/// <summary>
|
/// 依附顶点所依附顶点的索引
|
/// </summary>
|
public Int32 NearVertexIndex { get; set; }
|
}
|
|
|
/// <summary>
|
/// 边信息
|
/// </summary>
|
public class EdgeInfo
|
{
|
/// <summary>
|
/// 起点索引
|
/// </summary>
|
public Int32 StartIndex { get; set; }
|
|
/// <summary>
|
/// 终点索引
|
/// </summary>
|
public Int32 EndIndex { get; set; }
|
|
}
|
|
/// <summary>
|
/// 可序列化点
|
/// </summary>
|
public class PointSerialize
|
{
|
public PointSerialize()
|
{}
|
|
public PointSerialize(Int32 x, Int32 y,Int32 number)
|
{
|
this.X = x;
|
this.Y = y;
|
this.Parameter = number;
|
}
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
/// <summary>
|
/// 参数
|
/// </summary>
|
public Int32 Parameter { get; set; }
|
|
}
|
}
|
|
}
|