2024-02-08 07:50:36 -08:00
|
|
|
package sectr
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
Axis2 :: enum i32 {
|
|
|
|
Invalid = -1,
|
|
|
|
X = 0,
|
|
|
|
Y = 1,
|
|
|
|
Count,
|
|
|
|
}
|
|
|
|
|
2024-02-29 16:37:37 -08:00
|
|
|
is_power_of_two_u32 :: proc( value : u32 ) -> b32
|
|
|
|
{
|
|
|
|
return value != 0 && ( value & ( value - 1 )) == 0
|
|
|
|
}
|
|
|
|
|
2024-02-10 00:40:53 -08:00
|
|
|
import "core:math/linalg"
|
|
|
|
|
|
|
|
Vec2 :: linalg.Vector2f32
|
|
|
|
Vec3 :: linalg.Vector3f32
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
Vec2i :: [2]i32
|
|
|
|
Vec3i :: [3]i32
|
2024-03-02 07:24:09 -08:00
|
|
|
|
|
|
|
Range2 :: struct #raw_union{
|
|
|
|
using min_max : struct {
|
|
|
|
min, max : Vec2
|
|
|
|
},
|
|
|
|
using pts : struct {
|
|
|
|
p0, p1 : Vec2
|
|
|
|
},
|
|
|
|
using xy : struct {
|
|
|
|
x0, y0 : f32,
|
|
|
|
x1, y1 : f32,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
range2 :: #force_inline proc "contextless" ( a, b : Vec2 ) -> Range2 {
|
|
|
|
result := Range2 { pts = { a, b } }
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
Rect :: struct {
|
|
|
|
top_left, bottom_right : Vec2
|
|
|
|
}
|
2024-03-08 00:34:21 -08:00
|
|
|
|
|
|
|
add_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> Range2 {
|
|
|
|
result := Range2 { pts = {
|
|
|
|
a.p0 + b.p0,
|
|
|
|
a.p1 + b.p1,
|
|
|
|
}}
|
|
|
|
return result
|
|
|
|
}
|
2024-03-10 23:05:18 -07:00
|
|
|
|
|
|
|
equal_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> b32 {
|
|
|
|
result := a.p0 == b.p0 && a.p1 == b.p1
|
|
|
|
return b32(result)
|
|
|
|
}
|
|
|
|
|
2024-03-10 23:05:30 -07:00
|
|
|
|
|
|
|
// // Translated intersect_2f32 function
|
|
|
|
// intersect_2f32 :: proc(a, b: Rng2F32) -> Rng2F32 {
|
|
|
|
// c: Rng2F32
|
|
|
|
// c.min.x = Max(a.min.x, b.min.x)
|
|
|
|
// c.min.y = Max(a.min.y, b.min.y)
|
|
|
|
// c.max.x = Min(a.max.x, b.max.x)
|
|
|
|
// c.max.y = Min(a.max.y, b.max.y)
|
|
|
|
// return c
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
size_range2 :: #force_inline proc "contextless" ( value : Range2 ) -> Vec2 {
|
|
|
|
return { value.p1.x - value.p0.x, value.p0.y - value.p1.y }
|
2024-03-13 23:02:09 -07:00
|
|
|
}
|