use std::f32::NAN;
use bevy::prelude::*;
#[derive(Component)]
pub struct Blob;
#[derive(Component, Clone, Debug)]
pub struct BlobInfo {
pub center_block_pos: Vec2,
pub xbound: [f32; 2],
pub ybound: [f32; 2],
pub color: Color,
pub mass_center: [f32;2],
pub velocity: [f32;2],
pub move_distance: [f32;2],
pub crowding_distance: f32
}
impl Default for BlobInfo {
fn default() -> Self {
Self {
center_block_pos: Vec2::NAN,
xbound: [NAN, NAN],
ybound: [NAN, NAN],
color: Color::LIME_GREEN,
mass_center: [0.0, 0.0],
velocity: [0.0,0.0],
move_distance: [0.0,0.0],
crowding_distance: 0.0
}
}
}
impl BlobInfo {
pub fn init(&mut self, center: Vec2, size: Vec2) {
self.center_block_pos = center;
self.xbound = [center.x - size.x, center.x + size.x];
self.ybound = [center.y - size.y, center.y + size.y];
}
pub fn add(&mut self, translation: Vec2, size: Vec2) {
let large = translation + size;
let small = translation - size;
self.xbound[0] = self.xbound[0].min(small.x);
self.xbound[1] = self.xbound[1].max(large.x);
self.ybound[0] = self.ybound[0].min(small.y);
self.ybound[1] = self.ybound[1].max(large.y);
}
}
#[derive(Bundle)]
pub struct BlobBundle {
blob_flag: Blob,
visibility: Visibility,
computed_visibility: ComputedVisibility,
transform_bundle: TransformBundle,
info: BlobInfo,
}
impl Default for BlobBundle {
fn default() -> Self {
Self {
blob_flag: Blob,
visibility: Visibility::Visible,
computed_visibility: ComputedVisibility::HIDDEN,
transform_bundle: TransformBundle::IDENTITY,
info: BlobInfo::default(),
}
}
}