/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //字典立面的Key必须唯一,如何保证TempDict的Key值唯一? //调换Curve和Dict的顺序 //这里存在的一个bug Point3d Pt = default(Point3d); List <Curve> Crvs = new List <Curve>(); int Num = 1; Dictionary <Curve, double> _TempDict = new Dictionary <Curve, double>(); if (!DA.GetDataList <Curve>(0, Crvs)) { return; } if (!DA.GetData(1, ref Pt)) { return; } if (!DA.GetData(2, ref Num)) { return; } if (Num == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Num为0"); } double Param = 0; foreach (var Crv in Crvs) { if (Crv.ClosestPoint(Pt, out Param)) { Point3d TempPt = Crv.PointAt(Param); double Dist = Pt.DistanceTo(TempPt); _TempDict.Add(Crv, Dist); } } var ResultDict = _TempDict.OrderByDescending(item => - item.Value).ToDictionary(item => item.Key, item => item.Value); List <Curve> TempCrvs = ResultDict.Keys.ToList(); List <Curve> ResultCrvs = new List <Curve>(); if (TempCrvs.Count < Math.Abs(Num)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Num 数值过大"); return; } if (this.FindType == 0) { ResultCrvs = TempCrvs.GetRange(0, Math.Abs(Num)); } else { ResultCrvs = TempCrvs.GetRange(TempCrvs.Count - Num - 1, TempCrvs.Count); } DA.SetDataList(0, ResultCrvs); }
public Point3d[] PointsAt(Percent[] ps) { double[] ts = T(ps); return(ts.Select(o => Crv.PointAt(o)).ToArray()); }
public Point3d PointAt(CurveEnd end) { return(Crv.PointAt(T(end))); }
public Point3d PointAt(Percent p) { return(Crv.PointAt(T(p))); }