Skip to main content

binpack_3d/
algorithmen.rs

1use thiserror::Error;
2
3use crate::{
4    bin::{
5        Bin,
6        SpaceLeftBin,
7    },
8    corners::Corners,
9    items::Item,
10    sortedbin::SortedBin,
11};
12
13/// Defines a trait for 3d Bin Packaging algorithments, so is replacing the algorithm possible
14pub trait Algorithmen3DBinPackaging
15where
16    Self: Sized,
17{
18    /// A Algorithmen Input where all packages are there
19    fn create_algorithmen(input: Vec<Item>, bin: Bin) -> Result<Self, AlgorithmenError>;
20    /// Add Items Later
21    fn add_item(&mut self, input: Vec<Item>) -> Result<(), AlgorithmenError>;
22    /// Remove Item
23    /// If not fit give back items
24    fn remove_item(&mut self, input: Vec<Item>) -> Result<(), Vec<Item>>;
25    /// If Space is left
26    fn space_left(&self) -> u32;
27    /// Checks if the Items can be in a bin, possible fast check
28    fn check_fit_quick(input: &[Item], bin: &Bin) -> (bool, SpaceLeftBin);
29    /// A final result
30    ///
31    /// the score function checks what the best position is to place a object
32    ///
33    /// Used default score function
34    fn calculate(self) -> Result<SortedBin, AlgorithmenError>;
35    /// A final result
36    ///
37    /// the score function checks what the best position is to place a object
38    ///
39    /// In some chasses a custom is preferred
40    fn calculate_custom<F>(
41        self,
42        custom_score_function: Option<F>,
43    ) -> Result<SortedBin, AlgorithmenError>
44    where
45        F: Fn(&Bin, &Item, &Corners) -> f32 + Send + Sync;
46}
47
48/// Errors for AlgorithmenFirst
49#[derive(Debug, Error, PartialEq, Eq, PartialOrd, Ord)]
50pub enum AlgorithmenError {
51    /// Bin has for the packages not enough space left {0}
52    #[error("Bin has for the packages not enough space left ")]
53    NotEnoughSpace,
54    /// No Element was found in the list, should not be possible
55    #[error("No Element was found in the list, should not be possible")]
56    NoElementLeft,
57    /// Item was to big for item
58    #[error("Item was to big for item")]
59    ItemToBigForBin,
60}