using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RichCreator.Utility.Structs { /// /// 路径信息 /// public class HousePathInfo { public HousePathInfo() { Obstacles = new List(); LocationPoints = new List(); FindPathPoints = new List(); LoopLines = new List(); FindPathLines = new List(); } public HousePathInfo(Int32 width,Int32 height):this() { this.Width = width; this.Height = height; } #region Propertys /// /// 宽 /// public int Width { get; set; } /// /// 高 /// public int Height { get; set; } /// /// 障碍物 /// public List Obstacles { get; set; } /// /// 定位点 /// public List LocationPoints { get; set; } /// /// 寻路点 /// public List FindPathPoints{ get; set; } /// /// 循逻线 /// public List LoopLines { get; set; } /// /// 寻路线 /// public List FindPathLines { get; set; } #endregion #region Editor /// /// 添加障碍物 /// /// public bool AddObstacle(ZTPolygon obstacle) { Int32 index = 0; if (ExistsObstacle(out index, obstacle)) { return false; } this.Obstacles.Add(obstacle); return true; } /// /// 删除障碍物 /// /// /// public bool RemoveObstacle(ZTPolygon obstacle) { Int32 index = 0; if (!ExistsObstacle(out index, obstacle)) { return true; } this.Obstacles.RemoveAt(index); return true; } /// /// 是否存在障碍物 /// /// /// private bool ExistsObstacle(out Int32 index,ZTPolygon obstacle) { index = 0; for (int i = 0; i < Obstacles.Count; i++) { if (Obstacles[i] == obstacle) { index = i; return true; } } return false; } /// /// 添加定位点 /// /// /// /// public bool AddLocationPosition(ParametersPoint point) { if (this.LocationPoints.Exists((p) => { return point.Point.Equals(p.Point); })) { return false; } this.LocationPoints.Add(point); return true; } /// /// 清空定位点 /// /// public void ClearLocationPosiltion() { this.LocationPoints.Clear(); } /// /// 添加寻路点 /// /// /// public bool AddFindPathPoint(ZTPoint point) { Int32 index = 0; if (ExistsFindPathPoint(out index, point)) { return false; } this.FindPathPoints.Add(point); return true; } /// /// 删除寻路点 /// /// /// public bool RemoveFindPathPoint(ZTPoint point) { Int32 index = 0; if (!ExistsFindPathPoint(out index,point)) { return true; } //查询巡逻线和寻路线是否有用到此点 if (ExistsPointInAllLine(point)) { return false; } this.FindPathPoints.RemoveAt(index); return true; } /// /// 是否存在指定寻路点 /// /// /// /// private bool ExistsFindPathPoint(out Int32 index, ZTPoint point) { index = 0; for (int i = 0; i < this.FindPathPoints.Count; i++) { if (this.FindPathPoints[i].Equals(point)) { index = i; return true; } } return false; } /// /// 添加巡逻线 /// /// /// public bool AddLoopLine(ZTLinePoint line) { Int32 index = 0; if (ExistsLoopLine(out index, line)) { return false; } if (line.P1 .Equals( line.P2)) { return false; } this.LoopLines.Add(line); return true; } /// /// 删除巡逻线 /// /// /// public bool RemoveLoopLine(ZTLinePoint line) { Int32 index = 0; if (!ExistsLoopLine(out index, line)) { return true; } this.LoopLines.RemoveAt(index); return true; } /// /// 是否存在巡逻线 /// /// /// /// private bool ExistsLoopLine(out Int32 index, ZTLinePoint line) { index = 0; for (int i = 0; i < this.LoopLines.Count; i++) { if (this.LoopLines[i] == line) { index = i; return true; } } return false; } /// /// 添加寻路线 /// /// /// public bool AddFindPathLine(ZTLinePoint line) { Int32 index = 0; if (ExistsFindPathLine(out index, line)) { return false; } this.FindPathLines.Add(line); return true; } /// /// 删除寻路线 /// /// /// public bool RemoveFindPathLine(ZTLinePoint line) { Int32 index = 0; if (!ExistsFindPathLine(out index, line)) { return true; } this.FindPathLines.RemoveAt(index); return true; } /// /// 是否存在寻路线 /// /// /// /// private bool ExistsFindPathLine(out Int32 index, ZTLinePoint line) { index = 0; for (int i = 0; i < this.FindPathLines.Count; i++) { if (this.FindPathLines[i] == line) { index = i; return true; } } return false; } /// /// 巡逻线或寻路线中是否存在某点 /// /// /// private bool ExistsPointInAllLine(ZTPoint point) { for (int i = 0; i < this.LoopLines.Count; i++) { if (this.LoopLines[i].P1.Equals(point) || this.LoopLines[i].P2.Equals(point)) { return true; } } for (int i = 0; i < this.FindPathLines.Count; i++) { if (this.FindPathLines[i].P1 .Equals( point) || this.FindPathLines[i].P2.Equals(point)) { return true; } } return false; } #endregion /// /// 获取json /// /// public string ToJsonString() { string json = ZTImage.Json.JsonBuilder.ToJsonString(this); return json; } /// /// 从json字符串生成对象 /// /// /// public static HousePathInfo FromJsonString(string json) { return ZTImage.Json.JsonParser.ToObject(json); } /// /// 寻找巡逻路线 /// /// public void FindLoopPath(ZTPoint rolePosition) { } /// /// 两点之间寻路 /// /// /// public List FindPath(ZTPoint start, ZTPoint end) { //查询两点间是否连通 //查找两点是否在障碍物里,如果在则计算出来的最短距离 //计算最近的寻路点 //计算寻路点的最短路径 //得出所有路径点 return new List(); } } }