asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace RichCreator.Utility.Maps
{
    /// <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; }
 
        }
    }
 
}