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).

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.

Public Bottom: Single;

This item has no description.

Public Width: Single;

This item has no description.

Public Height: Single;

This item has no description.

Methods

Public class function Empty: TFloatRectangle; static; inline;

This item has no description.

Public function IsEmpty: Boolean;

This item has no description.

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

This item has no description.

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

This item has no description.

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

This item has no description.

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

Warning: this symbol is deprecated: use Center

This item has no description.

Public function Center: TVector2;

This item has no description.

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.

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.

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

This item has no description.

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.

Public function RemoveBottom(H: Single): TFloatRectangle;

This item has no description.

Public function RemoveRight(W: Single): TFloatRectangle;

This item has no description.

Public function RemoveTop(H: Single): TFloatRectangle;

This item has no description.

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

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

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

This item has no description.

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

This item has no description.

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

This item has no description.

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.

Public function BottomPart(H: Single): TFloatRectangle;

This item has no description.

Public function RightPart(W: Single): TFloatRectangle;

This item has no description.

Public function TopPart(H: Single): TFloatRectangle;

This item has no description.

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.

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

This item has no description.

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.

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

This item has no description.

Public function ToString: string;

This item has no description.

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

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

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

Does it have any common part with another rectangle.

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

This item has no description.

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

This item has no description.

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

This item has no description.

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.

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

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

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.

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

Return larger rectangle, so that it includes given point.

Public function ToX3DVector: TVector4;

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

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

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

Public function Round: TRectangle;

Round rectangle coordinates, converting TFloatRectangle to TRectangle.

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

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

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.

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

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

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

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

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

Common part of the two rectangles.

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

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

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.

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.

Public property Top: Single read GetTop;

This item has no description.

Public property LeftBottom: TVector2 read GetLeftBottom write SetLeftBottom;

This item has no description.

Public property Size: TVector2 read GetSize write SetSize;

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


Generated by PasDoc 0.16.0-snapshot.