コード例 #1
0
ファイル: GradationInfo.cs プロジェクト: vasichmen/WindEnergy
        /// <summary>
        /// получить соответствующую значению градацию типа Т
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        internal object GetItem(double val)
        {
            if (double.IsNaN(val))
            {
                throw new ArgumentException("Заданное значение не является числом!");
            }

            if (typeof(T) == typeof(GradationItem))
            {
                foreach (var v in items)
                {
                    if (val >= (v as GradationItem).From && val <= (v as GradationItem).To)
                    {
                        return(v);
                    }
                }
                var           max = double.MinValue;
                GradationItem mgi = null;
                foreach (GradationItem gi in items)
                {
                    if (gi.To > max)
                    {
                        max = gi.To; mgi = gi;
                    }
                }
                if (mgi != null)
                {
                    return(mgi);
                }
                else
                {
                    return(GradationItem.Empty);
                }
            }
            else if (typeof(T) == typeof(WindDirections16))
            {
                return(new RawItem()
                {
                    Direction = val
                }.DirectionRhumb);
            }
            else if (typeof(T) == typeof(WindDirections8))
            {
                return(new RawItem()
                {
                    Direction = val
                }.DirectionRhumb8);
            }
            else
            {
                throw new Exception("Этот тип не реализован");
            }
        }
コード例 #2
0
ファイル: GradationInfo.cs プロジェクト: vasichmen/WindEnergy
 /// <summary>
 /// преобразование градаций этого типа в GradationItem
 /// </summary>
 /// <returns></returns>
 internal GradationInfo <GradationItem> ToGradationItem()
 {
     if (typeof(T) == typeof(GradationItem))
     {
         return(this as GradationInfo <GradationItem>);
     }
     if (typeof(T) == typeof(WindDirections16))
     {
         double d = 22.5d / 2d;
         GradationInfo <GradationItem> res = new GradationInfo <GradationItem>();
         foreach (WindDirections16 item in this.items)
         {
             double        dir = RawItem.GetDirection(item);
             GradationItem gr  = new GradationItem(dir - d, dir + d);
             res.items.Add(gr);
         }
         return(res);
     }
     throw new WindEnergyException("Невозможно преобразовать этот тип градаций в GradationItem");
 }