unit iz_types;

interface
uses
  OpenGL;

type
  int = GLint;
  uint = GLuint;
  float = GLFloat;
  bool = GLboolean;

  IZColor = array [0..2] of GLfloat;

  izPosition_f = array[0..1] of float;
  izPosition_i = array[0..1] of int;
  izPosition_w = array[0..1] of word;
  izSize_f = array [0..1] of float;
  izSize_i = array [0..1] of int;
  izSize_w = array [0..1] of word;
  izQSize_f = array [0..2] of float;
  izQSize_i = array [0..2] of int;
  izQSize_w = array [0..2] of word;

  PzCur = ^zCur;
  zCur = record
    Pos,GamePos : izPosition_f;
  end;

  izPoint_f = record
    x,y : float;
  end;

  izPoint_w = record
    x,y : word;
  end;

  izVector2D = record
    X, Y : float;
  end;

  izColor3f = record
    Red,
    Green,
    Blue : GLFloat;
  end;

  izRect = packed record
    case int of
      0: (Left, Top, Right, Bottom: float);
      1: (TopLeft, BottomRight: izPoint_f);
  end;

var
  iz_dir_local,
  iz_dir_local_data,
  iz_dir_local_sys,
  iz_dir_local_gfx,
  iz_dir_local_sfx,
  iz_dir_local_gfx_gui,
  iz_dir_local_temp,
  iz_dir_local_temp_gfx,
  iz_dir_local_temp_sfx : string;

function iz_Rect(Left, Top, Right, Bottom: float): izRect;
function iz_IntersectRect(out Rect: izRect; const R1, R2: izRect): Boolean;
implementation

function iz_Rect(Left, Top, Right, Bottom: float): izRect;
begin
  Result.Left := Left;
  Result.Top := Top;
  Result.Bottom := Bottom;
  Result.Right := Right;
end;

function iz_IsRectEmpty(const Rect: izRect): Boolean;
begin
  Result := (Rect.Right <= Rect.Left) or (Rect.Bottom <= Rect.Top);
end;

function iz_IntersectRect(out Rect: izRect; const R1, R2: izRect): Boolean;
begin
  Rect := R1;
  if R2.Left > R1.Left then Rect.Left := R2.Left;
  if R2.Top > R1.Top then Rect.Top := R2.Top;
  if R2.Right < R1.Right then Rect.Right := R2.Right;
  if R2.Bottom < R1.Bottom then Rect.Bottom := R2.Bottom;
  Result := not iz_IsRectEmpty(Rect);
  //if not Result then FillChar(Rect, SizeOf(Rect), 0);
end;

end.
 