Unit IntRects

DescriptionusesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Extremely simple unit with basic operations on integer rectangles.

Does not use Types unit with TRect — I do not like all trash from Types unit, and I want to keep some compatibility with my types in VectorMath.

uses

Overview

Functions and Procedures

function IntRect(X1, Y1, X2, Y2:Integer):TIntRect;
function RectsEqual(const R1, R2:TIntRect):boolean;
function RectWidth(const r:TIntRect):Cardinal;
function RectHeight(const r:TIntRect):Cardinal;
function GrowRect(const r:TIntRect; GrowValue:Integer):TIntRect;
function CenteredRect(const R:TIntRect; w,h:Cardinal):TIntRect;
function PointInRect(const v:TVector2Integer; const r:TIntRect):boolean; overload;
function PointInRect(const x,y:Integer; const r:TIntRect):boolean; overload;
function IntRectToNiceStr(const R:TIntRect):string;

Types

TIntRect = array[0..1]of TVector2Integer;

Constants

IntRectEmpty: TIntRect = ((0, 0), (0, 0));

Description

Functions and Procedures

function IntRect(X1, Y1, X2, Y2:Integer):TIntRect;
 
function RectsEqual(const R1, R2:TIntRect):boolean;
 
function RectWidth(const r:TIntRect):Cardinal;
 
function RectHeight(const r:TIntRect):Cardinal;
 
function GrowRect(const r:TIntRect; GrowValue:Integer):TIntRect;

It's grow, or shrink (when GrowValue < 0). Just remember to preserve basic TIntRect type assumptions (Rect[0,0] <= Rect [1,0], Rect[0,1] <= Rect [1,1]), so don't shrink it too much.

function CenteredRect(const R:TIntRect; w,h:Cardinal):TIntRect;

Returns TIntRect with Width = W, Height = H and centered on R.

function PointInRect(const v:TVector2Integer; const r:TIntRect):boolean; overload;
 
function PointInRect(const x,y:Integer; const r:TIntRect):boolean; overload;
 
function IntRectToNiceStr(const R:TIntRect):string;
 

Types

TIntRect = array[0..1]of TVector2Integer;

Must be

  Rect[0,0] <= Rect [1,0],
  Rect[0,1] <= Rect [1,1]

If the exact pixel interpretation is required, TIntRect should be treated as a set of points (x,y) where

  Rect[0,0] <= x < Rect [1,0]
  Rect[0,1] <= y < Rect [1,1]

In such situations Rect may be considered empty when

  (Rect[0,0] = Rect [1,0]) or (Rect[0,1] = Rect [1,1])

Constants

IntRectEmpty: TIntRect = ((0, 0), (0, 0));
 

Generated by PasDoc 0.10.0 on 2008-02-25 00:00:32