我正在尝试使用递归函数并输出结果值的列表。这是我想出的代码,但它给了我
错误(CS0161):'Script_Instance.wrapper(int,int,Grasshopper.DataTree,System.Collections.Generic.List)':并非所有代码路径都返回值(第 87 行)
public List<int> wrapper(int br, int depth, DataTree<int> topo, List<double> vals)
{
List<int> collection = new List<int>();
collection.Add(br);
if (depth > 0)
{
double[] area = new double[vals.Count - 1];
for (int i = 0;i < topo.Branches[br].Count;i++)
{
area[i] = vals[topo.Branch(br)[i]];
}
double Im = area.Max();
int IofMaxArea = area.ToList().IndexOf(Im);
collection.Add(IofMaxArea);
// wrapper(topo.Branch(br)[IofMaxArea], de, topo, vals);
wrapper(topo.Branch(br)[IofMaxArea], depth-1, topo, vals);
}
if (depth == 0)
{
return collection;
}
}
我正在尝试改进一个运行良好但对我的需要来说太慢的 python 脚本。这是python代码。
import Grasshopper.DataTree as ghdt
import ghpythonlib.components as ghcomp
import rhinoscriptsyntax as rs
newTree = ghdt[object]()
def wrapper(br,depth):
if depth>0:
area = []
for k in range(topo.Branch(br).Count):
ar = vals[topo.Branch(br)[k]]
#polygonC = rs.CloseCurve(polygon)
area.append(ar)
IofMaxArea = area.index(max(area))
collection.append([pts[topo.Branch(br)[IofMaxArea]],topo.Branch(br)[IofMaxArea]])
#[topo.Branch(br)[IofMaxArea]
wrapper(topo.Branch(br)[IofMaxArea],depth-1)
else: return None
def isovister(b,d):
global collection
collection = []
collection.append([pts[b],b])
wrapper(b,d)
return collection
if topo.Branch(item).Count !=0:
results = isovister(item,de)
a = tuple(x[0] for x in results)
b = tuple(x[1] for x in results)
else:
a = None
b = None
这是在 Rhino3d+Grasshopper 中。