141141
142142function TWebGraph.NearNodesIndices(pt: TPoint; amount: Integer): TIntegerArray;
143143var
144- i: Integer;
144+ i, n : Integer;
145145 weights: TDoubleArray;
146146 tpa: TPointArray;
147147begin
@@ -150,14 +150,18 @@ begin
150150 for i := 0 to High(tpa) do
151151 if Self.WalkableClusters.InSameTPA(pt, tpa[i]) then
152152 begin
153- Result += Self.Nodes.IndexOf(tpa[i]);
153+ n := Self.Nodes.IndexOf(tpa[i]);
154+ if n = -1 then Continue;
155+ Result += n;
154156 weights += pt.DistanceTo(tpa[i]);
155157 end;
156158
157159 if Result = [] then
158160 for i := 0 to High(tpa) do
159161 begin
160- Result += Self.Nodes.IndexOf(tpa[i]);
162+ n := Self.Nodes.IndexOf(tpa[i]);
163+ if n = -1 then Continue;
164+ Result += n;
161165 weights += pt.DistanceTo(tpa[i]);
162166 end;
163167
@@ -236,21 +240,29 @@ begin
236240
237241 nodeA := [a, EGraphNode.NORMAL];
238242 nodeB := [b, EGraphNode.NORMAL];
243+
239244 if nS[0] = nG[0] then
240245 Exit([nodeA, nodeB]);
241246
247+
242248 if (Length(nG) = 1) and (Self.Paths[nG[0]] = []) then
243- raise GetDebugLn('WebGraph', 'Points ' + ToStr(a) + ' and ' + ToStr(b) + ' don''t connect!');
249+ raise GetDebugLn('WebGraph', 'Points ' + ToStr(a) + ' and ' + ToStr(b) + ' don''t connect! No paths available. ');
244250
245251 for i := 0 to High(nS) do
252+ begin
253+ if nS[i] = -1 then
254+ Continue;
246255 for j := 0 to High(nG) do
247256 begin
248- if nS[i ] = nG[j] then
257+ if nG[j ] = -1 then
249258 Continue;
259+ if nS[i] = nG[j] then Continue;
260+
250261 indices := Self.FindPath(nS[i],nG[j], rnd);
251262 if Length(indices) > 0 then
252263 Break(2);
253264 end;
265+ end;
254266
255267 if Length(indices) = 0 then
256268 raise GetDebugLn('WebGraph', 'Points ' + ToStr(a) + ' and ' + ToStr(b) + ' don''t connect!');
0 commit comments