diff --git a/PamhagenSysCtrl/Helpers/Pipeline/Graph.cs b/PamhagenSysCtrl/Helpers/Pipeline/Graph.cs index 5e5f79d..baeb3ae 100644 --- a/PamhagenSysCtrl/Helpers/Pipeline/Graph.cs +++ b/PamhagenSysCtrl/Helpers/Pipeline/Graph.cs @@ -55,14 +55,18 @@ namespace PamhagenSysCtrl.Helpers.Pipeline { } public Path? GetPath(IEnumerable points, Func? valid = null) { - if (points.Count() < 2) throw new ArgumentException("Path is too short"); + if (points.Count() < 2) return null; var start = points.First(); var path = new Path(start, []); foreach (var end in points.Skip(1)) { - if (GetPath(start, end, valid, visited: [..path.Hops.Select(h => h.Node)]) is not Path p) + if (valid != null && !valid(start)) { return null; - path.Hops = [..path.Hops, ..p.Hops]; - start = end; + } else if (GetPath(start, end, valid, visited: [.. path.Hops.Select(h => h.Node)]) is not Path p) { + return null; + } else { + path.Hops = [.. path.Hops, .. p.Hops]; + start = end; + } } return path; }