unit uUtils;

interface

uses  uSMath;

function pointInRect( const p: rVec2f; const r: rRect ): Boolean;
function pointInCircle( const p: rVec2f; const c: rCircle ): Boolean;
function collideCircleVsCircle( const _circle_1, _circle_2 : rCircle ): Boolean;
function collideCircleVsRect( const _circle: rCircle; const _rect: rRect ): Boolean;
function collideRectVsRect( const _rect_1, _rect_2 : rRect ): Boolean;

procedure setOldTVCof( cof: Single );
procedure setBlurCof( cof: Single );
procedure setBlurPO;

implementation

uses  uVar;

////////////////////////////////////////////////////////////////////////////////
///  HELP FUNCTIONS  ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
{$REGION '  Help Functions  '}
function pointInRect( const p: rVec2f; const r: rRect ): Boolean;
begin
  Result := ( p.X >= r.X ) and ( p.X <= r.X + r.Width ) and ( p.Y >= r.Y ) and ( p.Y <= r.Y + r.Height );
end;

function pointInCircle( const p: rVec2f; const c: rCircle ): Boolean;
var distance : rVec2f;
begin
  distance  := p - c.Pos;
  Result := distance.LengthSqr < Sqr( c.Radius );
end;

function collideCircleVsCircle( const _circle_1, _circle_2 : rCircle ): Boolean;
var distance : rVec2f;
begin
  distance  := _circle_1.Pos - _circle_2.Pos;
  Result := distance.LengthSqr <= Sqr( _circle_1.Radius + _circle_2.Radius );
end;

function collideCircleVsRect( const _circle: rCircle; const _rect: rRect ): Boolean;
begin
  Result := ( pointInCircle( Vec2f( _rect.X, _rect.Y ), _circle ) or
              pointInCircle( Vec2f( _rect.X + _rect.Width, _rect.Y ), _circle ) or
              pointInCircle( Vec2f( _rect.X + _rect.Width, _rect.Y + _rect.Height ), _circle ) or
              pointInCircle( Vec2f( _rect.X, _rect.Y + _rect.Height ), _circle ) ) or
            ( pointInRect( Vec2f( _circle.Pos.X - _circle.Radius, _circle.Pos.Y ), _rect ) or
              pointInRect( Vec2f( _circle.Pos.X + _circle.Radius, _circle.Pos.Y ), _rect ) or
              pointInRect( Vec2f( _circle.Pos.X, _circle.Pos.Y - _circle.Radius ), _rect ) or
              pointInRect( Vec2f( _circle.Pos.X, _circle.Pos.Y + _circle.Radius ), _rect ) );
end;

function collideRectVsRect( const _rect_1, _rect_2 : rRect ): Boolean;
begin
  Result := ( _rect_1.X + _rect_1.Width >= _rect_2.X ) and ( _rect_1.X <= _rect_2.X + _rect_2.Width ) and
            ( _rect_1.Y + _rect_1.Height >= _rect_2.Y ) and ( _rect_1.Y <= _rect_2.Y + _rect_2.Height );
end;
{$ENDREGION}
////////////////////////////////////////////////////////////////////////////////
///  SHADER PARAM FUNCTIONS  ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

procedure setOldTVCof( cof: Single );
begin
  AppOldTVCof := cof;
  AppPixelSizeOldTV[ 1 ]  := AppPixelSize[ 1 ] * AppOldTVCof;
  AppPixelSizeOldTV[ 2 ]  := AppPixelSize[ 2 ] * AppOldTVCof;
end;

procedure setBlurCof( cof: Single );
begin
  AppBlurCof := cof;
  AppPixelSizeBlur[ 1 ]   := AppPixelSize[ 1 ] * AppBlurCof;
  AppPixelSizeBlur[ 2 ]   := AppPixelSize[ 2 ] * AppBlurCof;
  setBlurPO;
end;

procedure setBlurPO;
begin
  AppBlurPO_X[ 1, 1 ] := -6 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 2, 1 ] := -5 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 3, 1 ] := -4 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 4, 1 ] := -3 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 1, 2 ] := -2 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 2, 2 ] := -1 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 3, 2 ] := 1 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 4, 2 ] := 2 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 1, 3 ] := 3 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 2, 3 ] := 4 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 3, 3 ] := 5 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 4, 3 ] := 6 * AppPixelSizeBlur[1];
  AppBlurPO_X[ 1, 4 ] := 0;
  AppBlurPO_X[ 2, 4 ] := 0;
  AppBlurPO_X[ 3, 4 ] := 0;
  AppBlurPO_X[ 4, 4 ] := 0;
  AppBlurPO_Y[ 1, 1 ] := -6 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 2, 1 ] := -5 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 3, 1 ] := -4 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 4, 1 ] := -3 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 1, 2 ] := -2 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 2, 2 ] := -1 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 3, 2 ] := 1 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 4, 2 ] := 2 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 1, 3 ] := 3 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 2, 3 ] := 4 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 3, 3 ] := 5 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 4, 3 ] := 6 * AppPixelSizeBlur[2];
  AppBlurPO_Y[ 1, 4 ] := 0;
  AppBlurPO_Y[ 2, 4 ] := 0;
  AppBlurPO_Y[ 3, 4 ] := 0;
  AppBlurPO_Y[ 4, 4 ] := 0;
end;

end.
