Changeset 342 for Generics/TemplateGenerics/Generic/GenericRectangle.inc
- Timestamp:
- Apr 3, 2012, 7:35:26 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/GenericRectangle.inc
r333 r342 11 11 function GetTopRight: TGRectanglePoint; 12 12 function GetWidth: TGRectangleDimension; 13 function GetEmpty: Boolean; 13 14 procedure SetBottom(const AValue: TGRectangleDimension); 14 15 procedure SetBottomLeft(const AValue: TGRectanglePoint); … … 21 22 procedure SetTopLeft(const AValue: TGRectanglePoint); 22 23 procedure SetTopRight(const AValue: TGRectanglePoint); 23 24 24 procedure SetWidth(const AValue: TGRectangleDimension); 25 procedure SetEmpty(const AValue: Boolean); 25 26 public 26 27 FLeft: TGRectangleDimension; … … 52 53 53 54 property Size: TGRectanglePoint read GetSize write SetSize; 55 property Empty: Boolean read GetEmpty write SetEmpty; 54 56 end; 55 57 … … 199 201 procedure TGRectangle.Intersect(Rect1, Rect2: TGRectangle); 200 202 begin 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; 205 210 end; 206 211 207 212 procedure TGRectangle.IntersectWith(Rect: TGRectangle); 208 213 begin 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; 213 221 end; 214 222 215 223 procedure TGRectangle.Union(Rect1, Rect2: TGRectangle); 216 224 begin 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; 221 234 end; 222 235 223 236 procedure TGRectangle.UnionWith(Rect: TGRectangle); 224 237 begin 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; 246 end; 247 248 function TGRectangle.GetEmpty: Boolean; 249 begin 250 Result := (Bottom <= Top) or (Right <= Left); 251 end; 252 253 procedure TGRectangle.SetEmpty(const AValue: Boolean); 254 begin 255 Top := 0; 256 Bottom := 0; 257 Left := 0; 258 Right := 0; 229 259 end; 230 260
Note:
See TracChangeset
for help on using the changeset viewer.