//- Vec2 F32
root_function Vec2_F32
vec2_F32(F32 x, F32 y)
{
  Vec2_F32 result;
  result.x = x;
  result.y = y;
  return result;
}

root_function Vec2_F32 add2_F32(Vec2_F32 a, Vec2_F32 b) { return vec2_F32(a.x+b.x, a.y+b.y); }
root_function Vec2_F32 sub2_F32(Vec2_F32 a, Vec2_F32 b) { return vec2_F32(a.x-b.x, a.y-b.y); }

//- Vec2 S32 
root_function Vec2_S32
vec2_S32(S32 x, S32 y)
{
  Vec2_S32 result;
  result.x = x;
  result.y = y;
  return result;
}


root_function Vec2_S64
vec2_S64(S64 x, S64 y)
{
  Vec2_S64 result;
  result.x = x;
  result.y = y;
  return result;
}

root_function Vec3_F32 
vec3_F32(F32 x, F32 y, F32 z)
{
  Vec3_F32 result;
  result.x = x;
  result.y = y;
  result.z = z;
  return result;
}

root_function Vec4_F32 
vec4_F32(F32 x, F32 y, F32 z, F32 w)
{
  Vec4_F32 result;
  result.x = x;
  result.y = y;
  result.z = z;
  result.w = w;
  return result;
}

//~ Range functions
root_function Rng2_F32
rng2_F32(Vec2_F32 min, Vec2_F32 max)
{
  Rng2_F32 result = { min, max };
  return result;
}

root_function Rng2_F32 
shift2_F32(Rng2_F32 r, Vec2_F32 v) { 
  // Shift the rectangle r by vector v.
  r.x0 += v.x; 
  r.y0 += v.y; 
  r.x1 += v.x; 
  r.y1 += v.y; 
  return r; 
}

root_function Rng2_F32
pad2_F32(Rng2_F32 r, F32 x)
{ 
  // Pad subtracts the p0 by value x on both axes, and adds to p1 on both axes,
  // resulting in a rectangle that is value x larger than input rectangle r on both axes.
  Vec2_F32 min = sub2_F32(r.min, vec2_F32(x, x));
  Vec2_F32 max = add2_F32(r.max, vec2_F32(x, x));
  return rng2_F32(min, max);
}

root_function Vec2_F32
dim2_F32(Rng2_F32 rng)
{
  return vec2_F32(absolute_value_F32(rng.max.x - rng.min.x),
      absolute_value_F32(rng.max.y - rng.min.y));
}

// Check if a rect contains a point
root_function B32 
rng2_contains_vec2_F32(Rng2_F32 r, Vec2_F32 x)
{
  B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); 
  return c;
}

root_function Rng2_F32 
rng2_intersect_f32(Rng2_F32 a, Rng2_F32 b)
{
  Rng2_F32 c; 
  c.p0.x = Max(a.min.x, b.min.x); 
  c.p0.y = Max(a.min.y, b.min.y); 
  c.p1.x = Min(a.max.x, b.max.x); 
  c.p1.y = Min(a.max.y, b.max.y); 
  return c;
}