CurveCore.cs 5.85 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.Thick.Base.Common
{
    public class CurveCore
    {
        #region ICurveService 成员

        public CurveType Flag;

        public List<CurveCell> Curves;

        public event PropertyChangedEventHandler PropertyChanged;

        public void SetRevised()
        {
            for (int i = 0; i < Curves.Count(); i++)
            {
                Curves[i].AD = Curves[i].RevisedAD;
            }
        }


        #region E

        int AD2Value_E(int ad, AD2ValueFlag flag)
        {
            int i;
            int thick;

            if (Curves.Count < 1) return -1;
            if (ad < 0) return -1;
            if (ad == 0) ad = 1;
            if (flag == AD2ValueFlag.NoRevised)
            {
                for (i = 0; i < Curves.Count; i++)
                {
                    if (ad < Curves[i].AD)
                        continue;
                    else
                        break;
                }
            }
            else
            {
                for (i = 0; i < Curves.Count; i++)
                {
                    if (ad < Curves[i].RevisedAD)
                        continue;
                    else
                        break;
                }
            }
            if (i >= Curves.Count) i = Curves.Count - 1;

            if (i == 0) i = 1;
            if (flag == AD2ValueFlag.NoRevised)
            {

                double adi_ad0 = Math.Log(Curves[i].AD) - Math.Log(Curves[i - 1].AD);
                double vi_v0 = Curves[i].Value - Curves[i - 1].Value;
                double a = vi_v0 / adi_ad0;
                double b = Curves[i - 1].Value - Math.Log(Curves[i - 1].AD) * a;

                thick = (int)(Math.Log(ad) * a + b);

                //double u;
                //u = Math.Log((double)Curves[i - 1].AD / Curves[i].AD, Math.E) * 100 / (Curves[i].Value - Curves[i - 1].Value);
                //thick = (int)(Math.Log((double)Curves[i - 1].AD / ad, Math.E) * 100 / u + Curves[i - 1].Value);
            }
            else
            {
                double adi_ad0 = Math.Log(Curves[i].RevisedAD) - Math.Log(Curves[i - 1].RevisedAD);
                double vi_v0 = Curves[i].Value - Curves[i - 1].Value;
                double a = vi_v0 / adi_ad0;
                double b = Curves[i - 1].Value - Math.Log(Curves[i - 1].RevisedAD) * a;

                thick = (int)(Math.Log(ad) * a + b);

                //double u;

                //u = Math.Log((double)Curves[i - 1].RevisedAD / Curves[i].RevisedAD, Math.E) * 100 / (Curves[i].Value - Curves[i - 1].Value);
                //thick = (int)(Math.Log((double)Curves[i - 1].RevisedAD / ad, Math.E) * 100 / u + Curves[i - 1].Value);

            }
            //if (thick < 0)
            //    return 0;

            return thick;
        }
        #endregion
        #region 线性
        int AD2Value_Line(int ad, AD2ValueFlag flag)
        {
            int i;
            int thick;

            if (Curves.Count < 2) return -1;
            if (ad < 0) return -1;
            if (ad == 0) ad = 1;
            bool isDescending = true;//降序排列
            if (Curves[0].AD < Curves[1].AD)
                isDescending = false;
            //找 ad0<ad<adi

            if (flag == AD2ValueFlag.NoRevised)
            {
                if (isDescending)//降序排列
                {
                    for (i = 0; i < Curves.Count; i++)
                    {
                        if (ad < Curves[i].AD)
                            continue;
                        else
                            break;
                    }
                }
                else
                {
                    for (i = 0; i < Curves.Count; i++)
                    {
                        if (ad > Curves[i].AD)
                            continue;
                        else
                            break;
                    }
                }
                if (i >= Curves.Count) i = Curves.Count - 1;
                if (i == 0) i = 1;

                double adi_ad0 = Curves[i].AD - Curves[i - 1].AD;
                double vi_v0 = Curves[i].Value - Curves[i - 1].Value;
                double a = vi_v0 / adi_ad0;
                double b = Curves[i - 1].Value - Curves[i - 1].AD * a;

                thick = (int)(ad * a + b);
                return thick;
            }
            else
            {
                if (isDescending)//降序排列
                {
                    for (i = 0; i < Curves.Count; i++)
                    {
                        if (ad < Curves[i].RevisedAD)
                            continue;
                        else
                            break;
                    }
                }
                else
                {
                    for (i = 0; i < Curves.Count; i++)
                    {
                        if (ad > Curves[i].RevisedAD)
                            continue;
                        else
                            break;
                    }
                }
                if (i >= Curves.Count) i = Curves.Count - 1;
                if (i == 0) i = 1;

                double adi_ad0 = Curves[i].AD - Curves[i - 1].RevisedAD;
                double vi_v0 = Curves[i].Value - Curves[i - 1].Value;
                double a = vi_v0 / adi_ad0;
                double b = Curves[i - 1].Value - Curves[i - 1].RevisedAD * a;

                thick = (int)(ad * a + b);
                return thick;
            }
        }
        #endregion

        public int AD2Value(int ad, AD2ValueFlag flag)
        {
            switch (Flag)
            {
                case CurveType.Line:
                    return AD2Value_Line(ad, flag);
                default:
                    return AD2Value_E(ad, flag);
            }
        }
        #endregion
    }
}