Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$I SRL/osr.simba}
- type TInt64Array = array of Int64;
- {$X+}
- procedure Quick64Sort(a:TInt64Array; ilo, ihi:Int32);
- begin
- var lo := ilo;
- var hi := ihi;
- var pivot := a[(lo + hi) div 2];
- while True do
- begin
- while(a[lo] < pivot) do lo += 1;
- while(a[hi] > pivot) do hi -= 1;
- if lo <= hi then
- begin
- var tmp := a[lo];
- a[lo] := a[hi];
- a[hi] := tmp;
- lo += 1;
- hi -= 1;
- end;
- if (lo > hi) then break;
- end;
- if(hi > ilo) then Quick64Sort(a, ilo, hi)
- if(lo < ihi) then Quick64Sort(a, lo, ihi)
- end
- function BinarySearch(value: Int64; list: TInt64Array): Int32;
- begin
- var l := Low(list);
- var h := High(list);
- Result := -1;
- while l <= h do
- begin
- var m := (l + h) div 2;
- if list[m] > value then h := m - 1
- else if list[m] < value then l := m + 1
- else Exit(m);
- end;
- end;
- {$X-}
- function Intersection(A,B: TPointArray): TPointArray;
- var
- i: Int32;
- aInt,bInt: TInt64Array;
- begin
- SetLength(aInt, Length(A));
- for i:=0 to High(A) do aInt[i] := Int64(A[i]);
- Quick64Sort(aInt, 0, High(aInt));
- SetLength(bInt, Length(B));
- for i:=0 to High(B) do bInt[i] := Int64(B[i]);
- Quick64Sort(bInt, 0, High(bInt));
- for i:=0 to High(aInt) do
- if BinarySearch(aInt[i], bInt) <> -1 then
- Result += TPoint(aInt[i]);
- end;
- var
- a,b,c: TPointArray;
- img: TMufasaBitmap;
- t: Double;
- begin
- a := TPAFromBox([100,100,300,300]);
- b := TPAFromBox([200,200,400,400]);
- WriteLn(Length(a) + Length(b));
- t := PerformanceTimer();
- c := Intersection(A,B);
- WriteLn(PerformanceTimer() - t,'ms');
- img.Init();
- img.SetSize(600,600);
- img.DrawTPA(a, 255);
- img.DrawTPA(b, $FF0000);
- img.DrawTPA(c, $00FF00);
- img.Debug();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement