Object TRectangle

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TRectangle = object(TObject)

Description

2D rectangle with integer coordinates. Useful for various 2D GUI operations.

The area covered by the rectangle starts in (Left,Bottom) pixel and spans (Width,Height) pixels. This means that the right-top pixel covered by the rectangle is (Left + Width - 1,Bottom + Height - 1). The rectangle is empty (Contains will always answer False) when either Width or Height are zero.

Hierarchy

  • TObject
  • TRectangle

Overview

Fields

Public Left: Integer;
Public Bottom: Integer;
Public Width: Cardinal;
Public Height: Cardinal;
Public internal const Empty: TRectangle = (Left: 0; Bottom: 0; Width: 0; Height: 0);

Methods

Public function Contains(const X, Y: Integer): boolean;
Public function Contains(const Point: TVector2Single): boolean;
Public function Center(const W, H: Cardinal): TRectangle;
Public function Grow(const Delta: Integer): TRectangle;
Public function Grow(const DeltaX, DeltaY: Integer): TRectangle;
Public function RemoveLeft(W: Cardinal): TRectangle;
Public function RemoveBottom(H: Cardinal): TRectangle;
Public function RemoveRight(W: Cardinal): TRectangle;
Public function RemoveTop(H: Cardinal): TRectangle;
Public function GrowLeft(const W: Cardinal): TRectangle;
Public function GrowBottom(const H: Cardinal): TRectangle;
Public function GrowRight(const W: Cardinal): TRectangle;
Public function GrowTop(const H: Cardinal): TRectangle;
Public function LeftPart(W: Cardinal): TRectangle;
Public function BottomPart(H: Cardinal): TRectangle;
Public function RightPart(W: Cardinal): TRectangle;
Public function TopPart(H: Cardinal): TRectangle;

Properties

Public property Right: Integer read GetRight;
Public property Top: Integer read GetTop;
Public property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;

Description

Fields

Public Left: Integer;
 
Public Bottom: Integer;
 
Public Width: Cardinal;
 
Public Height: Cardinal;
 
Public internal const Empty: TRectangle = (Left: 0; Bottom: 0; Width: 0; Height: 0);
 

Methods

Public function Contains(const X, Y: Integer): boolean;
 
Public function Contains(const Point: TVector2Single): boolean;
 
Public function Center(const W, H: Cardinal): TRectangle;

Return rectangle with given width and height centered in the middle of this rectangle. The given W, H may be smaller or larger than this rectangle sizes.

Public function Grow(const Delta: Integer): TRectangle;

Grow (when Delta > 0) or shrink (when Delta < 0) the rectangle, returning new value. This adds a margin of Delta pixels around all sides of the rectangle, so in total width grows by 2 * Delta, and the same for height. In case of shrinking, we protect from shrinking too much: the resulting width or height is set to zero (which makes a valid and empty rectangle) if shrinking too much.

Public function Grow(const DeltaX, DeltaY: Integer): TRectangle;
 
Public function RemoveLeft(W: Cardinal): TRectangle;

Returns the rectangle with a number of pixels from given side removed. Returns an empty rectangle if you try to remove too much.

Public function RemoveBottom(H: Cardinal): TRectangle;
 
Public function RemoveRight(W: Cardinal): TRectangle;
 
Public function RemoveTop(H: Cardinal): TRectangle;
 
Public function GrowLeft(const W: Cardinal): TRectangle;

Returns the rectangle with a number of pixels on given side added.

Public function GrowBottom(const H: Cardinal): TRectangle;
 
Public function GrowRight(const W: Cardinal): TRectangle;
 
Public function GrowTop(const H: Cardinal): TRectangle;
 
Public function LeftPart(W: Cardinal): TRectangle;

Returns the given side of the rectangle, cut down to given number of pixels from given side. This is similar to RemoveXxx methods, but here you specify which side to keep, as opposed to RemoveXxx methods where you specify which side you remove.

If the requested size is larger than current size (for example, W > Width for LeftPart) then the unmodified rectangle is returned.

Public function BottomPart(H: Cardinal): TRectangle;
 
Public function RightPart(W: Cardinal): TRectangle;
 
Public function TopPart(H: Cardinal): TRectangle;
 

Properties

Public property Right: Integer read GetRight;

Right and Top pixels are 1 pixel *outside* of the rectangle.

Public property Top: Integer read GetTop;
 
Public property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;
 

Generated by PasDoc 0.13.0 on 2014-10-26 05:15:14