Skip to content

Commit 23754ec

Browse files
committed
Fix kdtree: jump-to-next-node for flagmatch
Flags was implemented poorly in RangeQueries, smacked some gotos on there to jump ahead to next node. We cant exit here!
1 parent 03dafe8 commit 23754ec

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Source/simba.container_kdtree.pas

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ function TKDTree.RangeQuery(Low, High: TSingleArray; Setting: TTreeSettings = []
496496
This: PKDNode;
497497
Axis: Integer;
498498
i: Integer;
499+
label
500+
NextNode;
499501
begin
500502
if Node = NONE then Exit;
501503

@@ -509,11 +511,11 @@ function TKDTree.RangeQuery(Low, High: TSingleArray; Setting: TTreeSettings = []
509511

510512
if i = Self.Dimensions - 1 then // completed = within range
511513
begin
512-
if (tsIgnoreHidden in Setting) and This^.Hidden then
513-
Exit;
514+
if (not(tsIgnoreHidden in Setting)) and This^.Hidden then
515+
goto NextNode;
514516

515517
if (tsRefSensitive in Setting) and (This^.Split.Ref <> WorkingRef) then
516-
Exit;
518+
goto NextNode;
517519

518520
if ResultSize = Length(Result) then
519521
SetLength(Result, Length(Result) * 2);
@@ -526,6 +528,8 @@ function TKDTree.RangeQuery(Low, High: TSingleArray; Setting: TTreeSettings = []
526528
end;
527529
end;
528530

531+
NextNode:
532+
529533
if (Low[Axis] <= This^.Split.Vector[Axis]) then
530534
begin
531535
if (High[Axis] < This^.Split.Vector[Axis]) then
@@ -590,6 +594,8 @@ function TKDTree.RangeQueryEx(Center: TSingleArray; Radii: TSingleArray; Setting
590594
var
591595
This: PKDNode;
592596
Axis: Integer;
597+
label
598+
NextNode;
593599
begin
594600
if Node = NONE then Exit;
595601

@@ -598,11 +604,11 @@ function TKDTree.RangeQueryEx(Center: TSingleArray; Radii: TSingleArray; Setting
598604

599605
if Fits(This^.Split.Vector, Center) then
600606
begin
601-
if (tsIgnoreHidden in Setting) and This^.Hidden then
602-
Exit;
607+
if (not(tsIgnoreHidden in Setting)) and This^.Hidden then
608+
goto NextNode;
603609

604610
if (tsRefSensitive in Setting) and (This^.Split.Ref <> WorkingRef) then
605-
Exit;
611+
goto NextNode;
606612

607613
if ResultSize = Length(Result) then
608614
SetLength(Result, Length(Result) * 2);
@@ -614,6 +620,7 @@ function TKDTree.RangeQueryEx(Center: TSingleArray; Radii: TSingleArray; Setting
614620
This^.Hidden := True;
615621
end;
616622

623+
NextNode:
617624
if (Center[Axis] - Radii[Axis] <= This^.Split.Vector[Axis]) then
618625
Query(This^.L, Depth + 1);
619626

0 commit comments

Comments
 (0)