Some TBox functions dan cardin requested.
function OrderTBox(TBoxInput : TBox) : TBox;
function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
SCAR Code:
{*******************************************************************************
function OrderTBox(TBoxInput : TBox) : TBox;
By: Light
Description: Orders a TBox so it's upper left point is (x1,y1) and it's lower
right point is (x2,y1)
*******************************************************************************}
function OrderTBox(TBoxInput : TBox) : TBox;
var returnTBox : TBox;
begin
if(TBoxInput.x1 < TBoxInput.x2)then
begin
returnTBox.x1 := TBoxInput.x1;
returnTBox.x2 := TBoxInput.x2;
end else
begin
returnTBox.x1 := TBoxInput.x2;
returnTBox.x2 := TBoxInput.x1;
end;
if(TBoxInput.y1 < TBoxInput.y2)then
begin
returnTBox.y1 := TBoxInput.y1;
returnTBox.y2 := TBoxInput.y2;
end else
begin
returnTBox.y1 := TBoxInput.y2;
returnTBox.y2 := TBoxInput.y1;
end;
Result := returnTBox;
end;
{*******************************************************************************
function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
By: Light
Description: Checks if two TBoxs intersect with an area. Two sides touching is
not an intersection.
*******************************************************************************}
function CheckTBoxIntersection(TBox1, TBox2 : TBox) : boolean;
var orderedTBox1, orderedTBox2 : TBox;
begin
orderedTBox1 := OrderTBox(TBox1);
orderedTBox2 := OrderTBox(TBox2);
if((orderedTBox1.x1 >= orderedTBox2.x2)OR(orderedTBox1.x2 <= orderedTBox2.x1)
OR(orderedTBox1.y1 >= orderedTBox2.y2)OR(orderedTBox1.y2 <= orderedTBox2.y1))
then
begin
Result := False;
end else
begin
Result := True;
end;
end;
{*******************************************************************************
function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
By: Light
Description: Finds the TBox of intersection for two TBoxs. If there is no area
of intersection, then the return TBoxs x1, y1, x2 and y2 are all set to 0.
__________
| |
| |
| _|______
|_______|_| |
| |
| |
|_______|
*******************************************************************************}
function CollideTBoxs(TBox1, TBox2 : TBox) : TBox;
var returnTBox, orderedTBox1, orderedTBox2 : TBox;
begin
if(CheckTBoxIntersection(TBox1, TBox2))then
begin
orderedTBox1 := OrderTBox(TBox1);
orderedTBox2 := OrderTBox(TBox2);
if(orderedTBox1.x1 < orderedTBox2.x1)then
begin
returnTBox.x1 := orderedTBox2.x1;
end else
begin
returnTBox.x1 := orderedTBox1.x1;
end;
if(orderedTBox1.y1 < orderedTBox2.y1)then
begin
returnTBox.y1 := orderedTBox2.y1;
end else
begin
returnTBox.y1 := orderedTBox1.y1;
end;
if(orderedTBox1.x2 < orderedTBox2.x2)then
begin
returnTBox.x2 := orderedTBox1.x2;
end else
begin
returnTBox.x2 := orderedTBox2.x2;
end;
if(orderedTBox1.y2 < orderedTBox2.y2)then
begin
returnTBox.y2 := orderedTBox1.y2;
end else
begin
returnTBox.y2 := orderedTBox2.y2;
end;
end else
begin
returnTBox.x1 := 0;
returnTBox.y1 := 0;
returnTBox.x2 := 0;
returnTBox.y2 := 0;
end;
Result := returnTBox;
end;