Esempio n. 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var curves = new List <Curve>();
            var lines  = new List <Line>();

            if (DA.GetDataList(0, curves) && DA.GetDataList(1, lines))
            {
                curves.RemoveAll(_removeNullAndInvalidDelegate);
                lines.RemoveAll(_removeInvalidDelegate);

                if (curves.Count < 1)
                {
                    return;
                }

                CurvesTopology top = new CurvesTopology(curves, GH_Component.DocumentTolerance());

                var distances = top.MeasureAllEdgeLengths();

                List <Curve> result = new List <Curve>();

                for (int i = 0; i < lines.Count; i++)
                {
                    var line = lines[i];

                    int fromIndex = top.GetClosestNode(line.From);
                    int toIndex   = top.GetClosestNode(line.To);

                    if (fromIndex == toIndex)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The start and end positions are equal");
                        result.Add(null);
                        continue;
                    }

                    var pathSearch = new AStar(top, distances);
                    var current    = pathSearch.Cross(fromIndex, toIndex);

                    if (current == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                          string.Format("No walk found for line at position {0}. Are end points isolated?", i.ToString()));
                    }
                    result.Add(current);
                }

                DA.SetDataList(0, result);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var curves = new List<Curve>();
            var lines = new List<Line>();

            if (DA.GetDataList(0, curves) && DA.GetDataList(1, lines))
            {
                curves.RemoveAll(_removeNullAndInvalidDelegate);
                lines.RemoveAll(_removeInvalidDelegate);

                if (curves.Count < 1)
                    return;

                CurvesTopology top = new CurvesTopology(curves, GH_Component.DocumentTolerance());

                var distances = top.MeasureAllEdgeLengths();

                List<Curve> result = new List<Curve>();

                for (int i = 0; i < lines.Count; i++)
                {
                    var line = lines[i];

                    int fromIndex = top.GetClosestNode(line.From);
                    int toIndex = top.GetClosestNode(line.To);

                    if (fromIndex == toIndex)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The start and end positions are equal");
                        result.Add(null);
                        continue;
                    }

                    var pathSearch = new AStar(top, distances);
                    var current = pathSearch.Cross(fromIndex, toIndex);

                    if (current == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                            string.Format("No walk found for line at position {0}. Are end points isolated?", i.ToString()));
                    }
                    result.Add(current);
                }

                DA.SetDataList(0, result);
            }
        }