asmrobot
2019-10-29 f25f89101a98ad815c0ae2d25e1a8dc35d53a5dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace RichCreator.Utility.Structs
{
    /// <summary>
    /// 路径信息
    /// </summary>
    public class HousePathInfo
    {
        public HousePathInfo()
        {
            Obstacles = new List<ZTPolygon>();
            LocationPoints = new List<ParametersPoint>();
            FindPathPoints = new List<ZTPoint>();
            LoopLines = new List<ZTLinePoint>();
            FindPathLines = new List<ZTLinePoint>();
 
        }
 
        public HousePathInfo(Int32 width,Int32 height):this()
        {
            this.Width = width;
            this.Height = height;
        }
 
 
        #region Propertys
        /// <summary>
        /// 宽
        /// </summary>
        public int Width { get; set; }
 
        /// <summary>
        /// 高
        /// </summary>
        public int Height { get; set; }
        
 
 
 
        /// <summary>
        /// 障碍物
        /// </summary>
        public List<ZTPolygon> Obstacles { get; set; }
 
 
        /// <summary>
        /// 定位点
        /// </summary>
        public List<ParametersPoint> LocationPoints { get; set; }
 
 
        /// <summary>
        /// 寻路点
        /// </summary>
        public List<ZTPoint> FindPathPoints{ get; set; }
 
 
        /// <summary>
        /// 循逻线
        /// </summary>
        public List<ZTLinePoint> LoopLines { get; set; }
 
        /// <summary>
        /// 寻路线
        /// </summary>
        public List<ZTLinePoint> FindPathLines { get; set; }
 
        #endregion
 
 
        #region Editor
        /// <summary>
        /// 添加障碍物
        /// </summary>
        /// <returns></returns>
        public bool AddObstacle(ZTPolygon obstacle)
        {
            Int32 index = 0;
            if (ExistsObstacle(out index, obstacle))
            {
                return false;
            }
            this.Obstacles.Add(obstacle);
            return true;
        }
 
        /// <summary>
        /// 删除障碍物
        /// </summary>
        /// <param name="obstacle"></param>
        /// <returns></returns>
        public bool RemoveObstacle(ZTPolygon obstacle)
        {
            Int32 index = 0;
            if (!ExistsObstacle(out index, obstacle))
            {
                return true;
            }
 
            this.Obstacles.RemoveAt(index);
            return true;
        }
 
        /// <summary>
        /// 是否存在障碍物
        /// </summary>
        /// <param name="obstacle"></param>
        /// <returns></returns>
        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;
        }
 
 
        /// <summary>
        /// 添加定位点
        /// </summary>
        /// <param name="point"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public bool AddLocationPosition(ParametersPoint point)
        {
            if (this.LocationPoints.Exists((p) => { return point.Point.Equals(p.Point); }))
            {
                return false;
            }
 
            this.LocationPoints.Add(point);
            return true;
        }
 
        /// <summary>
        /// 清空定位点
        /// </summary>
        /// <returns></returns>
        public void ClearLocationPosiltion()
        {
            this.LocationPoints.Clear();
        }
        
 
        /// <summary>
        /// 添加寻路点
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public bool AddFindPathPoint(ZTPoint point)
        {
            Int32 index = 0;
            if (ExistsFindPathPoint(out index, point))
            {
                return false;
            }
 
            this.FindPathPoints.Add(point);
            return true;
        }
 
        /// <summary>
        /// 删除寻路点
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        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;
        }
 
        /// <summary>
        /// 是否存在指定寻路点
        /// </summary>
        /// <param name="index"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        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;
        }
 
        /// <summary>
        /// 添加巡逻线
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        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;
        }
 
        /// <summary>
        /// 删除巡逻线
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool RemoveLoopLine(ZTLinePoint line)
        {
            Int32 index = 0;
            if (!ExistsLoopLine(out index, line))
            {
                return true;
            }
            this.LoopLines.RemoveAt(index);
            return true;
        }
 
        /// <summary>
        /// 是否存在巡逻线
        /// </summary>
        /// <param name="index"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        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;
        }
 
 
        /// <summary>
        /// 添加寻路线
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool AddFindPathLine(ZTLinePoint line)
        {
            Int32 index = 0;
            if (ExistsFindPathLine(out index, line))
            {
                return false;
            }
            this.FindPathLines.Add(line);
            return true;
        }
 
        /// <summary>
        /// 删除寻路线
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool RemoveFindPathLine(ZTLinePoint line)
        {
            Int32 index = 0;
            if (!ExistsFindPathLine(out index, line))
            {
                return true;
            }
            this.FindPathLines.RemoveAt(index);
            return true;
        }
 
        /// <summary>
        /// 是否存在寻路线
        /// </summary>
        /// <param name="index"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        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;
        }
 
        /// <summary>
        /// 巡逻线或寻路线中是否存在某点
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        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
 
 
 
        /// <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 HousePathInfo FromJsonString(string json)
        {
            return ZTImage.Json.JsonParser.ToObject<HousePathInfo>(json);
        }
 
 
        /// <summary>
        /// 寻找巡逻路线
        /// </summary>
        /// <param name="rolePosition"></param>
        public void FindLoopPath(ZTPoint rolePosition)
        {
 
        }
 
        /// <summary>
        /// 两点之间寻路
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public List<ZTPoint> FindPath(ZTPoint start, ZTPoint end)
        {
            //查询两点间是否连通
            //查找两点是否在障碍物里,如果在则计算出来的最短距离
            //计算最近的寻路点
            //计算寻路点的最短路径
            //得出所有路径点
            return new List<ZTPoint>();
        }
 
 
    }
 
}