Record TRectangle

Unit

Declaration

type TRectangle = record

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. Neither Width nor Height can ever be negative.

Overview

Fields

Public Left: Integer;
Public Bottom: Integer;
Public Width: Cardinal;
Public Height: Cardinal;

Methods

Public class function Empty: TRectangle; static; inline;
Public function IsEmpty: Boolean;
Public function Contains(const X, Y: Integer): Boolean; overload;
Public function Contains(const Point: TVector2): Boolean; overload;
Public function Contains(const Point: TVector2Integer): Boolean; overload;
Public function CenterInside(const W, H: Cardinal): TRectangle;
Public function Grow(const Delta: Integer): TRectangle; overload;
Public function Grow(const DeltaX, DeltaY: Integer): TRectangle; overload;
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;
Public function Middle: TVector2Integer; deprecated 'use Center';
Public function Center: TVector2Integer;
Public function ClampX(const X: Integer): Integer;
Public function ClampY(const Y: Integer): Integer;
Public function ScaleToWidth(const NewWidth: Cardinal): TRectangle;
Public function ScaleToHeight(const NewHeight: Cardinal): TRectangle;
Public function ScaleAroundCenter(const Factor: Single): TRectangle;
Public function ScaleAroundMiddle(const Factor: Single): TRectangle; deprecated 'use ScaleAroundCenter';
Public function ScaleAround0(const Factor: Single): TRectangle;
Public function ScaleWidthAround0(const Factor: Single): Cardinal;
Public function ScaleHeightAround0(const Factor: Single): Cardinal;
Public function FitInside(const R: TRectangle; const AlignHorizontal: THorizontalPosition = hpMiddle; const AlignVertical: TVerticalPosition = vpMiddle): TRectangle;
Public function AlignCore( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): Integer; overload;
Public function Align( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): TRectangle; overload;
Public function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): Integer; overload;
Public function Align( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): TRectangle; overload;
Public function ToString: string;
Public function Translate(const V: TVector2Integer): TRectangle;
Public function Collides(const R: TRectangle): Boolean;
Public class operator + (const R1, R2: TRectangle): TRectangle;
Public class operator * (const R1, R2: TRectangle): TRectangle;
Public function Equals(const R: TRectangle): Boolean;

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;

This item has no description.

Public Bottom: Integer;

This item has no description.

Public Width: Cardinal;

This item has no description.

Public Height: Cardinal;

This item has no description.

Methods

Public class function Empty: TRectangle; static; inline;

This item has no description.

Public function IsEmpty: Boolean;

This item has no description.

Public function Contains(const X, Y: Integer): Boolean; overload;

This item has no description.

Public function Contains(const Point: TVector2): Boolean; overload;

This item has no description.

Public function Contains(const Point: TVector2Integer): Boolean; overload;

This item has no description.

Public function CenterInside(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; overload;

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; overload;

This item has no description.

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;

This item has no description.

Public function RemoveRight(W: Cardinal): TRectangle;

This item has no description.

Public function RemoveTop(H: Cardinal): TRectangle;

This item has no description.

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;

This item has no description.

Public function GrowRight(const W: Cardinal): TRectangle;

This item has no description.

Public function GrowTop(const H: Cardinal): TRectangle;

This item has no description.

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;

This item has no description.

Public function RightPart(W: Cardinal): TRectangle;

This item has no description.

Public function TopPart(H: Cardinal): TRectangle;

This item has no description.

Public function Middle: TVector2Integer; deprecated 'use Center';

Warning: this symbol is deprecated: use Center

This item has no description.

Public function Center: TVector2Integer;

This item has no description.

Public function ClampX(const X: Integer): Integer;

Clamp value to be within allowed horizontal range. That is, clamp to [Left, Right - 1].

Public function ClampY(const Y: Integer): Integer;

Clamp value to be within allowed vertical range. That is, clamp to [Bottom, Top - 1].

Public function ScaleToWidth(const NewWidth: Cardinal): TRectangle;

This item has no description.

Public function ScaleToHeight(const NewHeight: Cardinal): TRectangle;

This item has no description.

Public function ScaleAroundCenter(const Factor: Single): TRectangle;

Scale rectangle position and size around it's own Center point.

Since the scaling is independent in each axis, this handles "carefully" a half-empty rectangles (when one size is <= 0, but other is > 0). It scales correctly the positive dimension (not just returns Empty constant), leaving the other dimension (it's position and size) untouched.

Public function ScaleAroundMiddle(const Factor: Single): TRectangle; deprecated 'use ScaleAroundCenter';

Warning: this symbol is deprecated: use ScaleAroundCenter

This item has no description.

Public function ScaleAround0(const Factor: Single): TRectangle;

Scale rectangle position and size around the (0,0) point.

Since the scaling is independent in each axis, this handles "carefully" a half-empty rectangles (when one size is <= 0, but other is > 0). It scales correctly the positive dimension (not just returns Empty constant), leaving the other dimension (it's position and size) untouched.

These details matter, e.g. when you set TCastleUserInterface.Width, but not TCastleUserInterface.Height, and then you expect the TCastleUserInterface.EffectiveWidth to work.

Public function ScaleWidthAround0(const Factor: Single): Cardinal;

Scale Width, in the same manner as ScaleAround0 would do.

Public function ScaleHeightAround0(const Factor: Single): Cardinal;

Scale Height, in the same manner as ScaleAround0 would do.

Public function FitInside(const R: TRectangle; const AlignHorizontal: THorizontalPosition = hpMiddle; const AlignVertical: TVerticalPosition = vpMiddle): TRectangle;

Scale and align us to fit inside rectangle R, preserving our aspect ratio.

Public function AlignCore( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): Integer; overload;

Align this rectangle within other rectangle by calculating new value for Left.

Public function Align( const ThisPosition: THorizontalPosition; const OtherRect: TRectangle; const OtherPosition: THorizontalPosition; const X: Integer = 0): TRectangle; overload;

This item has no description.

Public function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): Integer; overload;

Align this rectangle within other rectangle by calculating new value for Bottom.

Public function Align( const ThisPosition: TVerticalPosition; const OtherRect: TRectangle; const OtherPosition: TVerticalPosition; const Y: Integer = 0): TRectangle; overload;

This item has no description.

Public function ToString: string;

This item has no description.

Public function Translate(const V: TVector2Integer): TRectangle;

Move the rectangle. Empty rectangle after moving is still an empty rectangle.

Public function Collides(const R: TRectangle): Boolean;

Does it have any common part with another rectangle.

Public class operator + (const R1, R2: TRectangle): TRectangle;

Sum of the two rectangles is a bounding rectangle - a smallest rectangle that contains them both.

Public class operator * (const R1, R2: TRectangle): TRectangle;

Common part of the two rectangles.

Public function Equals(const R: TRectangle): Boolean;

This item has no description.

Properties

Public property Right: Integer read GetRight;

Right and top coordinates of the rectangle. Right is simply the Left + Width, Top is simply the Bottom + Height.

If you use this for drawing, note that the pixel with coordinates (Right, Top) is actually *outside* of the rectangle (by 1 pixel). That's because the rectangle starts at pixel (Left, Bottom) and spans the (Width, Height) pixels.

Public property Top: Integer read GetTop;

This item has no description.

Public property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;

This item has no description.


Generated by PasDoc 0.16.0-snapshot.