当前位置: 首页>>代码示例>>C#>>正文


C# Interval.IncludesParameter方法代码示例

本文整理汇总了C#中Interval.IncludesParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Interval.IncludesParameter方法的具体用法?C# Interval.IncludesParameter怎么用?C# Interval.IncludesParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interval的用法示例。


在下文中一共展示了Interval.IncludesParameter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> dhrs = new List<DHr>();
            string key_u = "";
            string key_v = "";
            Interval subdivs = new Interval();
            if ((DA.GetDataList(0, dhrs)) && (DA.GetData(1, ref key_u)) && (DA.GetData(2, ref key_v)) && (DA.GetData(4, ref subdivs)))
            {
                int subdivs_u = (int) Math.Floor(subdivs.T0);
                int subdivs_v = (int) Math.Floor(subdivs.T1);

                Grasshopper.Kernel.Types.UVInterval ival_overall = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(3, ref ival_overall)) {
                    // go thru the given hours and find the max and min value for the given key
                    Interval ival_temp_u = new Interval(MDHr.INVALID_VAL, MDHr.INVALID_VAL);
                    Interval ival_temp_v = new Interval(MDHr.INVALID_VAL, MDHr.INVALID_VAL);
                    foreach (DHr dhr in dhrs) {
                        float val_u = dhr.val(key_u);
                        float val_v = dhr.val(key_v);
                        if ((ival_temp_u.T0 == MDHr.INVALID_VAL) || (val_u < ival_temp_u.T0)) ival_temp_u.T0 = val_u;
                        if ((ival_temp_u.T1 == MDHr.INVALID_VAL) || (val_u > ival_temp_u.T1)) ival_temp_u.T1 = val_u;
                        if ((ival_temp_v.T0 == MDHr.INVALID_VAL) || (val_v < ival_temp_v.T0)) ival_temp_v.T0 = val_v;
                        if ((ival_temp_v.T1 == MDHr.INVALID_VAL) || (val_v > ival_temp_v.T1)) ival_temp_v.T1 = val_v;
                    }
                }

                bool cull_outliers = false;
                DA.GetData(5, ref cull_outliers);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hrsOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer> freqOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval2D> ivalsOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval2D>();

                if (ival_overall.U.IsDecreasing) ival_overall.U.Swap();
                if (ival_overall.V.IsDecreasing) ival_overall.V.Swap();
                double delta_u = ival_overall.U.Length / subdivs_u;
                double delta_v = ival_overall.V.Length / subdivs_v;
                for (int u = 0; u < subdivs_u; u++) {
                    for (int v = 0; v < subdivs_v; v++) {
                        Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(new int[] { u, v });
                        ivalsOut.EnsurePath(path);
                        hrsOut.EnsurePath(path);

                        Interval sub_u = new Interval(ival_overall.U.T0 + u * delta_u, ival_overall.U.T0 + ((u + 1) * delta_u));
                        Interval sub_v = new Interval(ival_overall.V.T0 + v * delta_v, ival_overall.V.T0 + ((v + 1) * delta_v));
                        Grasshopper.Kernel.Types.UVInterval sub_uv = new Grasshopper.Kernel.Types.UVInterval(sub_u, sub_v);
                        Grasshopper.Kernel.Types.GH_Interval2D i2d = new Grasshopper.Kernel.Types.GH_Interval2D();
                        i2d.Value = sub_uv;
                        ivalsOut.Append(i2d, path);
                    }
                }

                foreach (DHr dhr in dhrs) {
                    int[] address = new int[] { -1 , -1};
                    for (int u = 0; u < subdivs_u; u++)
                    {
                        Grasshopper.Kernel.Data.GH_Path path_u = new Grasshopper.Kernel.Data.GH_Path(new int[] { u, 0 });
                        Interval sub_u = ivalsOut.get_DataItem(path_u, 0).Value.U;
                        double val = dhr.val(key_u);
                        if ((sub_u.IncludesParameter(val)) || ((!cull_outliers) && (u == 0) && (val <= sub_u.Min)) || ((!cull_outliers) && (u == subdivs_u - 1) && (val >= sub_u.Max)))
                        {
                            address[0] = u;
                            break;
                        }
                    }

                    for (int v = 0; v < subdivs_v; v++)
                    {
                        Grasshopper.Kernel.Data.GH_Path path_v = new Grasshopper.Kernel.Data.GH_Path(new int[] { 0, v });
                        Interval sub_v = ivalsOut.get_DataItem(path_v, 0).Value.V;
                        double val = dhr.val(key_v);
                        if ((sub_v.IncludesParameter(val)) || ((!cull_outliers) && (v == 0) && (val <= sub_v.Min)) || ((!cull_outliers) && (v == subdivs_v - 1) && (val >= sub_v.Max)))
                        {
                            address[1] = v;
                            break;
                        }
                    }
                    if ((address[0] < 0) || (address[1] < 0))
                    {
                        if (!cull_outliers) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Crud. Could not place an outlier into any intervals.  What gives?!");
                    }
                    else
                    {
                        Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(address);
                        hrsOut.Append(dhr, path);
                    }
                }

                foreach (Grasshopper.Kernel.Data.GH_Path path in hrsOut.Paths)
                {
                    int n = hrsOut.get_Branch(path).Count;
                    freqOut.Append(new Grasshopper.Kernel.Types.GH_Integer(n), path);
                }

                DA.SetDataTree(0, freqOut);
                DA.SetDataTree(1, ivalsOut);
                DA.SetDataTree(2, hrsOut);
            }
        }
开发者ID:ksteinfe,项目名称:dyear,代码行数:99,代码来源:Components+Filter.cs


注:本文中的Interval.IncludesParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。