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

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

Methods

class function Empty: TFloatRectangle; static; inline;
function IsEmpty: boolean;
function Contains(const X, Y: Single): boolean; overload;
function Contains(const Point: TVector2): boolean; overload;
function Middle: TVector2; deprecated 'use Center';
function Center: TVector2;
function Grow(const Delta: Single): TFloatRectangle; overload;
function Grow(const DeltaX, DeltaY: Single): TFloatRectangle; overload;
function ToString: string;
function Translate(const V: TVector2): TFloatRectangle;
function Collides(const R: TFloatRectangle): boolean;
function CollidesDisc(const DiscCenter: TVector2; const Radius: Single): boolean;
function ScaleAround0(const Factor: Single): TFloatRectangle;
function Include(const P: TVector2): TFloatRectangle;
function ToX3DVector: TVector4;
class function FromX3DVector(const V: TVector4): TFloatRectangle; static;
class operator + (const R1, R2: TFloatRectangle): TFloatRectangle;
class operator * (const R1, R2: TFloatRectangle): TFloatRectangle;

Properties

property Right: Single read GetRight ;
property Top: Single read GetTop ;

Description

Fields

Left: Single;

// Commented out – see TRectangle comments. procedure SetRight(const Value: Single); procedure SetTop(const Value: Single);

Bottom: Single;

// Commented out – see TRectangle comments. procedure SetRight(const Value: Single); procedure SetTop(const Value: Single);

Width: Single;
 
Height: Single;
 

Methods

class function Empty: TFloatRectangle; static; inline;
 
function IsEmpty: boolean;
 
function Contains(const X, Y: Single): boolean; overload;
 
function Contains(const Point: TVector2): boolean; overload;
 
function Middle: TVector2; deprecated 'use Center';

Warning: this symbol is deprecated: use Center

 
function Center: TVector2;
 
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.

function Grow(const DeltaX, DeltaY: Single): TFloatRectangle; overload;
 
function ToString: string;
 
function Translate(const V: TVector2): TFloatRectangle;

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

function Collides(const R: TFloatRectangle): boolean;

Does it have any common part with another rectangle.

function CollidesDisc(const DiscCenter: TVector2; const Radius: Single): boolean;
 
function ScaleAround0(const Factor: Single): TFloatRectangle;

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

function Include(const P: TVector2): TFloatRectangle;

Return larger rectangle, so that it includes given point.

function ToX3DVector: TVector4;

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

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

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

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

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

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

Common part of the two rectangles.

Properties

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.

property Top: Single read GetTop ;
 

Generated by PasDoc 0.15.0.