Record TFloatRectangle

Unit

Declaration

type TFloatRectangle = record

Description

2D rectangle with float coordinates. Useful for various 2D GUI operations, and for bounding boxes for 2D objects.

The area covered by the rectangle starts at (Left,Bottom) position and spans (Width,Height) units. The rectangle is empty (Contains will always answer False) when either Width or Height are less than zero. This is consistent with it's 3D equivalent, TBox3D, and different from it's integer counterpart TRectangle. In case of float bounding box (TBox3D) or float rectangle (TFloatRectangle), having a zero size makes sense, and it still is something non-empty (a single 2D or 3D point has zero size, but it also still has a position).

Source: base/castlerectangles.pas (line 264).

Overview

Fields

Public Left: Single;
Public Bottom: Single;
Public Width: Single;
Public Height: Single;

Methods

Public class function Empty: TFloatRectangle; static; inline;
Public function IsEmpty: Boolean;
Public function Contains(const X, Y: Single): Boolean; overload;
Public function Contains(const Point: TVector2): Boolean; overload;
Public function Contains(const R: TFloatRectangle): Boolean; overload;
Public function Middle: TVector2; deprecated 'use Center';
Public function Center: TVector2;
Public function CenterInside(const W, H: Single): TFloatRectangle;
Public function Grow(const Delta: Single): TFloatRectangle; overload;
Public function Grow(const DeltaX, DeltaY: Single): TFloatRectangle; overload;
Public function RemoveLeft(W: Single): TFloatRectangle;
Public function RemoveBottom(H: Single): TFloatRectangle;
Public function RemoveRight(W: Single): TFloatRectangle;
Public function RemoveTop(H: Single): TFloatRectangle;
Public function GrowLeft(const W: Single): TFloatRectangle;
Public function GrowBottom(const H: Single): TFloatRectangle;
Public function GrowRight(const W: Single): TFloatRectangle;
Public function GrowTop(const H: Single): TFloatRectangle;
Public function LeftPart(W: Single): TFloatRectangle;
Public function BottomPart(H: Single): TFloatRectangle;
Public function RightPart(W: Single): TFloatRectangle;
Public function TopPart(H: Single): TFloatRectangle;
Public function AlignCore( const ThisPosition: THorizontalPosition; const OtherRect: TFloatRectangle; const OtherPosition: THorizontalPosition; const X: Single = 0): Single; overload;
Public function Align( const ThisPosition: THorizontalPosition; const OtherRect: TFloatRectangle; const OtherPosition: THorizontalPosition; const X: Single = 0): TFloatRectangle; overload;
Public function AlignCore( const ThisPosition: TVerticalPosition; const OtherRect: TFloatRectangle; const OtherPosition: TVerticalPosition; const Y: Single = 0): Single; overload;
Public function Align( const ThisPosition: TVerticalPosition; const OtherRect: TFloatRectangle; const OtherPosition: TVerticalPosition; const Y: Single = 0): TFloatRectangle; overload;
Public function ToString: string;
Public function Translate(const V: TVector2): TFloatRectangle;
Public function Collides(const R: TFloatRectangle): Boolean;
Public function CollidesDisc(const DiscCenter: TVector2; const Radius: Single): Boolean;
Public function ScaleToWidth(const NewWidth: Single): TFloatRectangle;
Public function ScaleToHeight(const NewHeight: Single): TFloatRectangle;
Public function ScaleAroundCenter(const Factor: Single): TFloatRectangle;
Public function ScaleAround0(const Factor: Single): TFloatRectangle;
Public function FitInside(const R: TFloatRectangle; const AlignHorizontal: THorizontalPosition = hpMiddle; const AlignVertical: TVerticalPosition = vpMiddle): TFloatRectangle;
Public function Include(const P: TVector2): TFloatRectangle;
Public function ToX3DVector: TVector4;
Public class function FromX3DVector(const V: TVector4): TFloatRectangle; static;
Public function Round: TRectangle;
Public function Equals(const R: TFloatRectangle): Boolean; overload;
Public function Equals(const R: TFloatRectangle; const Epsilon: Single): Boolean; overload;
Public function PerfectlyEquals(const R: TFloatRectangle): Boolean;
Public class operator + (const R1, R2: TFloatRectangle): TFloatRectangle;
Public class operator * (const R1, R2: TFloatRectangle): TFloatRectangle;
Public procedure AddToCoords(const Coords: TVector2List); overload;
Public procedure AddToCoords(const Coords: TVector3List; const Z: Single); overload;

Properties

Public property Right: Single read GetRight;
Public property Top: Single read GetTop;
Public property LeftBottom: TVector2 read GetLeftBottom write SetLeftBottom;
Public property Size: TVector2 read GetSize write SetSize;

Description

Fields

Public Left: Single;

This item has no description.

Source: base/castlerectangles.pas (line 278).

Public Bottom: Single;

This item has no description.

Source: base/castlerectangles.pas (line 278).

Public Width: Single;

This item has no description.

Source: base/castlerectangles.pas (line 279).

Public Height: Single;

This item has no description.

Source: base/castlerectangles.pas (line 279).

Methods

Public class function Empty: TFloatRectangle; static; inline;

This item has no description.

Source: base/castlerectangles.pas (line 281).

Public function IsEmpty: Boolean;

This item has no description.

Source: base/castlerectangles.pas (line 283).

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

This item has no description.

Source: base/castlerectangles.pas (line 285).

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

This item has no description.

Source: base/castlerectangles.pas (line 286).

Public function Contains(const R: TFloatRectangle): Boolean; overload;

