| Description | uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables |
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.
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; |
TIntRect = array[0..1]of TVector2Integer; |
IntRectEmpty: TIntRect = ((0, 0), (0, 0)); |
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; |
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, 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]) |
IntRectEmpty: TIntRect = ((0, 0), (0, 0)); |