Browse Source

* small cleanups in intersectrect,unionrect offsetrect and inflaterect; fixes #40436

marcoonthegit 1 year ago
parent
commit
117094b540
1 changed files with 22 additions and 40 deletions
  1. 22 40
      rtl/objpas/types.pp

+ 22 - 40
rtl/objpas/types.pp

@@ -563,16 +563,11 @@ begin
   // The var parameter is only assigned in the end to avoid problems
   // when passing the same rectangle in the var and const parameters.
   // See http://bugs.freepascal.org/view.php?id=17722
-  if IsRectEmpty(lRect) then
-  begin
-    FillChar(Rect,SizeOf(Rect),0);
-    IntersectRect:=false;
-  end
+  Result:=not IsRectEmpty(lRect);
+  if Result then
+    Rect := lRect
   else
-  begin
-    IntersectRect:=true;
-    Rect := lRect;
-  end;	
+    FillChar(Rect,SizeOf(Rect),0);
 end;
 
 function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
@@ -589,16 +584,11 @@ begin
   if R2.Bottom>R1.Bottom then
     lRect.Bottom:=R2.Bottom;
 
-  if IsRectEmpty(lRect) then
-  begin
-    FillChar(Rect,SizeOf(Rect),0);
-    UnionRect:=false;
-  end
+  Result:=not IsRectEmpty(lRect);
+  if Result then
+    Rect := lRect
   else
-  begin
-    Rect:=lRect;
-    UnionRect:=true;
-  end;
+    FillChar(Rect,SizeOf(Rect),0);
 end;
 
 function IsRectEmpty(const Rect : TRect) : Boolean;
@@ -608,19 +598,15 @@ end;
 
 function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
 begin
-  if assigned(@Rect) then
-    begin
+  Result:=assigned(@Rect);
+  if Result then
     with Rect do
       begin
-      inc(Left,dx);
-      inc(Top,dy);
-      inc(Right,dx);
-      inc(Bottom,dy);
+        inc(Left,dx);
+        inc(Top,dy);
+        inc(Right,dx);
+        inc(Bottom,dy);
       end;
-    OffsetRect:=true;
-    end
-  else
-    OffsetRect:=false;
 end;
 
 function Avg(a, b: Longint): Longint;
@@ -642,19 +628,15 @@ end;
 
 function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
 begin
-  if Assigned(@Rect) then
-  begin
+  Result:=assigned(@Rect);
+  if Result then
     with Rect do
-    begin
-      dec(Left, dx);
-      dec(Top, dy);
-      inc(Right, dx);
-      inc(Bottom, dy);
-    end;
-    Result := True;
-  end
-  else
-    Result := False;
+      begin
+        dec(Left, dx);
+        dec(Top, dy);
+        inc(Right, dx);
+        inc(Bottom, dy);
+      end;
 end;
 
 function Size(AWidth, AHeight: Integer): TSize; inline;