This item has no description.

Source: base/castlerectangles.pas (line 287).

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

Warning: this symbol is deprecated: use Center

This item has no description.

Source: base/castlerectangles.pas (line 307).

Public function Center: TVector2;

This item has no description.

Source: base/castlerectangles.pas (line 308).

Public function CenterInside(const W, H: Single): TFloatRectangle;

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: base/castlerectangles.pas (line 313).

Public function Grow(const Delta: Single): TFloatRectangle; 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: base/castlerectangles.pas (line 322).

Public function Grow(const DeltaX, DeltaY: Single): TFloatRectangle; overload;

This item has no description.

Source: base/castlerectangles.pas (line 323).

Public function RemoveLeft(W: Single): TFloatRectangle;

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

Source: base/castlerectangles.pas (line 328).

Public function RemoveBottom(H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 329).

Public function RemoveRight(W: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 330).

Public function RemoveTop(H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 331).

Public function GrowLeft(const W: Single): TFloatRectangle;

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

Source: base/castlerectangles.pas (line 336).

Public function GrowBottom(const H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 337).

Public function GrowRight(const W: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 338).

Public function GrowTop(const H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 339).

Public function LeftPart(W: Single): TFloatRectangle;

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: base/castlerectangles.pas (line 351).

Public function BottomPart(H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 352).

Public function RightPart(W: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 353).

Public function TopPart(H: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 354).

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

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

Source: base/castlerectangles.pas (line 359).

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

This item has no description.

Source: base/castlerectangles.pas (line 364).

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

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

Source: base/castlerectangles.pas (line 372).

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

This item has no description.

Source: base/castlerectangles.pas (line 377).

Public function ToString: string;

This item has no description.

Source: base/castlerectangles.pas (line 383).

Public function Translate(const V: TVector2): TFloatRectangle;

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

Source: base/castlerectangles.pas (line 386).

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

Does it have any common part with another rectangle.

Source: base/castlerectangles.pas (line 389).

Public function CollidesDisc(const DiscCenter: TVector2; const Radius: Single): Boolean;

This item has no description.

Source: base/castlerectangles.pas (line 391).

Public function ScaleToWidth(const NewWidth: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 393).

Public function ScaleToHeight(const NewHeight: Single): TFloatRectangle;

This item has no description.

Source: base/castlerectangles.pas (line 394).

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

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: base/castlerectangles.pas (line 404).

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

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

Source: base/castlerectangles.pas (line 407).

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

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

Source: base/castlerectangles.pas (line 410).

Public function Include(const P: TVector2): TFloatRectangle;

Return larger rectangle, so that it includes given point.

Source: base/castlerectangles.pas (line 415).

Public function ToX3DVector: TVector4;

Convert to a 4D vector, like expected by X3D fields OrthoViewpoint.fieldOfView or DirectionalLight.projectionRectangle.

Source: base/castlerectangles.pas (line 419).

Public class function FromX3DVector(const V: TVector4): TFloatRectangle; static;

Convert from a 4D vector, like expected by X3D fields OrthoViewpoint.fieldOfView or DirectionalLight.projectionRectangle.

Source: base/castlerectangles.pas (line 423).

Public function Round: TRectangle;

Round rectangle coordinates, converting TFloatRectangle to TRectangle.

Source: base/castlerectangles.pas (line 426).

Public function Equals(const R: TFloatRectangle): Boolean; overload;

Is another rectangle equal to this one. Floating-point values are compared with an epsilon tolerance.

Source: base/castlerectangles.pas (line 430).

Public function Equals(const R: TFloatRectangle; const Epsilon: Single): Boolean; overload;

Is another rectangle equal to this one. Floating-point values are compared with an epsilon tolerance.

Source: base/castlerectangles.pas (line 434).

Public function PerfectlyEquals(const R: TFloatRectangle): Boolean;

Compare using exact comparison (without any epsilon to tolerate small float differences).

Source: base/castlerectangles.pas (line 437).

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

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

Source: base/castlerectangles.pas (line 441).

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

Common part of the two rectangles.

Source: base/castlerectangles.pas (line 444).

Public procedure AddToCoords(const Coords: TVector2List); overload;

Add 4 corners of this rectangle to the list, in CCW order, starting from left-bottom.

Source: base/castlerectangles.pas (line 451).

Public procedure AddToCoords(const Coords: TVector3List; const Z: Single); overload;

Add 4 corners of this rectangle to the list, in CCW order, starting from left-bottom. Set the Z coordinate of all added (3D) points to the one you specify by the Z parameter.

Source: base/castlerectangles.pas (line 455).

Properties

Public property Right: Single read GetRight;

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

Note: If you use this for drawing, and the values of Left, Bottom, Width, Height are actually integers (or close to integers), then the pixel with (Round(Right), Round(Top)) coordinates is actually *outside* of the rectangle (by 1 pixel). That's because the rectangle starts at the pixel (Round(Left), Round(Bottom)) and spans the (Round(Width), Round(Height)) pixels.

Source: base/castlerectangles.pas (line 302).

Public property Top: Single read GetTop;

This item has no description.

Source: base/castlerectangles.pas (line 303).

Public property LeftBottom: TVector2 read GetLeftBottom write SetLeftBottom;

This item has no description.

Source: base/castlerectangles.pas (line 306).

Public property Size: TVector2 read GetSize write SetSize;

Alternative way to access Width and Height. Name consistent with TBoxNode.Size, TBox3D.Size.

Source: base/castlerectangles.pas (line 448).


Generated by PasDoc 0.17.0.snapshot.