mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-22 04:41:34 +02:00
Makes IntersectRect more efficient
git-svn-id: trunk@16226 -
This commit is contained in:
parent
b4b9354468
commit
3c2a94fad3
@ -345,31 +345,31 @@ end;
|
|||||||
|
|
||||||
function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
|
function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
|
||||||
var
|
var
|
||||||
lR1, lR2: TRect;
|
lRect: TRect;
|
||||||
begin
|
begin
|
||||||
// We copy the parameter to a local variables to avoid problems
|
lRect := R1;
|
||||||
|
if R2.Left > R1.Left then
|
||||||
|
lRect.Left := R2.Left;
|
||||||
|
if R2.Top > R1.Top then
|
||||||
|
lRect.Top := R2.Top;
|
||||||
|
if R2.Right < R1.Right then
|
||||||
|
lRect.Right := R2.Right;
|
||||||
|
if R2.Bottom < R1.Bottom then
|
||||||
|
lRect.Bottom := R2.Bottom;
|
||||||
|
|
||||||
|
// The var parameter is only assigned in the end to avoid problems
|
||||||
// when passing the same rectangle in the var and const parameters.
|
// when passing the same rectangle in the var and const parameters.
|
||||||
// See http://bugs.freepascal.org/view.php?id=17722
|
// See http://bugs.freepascal.org/view.php?id=17722
|
||||||
lR1 := R1;
|
if IsRectEmpty(lRect) then
|
||||||
lR2 := R2;
|
|
||||||
|
|
||||||
Rect := lR1;
|
|
||||||
if lR2.Left > lR1.Left then
|
|
||||||
Rect.Left := lR2.Left;
|
|
||||||
if lR2.Top > R1.Top then
|
|
||||||
Rect.Top := lR2.Top;
|
|
||||||
if lR2.Right < R1.Right then
|
|
||||||
Rect.Right := lR2.Right;
|
|
||||||
if lR2.Bottom < R1.Bottom then
|
|
||||||
Rect.Bottom := lR2.Bottom;
|
|
||||||
|
|
||||||
if IsRectEmpty(Rect) then
|
|
||||||
begin
|
begin
|
||||||
FillChar(Rect,SizeOf(Rect),0);
|
FillChar(Rect,SizeOf(Rect),0);
|
||||||
IntersectRect:=false;
|
IntersectRect:=false;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
IntersectRect:=true;
|
IntersectRect:=true;
|
||||||
|
Rect := lRect;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
|
function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user