Ignore:
Timestamp:
Apr 3, 2012, 7:35:26 AM (13 years ago)
Author:
chronos
Message:
  • Added: Update locking support for TGList.
  • Modified: Enhanced TGStream methods.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericRectangle.inc

    r333 r342  
    1111  function GetTopRight: TGRectanglePoint;
    1212  function GetWidth: TGRectangleDimension;
     13  function GetEmpty: Boolean;
    1314  procedure SetBottom(const AValue: TGRectangleDimension);
    1415  procedure SetBottomLeft(const AValue: TGRectanglePoint);
     
    2122  procedure SetTopLeft(const AValue: TGRectanglePoint);
    2223  procedure SetTopRight(const AValue: TGRectanglePoint);
    23 
    2424  procedure SetWidth(const AValue: TGRectangleDimension);
     25  procedure SetEmpty(const AValue: Boolean);
    2526public
    2627  FLeft: TGRectangleDimension;
     
    5253
    5354  property Size: TGRectanglePoint read GetSize write SetSize;
     55  property Empty: Boolean read GetEmpty write SetEmpty;
    5456end;
    5557
     
    199201procedure TGRectangle.Intersect(Rect1, Rect2: TGRectangle);
    200202begin
    201   Left := Max(Rect1.Left, Rect2.Left);
    202   Top := Max(Rect1.Top, Rect2.Top);
    203   Right := Min(Rect1.Right, Rect2.Right);
    204   Bottom := Min(Rect1.Bottom, Rect2.Bottom);
     203  if Rect1.Empty or Rect2.Empty then Empty := True
     204  else begin
     205    Left := Max(Rect1.Left, Rect2.Left);
     206    Top := Max(Rect1.Top, Rect2.Top);
     207    Right := Min(Rect1.Right, Rect2.Right);
     208    Bottom := Min(Rect1.Bottom, Rect2.Bottom);
     209  end;
    205210end;
    206211
    207212procedure TGRectangle.IntersectWith(Rect: TGRectangle);
    208213begin
    209   Left := Max(Left, Rect.Left);
    210   Top := Max(Top, Rect.Top);
    211   Right := Min(Right, Rect.Right);
    212   Bottom := Min(Bottom, Rect.Bottom);
     214  if Empty or Rect.Empty then Empty := True
     215  else begin
     216    Left := Max(Left, Rect.Left);
     217    Top := Max(Top, Rect.Top);
     218    Right := Min(Right, Rect.Right);
     219    Bottom := Min(Bottom, Rect.Bottom);
     220  end;
    213221end;
    214222
    215223procedure TGRectangle.Union(Rect1, Rect2: TGRectangle);
    216224begin
    217   Left := Min(Rect1.Left, Rect2.Left);
    218   Top := Min(Rect1.Top, Rect2.Top);
    219   Right := Max(Rect1.Right, Rect2.Right);
    220   Bottom := Max(Rect1.Bottom, Rect2.Bottom);
     225  if Rect1.Empty then Assign(Rect2)
     226  else
     227  if Rect2.Empty then Assign(Rect1)
     228  else begin
     229    Left := Min(Rect1.Left, Rect2.Left);
     230    Top := Min(Rect1.Top, Rect2.Top);
     231    Right := Max(Rect1.Right, Rect2.Right);
     232    Bottom := Max(Rect1.Bottom, Rect2.Bottom);
     233  end;
    221234end;
    222235
    223236procedure TGRectangle.UnionWith(Rect: TGRectangle);
    224237begin
    225   Left := Min(Left, Rect.Left);
    226   Top := Min(Top, Rect.Top);
    227   Right := Max(Right, Rect.Right);
    228   Bottom := Max(Bottom, Rect.Bottom);
     238  if Empty then Assign(Rect)
     239  else
     240  if not Rect.Empty then begin
     241    Left := Min(Left, Rect.Left);
     242    Top := Min(Top, Rect.Top);
     243    Right := Max(Right, Rect.Right);
     244    Bottom := Max(Bottom, Rect.Bottom);
     245  end;
     246end;
     247
     248function TGRectangle.GetEmpty: Boolean;
     249begin
     250  Result := (Bottom <= Top) or (Right <= Left);
     251end;
     252
     253procedure TGRectangle.SetEmpty(const AValue: Boolean);
     254begin
     255  Top := 0;
     256  Bottom := 0;
     257  Left := 0;
     258  Right := 0;
    229259end;
    230260
Note: See TracChangeset for help on using the changeset viewer.