138 lines
3.8 KiB
Odin
138 lines
3.8 KiB
Odin
package main
|
|
|
|
import rl "libraries/raylib"
|
|
import "core:math/linalg"
|
|
|
|
// Wraps os.read_entire_file and os.write_entire_file, but they also work with emscripten.
|
|
@(require_results)
|
|
read_entire_file :: proc(name: string, allocator := context.allocator, loc := #caller_location) -> (data: []byte, success: bool) {
|
|
return _read_entire_file(name, allocator, loc)
|
|
}
|
|
|
|
write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (success: bool) {
|
|
return _write_entire_file(name, data, truncate)
|
|
}
|
|
|
|
v1 :: [1]f32
|
|
v2 :: [2]f32
|
|
v3 :: [3]f32
|
|
v4 :: [4]f32
|
|
iv2 :: [2]i32
|
|
iv3 :: [3]i32
|
|
iv4 :: [4]i32
|
|
mat2 :: matrix[2, 2]f32
|
|
mat3 :: matrix[3, 3]f32
|
|
mat4 :: matrix[4, 4]f32
|
|
rect2 :: rl.Rectangle
|
|
irect2 :: struct {x, y, width, height: i32}
|
|
tri2 :: [3]v2
|
|
Bezier :: [3]v2
|
|
|
|
/// ### RECTANGLES ### ///
|
|
rect_from :: proc {
|
|
rect2_from_v2,
|
|
irect2_from_iv2,
|
|
}
|
|
|
|
@(private="file") rect2_from_v2 :: proc "contextless" (position, size: v2) -> rect2 {
|
|
return {position.x, position.y, size.x, size.y}
|
|
}
|
|
|
|
@(private="file") irect2_from_iv2 :: proc "contextless" (position, size: iv2) -> irect2 {
|
|
return {position.x, position.y, size.x, size.y}
|
|
}
|
|
|
|
rect_scale :: proc{
|
|
rect2_scale,
|
|
irect2_scale,
|
|
}
|
|
|
|
@(private="file") rect2_scale :: proc "contextless" (rect: rect2, scalar: f32) -> rect2 {
|
|
return {rect.x * scalar, rect.y * scalar, rect.width * scalar, rect.height * scalar}
|
|
}
|
|
|
|
@(private="file") irect2_scale :: proc "contextless" (rect: irect2, scalar: i32) -> irect2 {
|
|
return {rect.x * scalar, rect.y * scalar, rect.width * scalar, rect.height * scalar}
|
|
}
|
|
|
|
rect_grow :: proc {
|
|
rect2_grow,
|
|
rect2_grow_v2,
|
|
irect2_grow,
|
|
rect2_grow_iv2,
|
|
}
|
|
|
|
@(private="file") rect2_grow :: proc "contextless" (rect: rect2, grow: f32) -> rect2 {
|
|
return {rect.x - grow, rect.y - grow, rect.width + grow * 2.0, rect.height + grow * 2.0}
|
|
}
|
|
|
|
@(private="file") rect2_grow_v2 :: proc "contextless" (rect: rect2, grow: v2) -> rect2 {
|
|
return {rect.x - grow.x, rect.y - grow.y, rect.width + grow.x * 2.0, rect.height + grow.y * 2.0}
|
|
}
|
|
|
|
@(private="file") irect2_grow :: proc "contextless" (rect: irect2, grow: i32) -> irect2 {
|
|
return {rect.x - grow, rect.y - grow, rect.width + grow * 2, rect.height + grow * 2}
|
|
}
|
|
|
|
@(private="file") rect2_grow_iv2 :: proc "contextless" (rect: irect2, grow: iv2) -> irect2 {
|
|
return {rect.x - grow.x, rect.y - grow.y, rect.width + grow.x * 2.0, rect.height + grow.y * 2.0}
|
|
}
|
|
|
|
|
|
rect_from_area :: proc {
|
|
rect_from_area_v2,
|
|
rect_from_area_iv2,
|
|
}
|
|
|
|
@(private="file") rect_from_area_v2 :: proc "contextless" (start, end: v2) -> rect2 {
|
|
tl := linalg.min(start, end)
|
|
return {**tl, **(linalg.max(start, end) - tl)}
|
|
}
|
|
|
|
@(private="file") rect_from_area_iv2 :: proc "contextless" (start, end: iv2) -> irect2 {
|
|
tl := linalg.min(start, end)
|
|
return {**tl, **(linalg.max(start, end) - tl)}
|
|
}
|
|
|
|
rect_from_corners :: proc {
|
|
rect2_from_corners,
|
|
irect2_from_corners,
|
|
}
|
|
|
|
@(private="file") rect2_from_corners :: proc "contextless" (tl, tr, br, bl: v2) -> rect2 {
|
|
top_left := linalg.min(linalg.min(tl, tr, br), bl)
|
|
bottom_right := linalg.max(linalg.max(tl, tr, br), bl)
|
|
return {**top_left, **(bottom_right - top_left)}
|
|
}
|
|
|
|
@(private="file") irect2_from_corners :: proc "contextless" (tl, tr, br, bl: iv2) -> irect2 {
|
|
top_left := linalg.min(linalg.min(tl, tr, br), bl)
|
|
bottom_right := linalg.max(linalg.max(tl, tr, br), bl)
|
|
return {**top_left, **(bottom_right - top_left)}
|
|
}
|
|
|
|
rect_get_tl :: proc {
|
|
rect2_get_tl,
|
|
irect2_get_tl,
|
|
}
|
|
|
|
@(private="file") rect2_get_tl :: proc(rect: rect2) -> v2 {
|
|
return {rect.x, rect.y}
|
|
}
|
|
|
|
@(private="file") irect2_get_tl :: proc(rect: irect2) -> iv2 {
|
|
return {rect.x, rect.y}
|
|
}
|
|
|
|
rect_get_br :: proc {
|
|
rect2_get_br,
|
|
irect2_get_br,
|
|
}
|
|
|
|
@(private="file") rect2_get_br :: proc(rect: rect2) -> v2 {
|
|
return {rect.x + rect.width, rect.y + rect.height}
|
|
}
|
|
|
|
@(private="file") irect2_get_br :: proc(rect: irect2) -> iv2 {
|
|
return {rect.x + rect.width, rect.y + rect.height}
|
|
}
|