Shuxia Ning
2024-12-05 1e9a72970e30b74b8f0cb7c74e2bec9df1aa1d22
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
 
namespace Eventech.Model
{
    //比ThroughCurve多一个参数
    [Serializable]
    public class ThroughParaCurve : ThroughCurve, ICloneable
    {
        public ThroughParaCurve() { }
        public ThroughParaCurve(string strPara)
        {
            if (string.IsNullOrEmpty(strPara))
            {
                isNull = true;
                return;
            }
 
            string[] strParas = strPara.Split(',');
            if (strParas.Count() < 5)
            {
                isNull = true;
                return;
            }
 
            DispTension = float.Parse(strParas[0]);
            IsClosed = bool.Parse(strParas[1]);
            CurvePara = Convert.ToDouble(strParas[2]);
 
            int iPtCount = Convert.ToInt32(strParas[3]);
            if (iPtCount == 0)
            {
                isNull = true;
                return;
            }
 
            PointInfo = new Eventech.Model.FeatPointList();
            for (int i = 0; i < iPtCount; i++)
            {//可能只有一个点
                PointInfo.Add(new Eventech.Model.FeatPoint() { X = Convert.ToDouble(strParas[4 + i * 2]), Y = Convert.ToDouble(strParas[4 + 2 * i + 1]) });
            }
        }
        public ThroughParaCurve(ThroughParaCurve rhs) {
            this.DispTension = rhs.DispTension;
            this.IsClosed = rhs.IsClosed;
            this.CurvePara = rhs.CurvePara;
            this.PointInfo = rhs.PointInfo.Clone();
        }
 
        public ThroughParaCurve(double para, List<Eventech.Model.FeatPoint> curveInfo, bool isClosed=false, float tension=0.5f)
        {
            CurvePara = para;
            PointInfo = new Eventech.Model.FeatPointList(curveInfo);
            IsClosed = isClosed;
            DispTension = tension;
        }
 
 
        [DataMember]
        public double CurvePara { get { return _curvePara; } set { _curvePara = value; } }
        public double _curvePara = -1;
 
 
        public new ThroughParaCurve Clone() 
        {
            return new ThroughParaCurve(this);
        }
        object ICloneable.Clone()
        {
            return Clone();
        }
 
        public new string ToDsString()
        {
            return ToDsString(this);
        }
 
        public static string ToDsString(ThroughParaCurve curve)
        {
            if (curve == null || curve.PointInfo == null)
                return null;
 
            StringBuilder sb = new StringBuilder();
            sb.Append(curve.DispTension);
            sb.Append(","); sb.Append(curve.IsClosed);
            sb.Append(","); sb.Append(curve.CurvePara);
            sb.Append(","); sb.Append(curve.PointInfo.Count);
 
            foreach (var point in curve.PointInfo)
            {//必须用,分割,//可能只有一个点
                sb.AppendFormat(",{0},{1}", point.X, point.Y);
            }
 
            return sb.ToString();
        }
 
        public static ThroughParaCurve ToParameter(string strPara)
        {
            ThroughParaCurve curve = new ThroughParaCurve(strPara);
            if (curve.IsNull)
                return null;
            return curve;
        }
 
 
 
        public class Comparer : IComparer<ThroughParaCurve>
        {
            public Comparer()
            {
            }
 
            #region IComparer<Eventech.Model.FeatPoint> 成员
            private double ignoreDis = 0.001;
            int IComparer<ThroughParaCurve>.Compare(ThroughParaCurve obj1, ThroughParaCurve obj2)
            {
                if (Math.Abs(obj1.CurvePara - obj2.CurvePara) < ignoreDis)
                {//参数一样 就比较Y的平均值
                    double y1_arv = (from x in obj1.PointInfo select x.Y).Average();
                    double y2_arv = (from x in obj2.PointInfo select x.Y).Average();
                    if (Math.Abs(y1_arv - y2_arv)<0.01)
                        return 0;
                    else if (y1_arv > y2_arv)
                        return 1;
                    else 
                        return -1;
                }
                else if (obj1.CurvePara > obj2.CurvePara)
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
 
            #endregion
        }
 
        //比较相同:主要用与LIST的Contains方法和Distinct
        public class EqualComparer : IEqualityComparer<ThroughParaCurve>
        {
            private double ignoreDis = 0.001;
            public EqualComparer()
            {
                ignoreDis = 0.001;
            }
            public EqualComparer(double dis)
            {
                ignoreDis = dis;
            }
 
            public bool Equals(ThroughParaCurve lhs, ThroughParaCurve rhs)
            {
 
                if (Math.Abs(lhs.CurvePara - rhs.CurvePara) < ignoreDis)
                    return true;
                else
                    return false;
            }
 
            public int GetHashCode(ThroughParaCurve obj)
            {
                //return obj.X.GetHashCode() + obj.Y.GetHashCode(); 
                return 0;
            }
        }
 
    }
 
 
 
}