Object TFloatRectangle

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TFloatRectangle = object(TObject)

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

Hierarchy

  • TObject
  • TFloatRectangle

Overview

Fields

Public Left: Single;
Public Bottom: Single;
Public Width: Single;
Public Height: Single;
Public internal const Empty: TFloatRectangle = (Left: 0; Bottom: 0; Width: -1; Height: -1);

Methods

Public function IsEmpty: boolean;
Public function Contains(const X, Y: Single): boolean;
Public function Contains(const Point: TVector2Single): boolean;
Public function Middle: TVector2Single; deprecated 'use Center';
Public function Center: TVector2Single;
Public function Grow(const Delta: Single): TFloatRectangle;
Public function Grow(const DeltaX, DeltaY: Single): TFloatRectangle;
Public function ToString: string;
Public function Translate(const V: TVector2Single): TFloatRectangle;
Public function Collides(const R: TFloatRectangle): boolean;
Public function CollidesDisc(const DiscCenter: TVector2Single; const Radius: Single): boolean;
Public function ScaleAround0(const Factor: Single): TFloatRectangle;
Public function Add(const P: TVector2Single): TFloatRectangle;
Public function ToX3DVector: TVector4Single;
Public class function FromX3DVector(const V: TVector4Single): TFloatRectangle; static;

Properties

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

Description

Fields

Public Left: Single;

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

Public Bottom: Single;

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

Public Width: Single;
 
Public Height: Single;
 
Public internal const Empty: TFloatRectangle = (Left: 0; Bottom: 0; Width: -1; Height: -1);
 

Methods

Public function IsEmpty: boolean;
 
Public function Contains(const X, Y: Single): boolean;
 
Public function Contains(const Point: TVector2Single): boolean;
 
Public function Middle: TVector2Single; deprecated 'use Center';

Warning: this symbol is deprecated: use Center

 
Public function Center: TVector2Single;
 
Public function Grow(const Delta: Single): TFloatRectangle;

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;
 
Public function ToString: string;
 
Public function Translate(const V: TVector2Single): 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: TVector2Single; const Radius: Single): boolean;
 
Public function ScaleAround0(const Factor: Single): TFloatRectangle;

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

Public function Add(const P: TVector2Single): TFloatRectangle;

Return larger rectangle, so that it includes given point.

Public function ToX3DVector: TVector4Single;

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

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

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

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 ;
 

Generated by PasDoc 0.14.0.