use crate::geometry::DTransformation;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtItem {
pub id: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_orientations: Option<Vec<f32>>,
pub shape: ExtShape,
pub min_quality: Option<usize>,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtContainer {
pub id: u64,
pub shape: ExtShape,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub zones: Vec<ExtQualityZone>,
}
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type", content = "data")]
#[serde(rename_all = "snake_case")]
pub enum ExtShape {
Rectangle {
x_min: f32,
y_min: f32,
width: f32,
height: f32,
},
SimplePolygon(ExtSPolygon),
Polygon(ExtPolygon),
MultiPolygon(Vec<ExtPolygon>),
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtPolygon {
pub outer: ExtSPolygon,
#[serde(default)]
pub inner: Vec<ExtSPolygon>,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtSPolygon(pub Vec<(f32, f32)>);
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtQualityZone {
pub quality: usize,
pub shape: ExtShape,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtLayout {
pub container_id: u64,
pub placed_items: Vec<ExtPlacedItem>,
pub density: f32,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtPlacedItem {
pub item_id: u64,
pub transformation: ExtTransformation,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ExtTransformation {
pub rotation: f32,
pub translation: (f32, f32),
}
impl From<DTransformation> for ExtTransformation {
fn from(dt: DTransformation) -> Self {
ExtTransformation {
rotation: dt.rotation().to_degrees(),
translation: dt.translation(),
}
}
}
impl From<ExtTransformation> for DTransformation {
fn from(ext_dt: ExtTransformation) -> Self {
DTransformation::new(ext_dt.rotation.to_radians(), ext_dt.translation)
}
}