jagua_rs/entities/instances/
bin_packing.rsuse crate::entities::bin::Bin;
use crate::entities::instances::instance_generic::InstanceGeneric;
use crate::entities::item::Item;
use crate::fsize;
use crate::geometry::geo_traits::Shape;
use crate::util::assertions;
#[derive(Debug, Clone)]
pub struct BPInstance {
pub items: Vec<(Item, usize)>,
pub item_area: fsize,
pub bins: Vec<(Bin, usize)>,
}
impl BPInstance {
pub fn new(items: Vec<(Item, usize)>, bins: Vec<(Bin, usize)>) -> Self {
assert!(assertions::instance_item_bin_ids_correct(&items, &bins));
let item_area = items
.iter()
.map(|(item, qty)| item.shape.area() * *qty as fsize)
.sum();
Self {
items,
item_area,
bins,
}
}
}
impl InstanceGeneric for BPInstance {
fn items(&self) -> &[(Item, usize)] {
&self.items
}
fn item_area(&self) -> fsize {
self.item_area
}
}