本文整理汇总了C#中Interval.Swap方法的典型用法代码示例。如果您正苦于以下问题:C# Interval.Swap方法的具体用法?C# Interval.Swap怎么用?C# Interval.Swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interval
的用法示例。
在下文中一共展示了Interval.Swap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveInstance
protected override void SolveInstance(IGH_DataAccess DA)
{
Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
string key = "";
int subdivs = 0;
if ((DA.GetDataTree(0, out hourTreeIn)) && (DA.GetData(1, ref key)) && (DA.GetData(3, ref subdivs)))
{
Interval ival_overall = new Interval();
if (!DA.GetData(2, ref ival_overall)) {
// go thru the given hours and find the max and min value for the given key
ival_overall.T0 = MDHr.INVALID_VAL;
ival_overall.T1 = MDHr.INVALID_VAL;
foreach (DHr dhr in hourTreeIn.AllData(true)) {
float val = dhr.val(key);
if ((ival_overall.T0 == MDHr.INVALID_VAL) || (val < ival_overall.T0)) ival_overall.T0 = val;
if ((ival_overall.T1 == MDHr.INVALID_VAL) || (val > ival_overall.T1)) ival_overall.T1 = val;
}
}
Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer> freqTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer>();
Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval> ivalTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval>();
List<Interval> ivalList = new List<Interval>();
if (ival_overall.IsDecreasing) ival_overall.Swap();
double delta = ival_overall.Length / subdivs;
for (int n = 0; n < subdivs; n++) { ivalList.Add(new Interval(ival_overall.T0 + n * delta, ival_overall.T0 + ((n + 1) * delta))); }
for (int b = 0; b < hourTreeIn.Branches.Count; b++)
{
Grasshopper.Kernel.Data.GH_Structure<DHr> hourBranch = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
for (int n = 0; n < subdivs; n++) { hourBranch.EnsurePath(n); }
List<int> freqOut = new List<int>();
List<DHr> hrsIn = hourTreeIn.Branches[b];
foreach (DHr dhr in hrsIn)
{
if (dhr.val(key) < ivalList[0].T0)
{
hourBranch.Append(dhr, new Grasshopper.Kernel.Data.GH_Path(0));
continue;
}
if (dhr.val(key) > ivalList[ivalList.Count - 1].T1)
{
hourBranch.Append(dhr, new Grasshopper.Kernel.Data.GH_Path(ivalList.Count - 1));
continue;
}
for (int n = 0; n < subdivs; n++)
{
if (ivalList[n].IncludesParameter(dhr.val(key)))
{
hourBranch.Append(dhr,new Grasshopper.Kernel.Data.GH_Path(n));
break;
}
}
}
for (int bb = 0; bb < hourBranch.Branches.Count; bb++)
{
Grasshopper.Kernel.Data.GH_Path branch_path = hourTreeIn.Paths[b].AppendElement(bb);
hourTreeOut.AppendRange(hourBranch.Branches[bb], branch_path);
Grasshopper.Kernel.Types.GH_Integer freq = new Grasshopper.Kernel.Types.GH_Integer(hourBranch.Branches[bb].Count);
freqTreeOut.Append(freq, branch_path);
Grasshopper.Kernel.Types.GH_Interval ival = new Grasshopper.Kernel.Types.GH_Interval(ivalList[bb]);
ivalTreeOut.Append(ival, branch_path);
}
}
hourTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);
freqTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);
ivalTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);
DA.SetDataTree(0, freqTreeOut);
DA.SetDataTree(1, ivalTreeOut);
DA.SetDataTree(2, hourTreeOut);
}
}