Shuxia Ning
2025-02-13 2f1cbec203dcff25df7a5c2b51b13ec558f2c3db
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
 
 
namespace IStation.Model
{
    /// <summary>
    /// 曲线点
    /// </summary>
    [DataContract]
    public partial class CurvePoint : ICloneable
    {
        #region 构造函数
 
        public CurvePoint() { }
        public CurvePoint(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
        public CurvePoint(float x, float y)
        {
            this.X = x;
            this.Y = y;
        }
        public CurvePoint(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
        public CurvePoint(decimal x, decimal y)
        {
            this.X = Convert.ToDouble(x);
            this.Y = Convert.ToDouble(y);
        }
        public CurvePoint(CurvePoint rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;
        }
        public CurvePoint(System.Drawing.Point p) : this(p.X, p.Y) { }
        public CurvePoint(System.Drawing.PointF p) : this(p.X, p.Y) { }
        public CurvePoint(string strParas)
        {
            if (string.IsNullOrEmpty(strParas))
                return;
            var strParas_split_array = strParas.Split(new string[] { Separator1 }, StringSplitOptions.RemoveEmptyEntries);
            if (strParas_split_array.Count() != 2)
                return;
            if (double.TryParse(strParas_split_array[0], out double x))
            {
                this.X = x;
            }
            if (double.TryParse(strParas_split_array[1], out double y))
            {
                this.Y = y;
            }
        }
 
        public static CurvePoint ToParameter(string strParas)
        {
            if (string.IsNullOrEmpty(strParas))
                return null;
            var strParas_split_array = strParas.Split(new string[] { Separator1 }, StringSplitOptions.RemoveEmptyEntries);
            if (strParas_split_array.Count() != 2)
                return null;
            CurvePoint pt = new CurvePoint();
            if (double.TryParse(strParas_split_array[0], out double x))
            {
                pt.X = x;
            }
            else
            {
                return null;
            }
            if (double.TryParse(strParas_split_array[1], out double y))
            {
                pt.Y = y;
            }
            else
            {
                return null;
            }
            return pt;
        }
        #endregion
 
        #region 静态
 
        public const string Separator1 = ",";
        public const string Separator2 = "|";
 
 
 
        public const double Missing = double.MaxValue;
        public const string Format = "N2";
 
        #endregion
 
        #region 属性
 
        /// <summary>
        /// X
        /// </summary>
        [DataMember]
        public double X
        {
            get { return x; }
            set { x = value; }
        }
        protected double x = Missing;
 
        /// <summary>
        /// Y
        /// </summary>
        [DataMember]
        public double Y
        {
            get { return y; }
            set { y = value; }
        }
        protected double y = Missing;
 
        #endregion
 
        /// <summary>
        /// 转换为DS
        /// </summary>
        public string ToDsString()
        {
            return $"{this.X}{Separator1}{this.Y}";
        }
 
        /// <summary>
        /// 偏置
        /// </summary>
        public CurvePoint Offset(double x, double y)
        {
            return new CurvePoint(this.X + x, this.Y + y);
        }
 
        /// <summary>
        /// ToString
        /// </summary>
        public override string ToString()
        {
            return $"X:{this.X}{Separator1}Y:{this.Y}";
        }
 
        /// <summary>
        /// ToString
        /// </summary>
        public string ToString(string format)
        {
            return $"X:{this.X.ToString(format)}{Separator1}Y:{this.Y.ToString(format)}";
        }
 
        /// <summary>
        /// ToString
        /// </summary>
        public string ToString(string formatx, string formaty)
        {
            return $"X:{this.X.ToString(formatx)}{Separator1}Y:{this.Y.ToString(formaty)}";
        }
 
        /// <summary>
        /// 
        /// </summary>
        public bool IsMissing()
        {
            return this.X == Missing || this.Y == Missing;
        }
 
        /// <summary>
        /// 是否无效
        /// </summary>
        public bool IsInvalid()
        {
            return this.X == Missing ||
                    this.Y == Missing ||
                    double.IsInfinity(this.X) ||
                    double.IsInfinity(this.Y) ||
                    double.IsNaN(this.X) ||
                    double.IsNaN(this.Y);
        }
        //判断是否是0点,用于判断函数是否成功返回
        internal static bool IsZeroPt(CurvePoint pt)
        {
            if (Math.Abs(pt.X) < 0.0001 && Math.Abs(pt.Y) < 0.0001)
                return true;
            else
                return false;
 
        }
        /// <summary>
        /// 
        /// </summary>
        public bool IsZeroPt()
        {
            if ((Math.Abs(x) < 0.0001) && (Math.Abs(y) < 0.0001))
                return true;
            else
                return false;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static CurvePoint ToModel(string strParas)
        {
            return new CurvePoint(strParas);
        }
 
        /// <summary>
        /// 
        /// </summary>
        public CurvePoint Copy()
        {
            return new CurvePoint(this);
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static CurvePoint Copy(CurvePoint pt)
        {
            if (pt == null)
                return null;
            return new CurvePoint(pt);
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static List<CurvePoint> Copy(IEnumerable<CurvePoint> src_list)
        {
            if (src_list == null)
                return null;
            var list = new List<CurvePoint>();
            foreach (var pt in src_list)
            {
                list.Add(new CurvePoint(pt));
            }
 
            return list;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static bool IsValueInvalid(double value)
        {
            return (value == Missing ||
                    double.IsInfinity(value) ||
                    double.IsNaN(value));
        }
 
        /// <summary>
        /// 距离
        /// </summary>
        public double Distance(CurvePoint pt)
        {
            if (pt == null)
                return double.MaxValue;
            return Math.Sqrt((pt.X - this.X) * (pt.X - this.X) + (pt.Y - this.Y) * (pt.Y - this.Y));
        }
 
        /// <summary>
        /// 距离
        /// </summary>
        public double Distance(IEnumerable<CurvePoint> list)
        {
            if (list == null || list.Count() < 1)
                return double.MaxValue;
 
            return list.Select(x => this.Distance(x)).Min();
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static string ToDsString(IEnumerable<CurvePoint> src_list)
        {
            if (src_list == null || src_list.Count() < 1)
                return default;
            var str_list = src_list.Select(x => x.ToDsString());
            return string.Join(Separator2, str_list);
        }
 
        /// <summary>
        /// 
        /// </summary>
        public static List<CurvePoint> ToList(string strParas)
        {
            if (string.IsNullOrEmpty(strParas))
                return default;
            var str_list = strParas.Split(new string[] { Separator2 }, StringSplitOptions.RemoveEmptyEntries);
            List<CurvePoint> points = new List<CurvePoint>(str_list.Count());
            foreach (var s in str_list)
            {
                var pt = IStation.Model.CurvePoint.ToParameter(s);
                if (pt != null)
                    points.Add(pt);
            }
            return points;
        }
        public static List<CurvePoint> ToList(string strParas, string[] endChar)
        {
            if (string.IsNullOrEmpty(strParas))
                return default;
            if (endChar == null || endChar.Length == 0)
                return ToList(strParas);
            var str_list = strParas.Split(new string[] { Separator2 }, StringSplitOptions.RemoveEmptyEntries);
            List<CurvePoint> points = new List<CurvePoint>(str_list.Count());
            foreach (var s in str_list)
            {
                if (endChar.Contains(s))
                    break;
                var pt = IStation.Model.CurvePoint.ToParameter(s);
                if (pt != null)
                    points.Add(pt);
            }
            return points;
        }
        /// <summary>
        /// 是否向x轴的射线穿透线段,有交点且在线的左边
        /// </summary>
        public bool IsIntersectLineLeft(CurvePoint p1, CurvePoint p2)
        {
            if (p1 == null || p2 == null)
                return default;
            double y_max = p1.y > p2.y ? p1.y : p2.y;
            double y_min = p1.y > p2.y ? p2.y : p1.y;
 
            if (Math.Abs(p1.y - p2.y) < 0.0001)
            {
                if (Math.Abs(y - p1.y) < 0.0001)
                    return true;
                else
                    return false;
            }
 
            bool isLeft = false;
            if (y < y_max && y >= y_min)
            {
                if (x <= (p1.x + (p2.x - p1.x) * (y - p1.y) / (p2.y - p1.y)))
                {
                    isLeft = true;
                }
            }
            return isLeft;
        }
 
 
 
        #region Clone
        public CurvePoint Clone()
        {
            return new CurvePoint(x, y);
        }
        object ICloneable.Clone()
        {
            return this.Clone();
        }
 
        #endregion
 
        #region Equals
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            var rhs = obj as CurvePoint;
            if (rhs == null)
                return default;
            return this.X == rhs.X && this.Y == rhs.Y;
        }
        #endregion
 
 
 
 
 
 
 
 
 
 
 
 
    }
 
 
 
 
}