use crate::tiles::TilePos;
use crate::{TilemapGridSize, TilemapTileSize, TilemapType};
use bevy::camera::primitives::Aabb;
use bevy::math::{UVec2, Vec2, Vec3};
pub fn chunk_index_to_world_space(
chunk_index: UVec2,
chunk_size: UVec2,
grid_size: &TilemapGridSize,
map_type: &TilemapType,
) -> Vec2 {
let anchor_tile_pos = TilePos {
x: chunk_index.x * chunk_size.x,
y: chunk_index.y * chunk_size.y,
};
anchor_tile_pos.center_in_world_unanchored(grid_size, map_type)
}
pub fn chunk_aabb(
chunk_size: UVec2,
grid_size: &TilemapGridSize,
tile_size: &TilemapTileSize,
map_type: &TilemapType,
) -> Aabb {
let border = Vec2::from(grid_size).max(tile_size.into()) / 2.0;
let c0 = chunk_index_to_world_space(UVec2::new(0, 0), chunk_size, grid_size, map_type);
let c1 = chunk_index_to_world_space(UVec2::new(1, 0), chunk_size, grid_size, map_type);
let c2 = chunk_index_to_world_space(UVec2::new(0, 1), chunk_size, grid_size, map_type);
let c3 = chunk_index_to_world_space(UVec2::new(1, 1), chunk_size, grid_size, map_type);
let minimum = Vec3::from((c0.min(c1).min(c2).min(c3) - border, 0.0));
let maximum = Vec3::from((c0.max(c1).max(c2).max(c3) + border, 1.0));
Aabb::from_min_max(minimum, maximum)
}