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.

Source: src/base/castlerectangles.pas (line 64).

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.

Source: src/base/castlerectangles.pas (line 84).

Public Bottom: Integer;

This item has no description.

Source: src/base/castlerectangles.pas (line 84).

Public Width: Cardinal;

This item has no description.

Source: src/base/castlerectangles.pas (line 85).

Public Height: Cardinal;

This item has no description.

Source: src/base/castlerectangles.pas (line 85).

Methods

Public class function Empty: TRectangle; static; inline;

This item has no description.

Source: src/base/castlerectangles.pas (line 87).

Public function IsEmpty: Boolean;

This item has no description.

Source: src/base/castlerectangles.pas (line 89).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 91).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 92).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 93).

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.

Source: src/base/castlerectangles.pas (line 111).

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.

Source: src/base/castlerectangles.pas (line 120).

Public function Grow(const DeltaX, DeltaY: Integer): TRectangle; overload;

This item has no description.

Source: src/base/castlerectangles.pas (line 121).

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.

Source: src/base/castlerectangles.pas (line 126).

Public function RemoveBottom(H: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 127).

Public function RemoveRight(W: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 128).

Public function RemoveTop(H: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 129).

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

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

Source: src/base/castlerectangles.pas (line 135).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 136).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 137).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 138).

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.

Source: src/base/castlerectangles.pas (line 150).

Public function BottomPart(H: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 151).

Public function RightPart(W: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 152).

Public function TopPart(H: Cardinal): TRectangle;

This item has no description.

Source: src/base/castlerectangles.pas (line 153).

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

Warning: this symbol is deprecated: use Center

This item has no description.

Source: src/base/castlerectangles.pas (line 157).

Public function Center: TVector2Integer;

This item has no description.

Source: src/base/castlerectangles.pas (line 158).

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

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

Source: src/base/castlerectangles.pas (line 162).

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

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

Source: src/base/castlerectangles.pas (line 166).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 168).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 169).

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.

Source: src/base/castlerectangles.pas (line 179).

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

Warning: this symbol is deprecated: use ScaleAroundCenter

This item has no description.

Source: src/base/castlerectangles.pas (line 180).

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.

Source: src/base/castlerectangles.pas (line 196).

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

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

Source: src/base/castlerectangles.pas (line 199).

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

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

Source: src/base/castlerectangles.pas (line 201).

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.

Source: src/base/castlerectangles.pas (line 204).

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.

Source: src/base/castlerectangles.pas (line 210).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 215).

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.

Source: src/base/castlerectangles.pas (line 223).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 228).

Public function ToString: string;

This item has no description.

Source: src/base/castlerectangles.pas (line 234).

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

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

Source: src/base/castlerectangles.pas (line 237).

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

Does it have any common part with another rectangle.

Source: src/base/castlerectangles.pas (line 240).

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

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

Source: src/base/castlerectangles.pas (line 244).

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

Common part of the two rectangles.

Source: src/base/castlerectangles.pas (line 247).

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

This item has no description.

Source: src/base/castlerectangles.pas (line 249).

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.

Source: src/base/castlerectangles.pas (line 104).

Public property Top: Integer read GetTop;

This item has no description.

Source: src/base/castlerectangles.pas (line 105).

Public property LeftBottom: TVector2Integer read GetLeftBottom write SetLeftBottom;

This item has no description.

Source: src/base/castlerectangles.pas (line 156).


Generated by PasDoc 0.17.0.snapshot.