Init new repository
This commit is contained in:
96
examples/sandbox/common.lc
Normal file
96
examples/sandbox/common.lc
Normal file
@@ -0,0 +1,96 @@
|
||||
FloatMin :: proc(a: float, b: float): float {
|
||||
if (a > b) return b;
|
||||
return a;
|
||||
}
|
||||
|
||||
FloatMax :: proc(a: float, b: float): float {
|
||||
if (a > b) return a;
|
||||
return a;
|
||||
}
|
||||
|
||||
FloatClamp :: proc(val: float, min: float, max: float): float {
|
||||
if (val > max) return max;
|
||||
if (val < min) return min;
|
||||
return val;
|
||||
}
|
||||
|
||||
IntMin :: proc(a: int, b: int): int {
|
||||
if (a > b) return b;
|
||||
return a;
|
||||
}
|
||||
|
||||
IntMax :: proc(a: int, b: int): int {
|
||||
if (a > b) return a;
|
||||
return a;
|
||||
}
|
||||
|
||||
IntClamp :: proc(val: int, min: int, max: int): int {
|
||||
if (val > max) return max;
|
||||
if (val < min) return min;
|
||||
return val;
|
||||
}
|
||||
|
||||
Rect2 :: struct {
|
||||
min: Vector2;
|
||||
max: Vector2;
|
||||
}
|
||||
|
||||
CutLeft :: proc(r: *Rect2, value: float): Rect2 {
|
||||
minx := r.min.x;
|
||||
r.min.x = FloatMin(r.max.x, r.min.x + value);
|
||||
return :Rect2{
|
||||
{ minx, r.min.y},
|
||||
{r.min.x, r.max.y},
|
||||
};
|
||||
}
|
||||
|
||||
CutRight :: proc(r: *Rect2, value: float): Rect2 {
|
||||
maxx := r.max.x;
|
||||
r.max.x = FloatMax(r.max.x - value, r.min.x);
|
||||
return :Rect2{
|
||||
{r.max.x, r.min.y},
|
||||
{ maxx, r.max.y},
|
||||
};
|
||||
}
|
||||
|
||||
CutBottom :: proc(r: *Rect2, value: float): Rect2 { // Y is down
|
||||
maxy := r.max.y;
|
||||
r.max.y = FloatMax(r.min.y, r.max.y - value);
|
||||
return :Rect2{
|
||||
{r.min.x, r.max.y},
|
||||
{r.max.x, maxy},
|
||||
};
|
||||
}
|
||||
|
||||
CutTop :: proc(r: *Rect2, value: float): Rect2 { // Y is down
|
||||
miny := r.min.y;
|
||||
r.min.y = FloatMin(r.min.y + value, r.max.y);
|
||||
return :Rect2{
|
||||
{r.min.x, miny},
|
||||
{r.max.x, r.min.y},
|
||||
};
|
||||
}
|
||||
|
||||
Shrink :: proc(r: Rect2, value: float): Rect2 {
|
||||
r.min.x += value;
|
||||
r.max.x -= value;
|
||||
r.min.y += value;
|
||||
r.max.y -= value;
|
||||
return r;
|
||||
}
|
||||
|
||||
RectFromSize :: proc(pos: Vector2, size: Vector2): Rect2 {
|
||||
result: Rect2 = {pos, Vector2Add(pos, size)};
|
||||
return result;
|
||||
}
|
||||
|
||||
GetRectSize :: proc(rect: Rect2): Vector2 {
|
||||
result: Vector2 = {rect.max.x - rect.min.x, rect.max.y - rect.min.y};
|
||||
return result;
|
||||
}
|
||||
|
||||
RectToRectangle :: proc(rect: Rect2): Rectangle {
|
||||
size := GetRectSize(rect);
|
||||
result: Rectangle = {rect.min.x, rect.min.y, size.x, size.y};
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user