2024-03-19 05:36:58 -07:00
|
|
|
// Goal is for any Position or 'Shape' intersections used by the prototype to be defined here for centeralization
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
import "core:math/linalg"
|
|
|
|
|
2024-03-14 21:02:28 -07:00
|
|
|
// AABB: Separating Axis Theorem
|
|
|
|
intersects_range2 :: #force_inline proc "contextless" ( a, b: Range2 ) -> bool
|
|
|
|
{
|
|
|
|
// Check if there's no overlap on the x-axis
|
|
|
|
if a.max.x < b.min.x || b.max.x < a.min.x {
|
|
|
|
return false; // No overlap on x-axis means no intersection
|
|
|
|
}
|
|
|
|
// Check if there's no overlap on the y-axis
|
|
|
|
if a.max.y < b.min.y || b.max.y < a.min.y {
|
|
|
|
return false; // No overlap on y-axis means no intersection
|
|
|
|
}
|
|
|
|
// If neither of the above conditions are true, there's at least a partial overlap
|
|
|
|
return true;
|
2024-03-02 07:24:09 -08:00
|
|
|
}
|
2024-02-11 20:00:06 -08:00
|
|
|
|
2024-03-12 17:55:29 -07:00
|
|
|
// TODO(Ed): Do we need this? Also does it even work (looks unfinished)?
|
2024-03-14 21:02:28 -07:00
|
|
|
is_within_screenspace :: #force_inline proc "contextless" ( pos : Vec2 ) -> b32 {
|
2024-02-11 20:00:06 -08:00
|
|
|
state := get_state(); using state
|
|
|
|
screen_extent := state.app_window.extent
|
|
|
|
cam := & project.workspace.cam
|
|
|
|
within_x_bounds : b32 = pos.x >= -screen_extent.x && pos.x <= screen_extent.x
|
|
|
|
within_y_bounds : b32 = pos.y >= -screen_extent.y && pos.y <= screen_extent.y
|
|
|
|
return within_x_bounds && within_y_bounds
|
|
|
|
}
|
2024-03-10 23:05:30 -07:00
|
|
|
|
2024-03-14 21:02:28 -07:00
|
|
|
within_range2 :: #force_inline proc "contextless" ( a, b : Range2 ) -> bool {
|
|
|
|
within_x := b.min.x >= a.min.x && b.max.x <= a.max.x
|
|
|
|
within_y := b.min.y >= a.min.y && b.max.y <= a.max.y
|
2024-03-10 23:05:30 -07:00
|
|
|
return within_x && within_y
|
|
|
|
}
|
2024-03-14 21:02:28 -07:00
|
|
|
|
|
|
|
pos_within_range2 :: #force_inline proc "contextless" ( pos : Vec2, range : Range2 ) -> b32 {
|
|
|
|
within_x := pos.x > range.min.x && pos.x < range.max.x
|
|
|
|
within_y := pos.y > range.min.y && pos.y < range.max.y
|
|
|
|
return b32(within_x && within_y)
|
|
|
|
}
|