From: DannyRS
Something like this is what I've been trying but it takes way to long to be practical in most uses, if there are alot of TPA results
Was considering some kind of tradeoff and finding the middle of the two ATPA boxes and checking if they are within X distance from each other and then doing the calculation for those boxes? Might still take a long time if both ATPA's have alot of boxes
Function ATPAIntersections(ATPAOne, ATPATwo: T2DPointArray): TPointArray;
var
I, J, K, L, Index: Integer;
Begin
For I := 0 To High(ATPAOne) Do
For K := 0 To High(ATPAOne[I]) Do
For J := 0 To High(ATPATwo) Do
For L := 0 To High(ATPATwo[J]) Do
If (ATPAOne[I][K] = ATPATwo[J][L]) Then
Begin
SetLength(Result, Index + 1);
Result[Index] := ATPAOne[I][K];
Inc(Index);
End;
End;
var
ATPAOne, ATPATwo: T2DPointArray;
begin
ATPAOne := [TPointArray([Point(0, 0), Point(1, 1)]), TPointArray([Point(10, 10), Point(11, 11), Point(14, 0), Point(20, 20), Point(12, 12)])];
ATPATwo := [TPointArray([Point(0, 0), Point(1, 1)]), TPointArray([Point(10, 10), Point(11, 11), Point(12, 12), Point(13, 13)])];
writeln(ATPAIntersections(ATPAOne, ATPATwo));
end.
You can easily change the result to a TBoxArray and it'll hold a list of all boxes that intersect.. I chose to leave it as a TPA.. You get a list of all points that are in both ATPA's. I see it as more useful than the boxes.
The two ATPA's can also be of different sizes/lengths.
Seems pretty fast to me :S