1use crate::JsString;
7use std::collections::HashMap;
8
9pub type ComponentMap = HashMap<JsString, JsString, crate::JsHash>;
12
13#[derive(Debug, Clone, PartialEq)]
14pub struct EntityAabb {
15 pub min: [f64; 3],
16 pub max: [f64; 3],
17}
18
19#[derive(Debug, Clone, PartialEq)]
22pub struct EntityFingerprint<R = ()> {
23 pub key: JsString,
24 pub ifc_type: JsString,
25 pub data_hash: JsString,
26 pub geometry_hash: Option<JsString>,
27 pub aabb: Option<EntityAabb>,
28 pub volume: Option<f64>,
29 pub components: Option<ComponentMap>,
30 pub container: Option<JsString>,
31 pub reference: R,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
35pub enum DiffScope {
36 Data,
37 Geometry,
38 #[default]
39 Both,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum DiffState { Added, Modified, Deleted, Unchanged }
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum DiffChangeKind { Data, Geometry, Container }
47
48#[derive(Debug, Default, Clone, PartialEq, Eq)]
49pub struct DiffCounts {
50 pub added: usize,
51 pub modified: usize,
52 pub deleted: usize,
53 pub unchanged: usize,
54}
55
56#[derive(Debug)]
58pub struct DiffEntry<'a, R> {
59 pub key: JsString,
60 pub state: DiffState,
61 pub change_kinds: Vec<DiffChangeKind>,
62 pub base: Option<&'a EntityFingerprint<R>>,
63 pub head: Option<&'a EntityFingerprint<R>>,
64 pub changed_components: Option<Vec<JsString>>,
65}
66
67#[derive(Debug, Default)]
68pub struct KeyDiffOptions {
69 pub strip_placement_geometry: bool,
71 pub scope: DiffScope,
72 pub exclude_types: Vec<JsString>,
73 pub key_aliases: Option<HashMap<JsString, JsString>>,
75}
76
77#[derive(Debug)]
78pub struct KeyDiff<'a, R> {
79 pub scope: DiffScope,
80 pub excluded_types: Vec<JsString>,
81 pub entries: Vec<DiffEntry<'a, R>>,
82 pub by_key: HashMap<JsString, usize>,
84 pub counts: DiffCounts,
85 pub applied_key_aliases: Option<Vec<(JsString, JsString)>>,
86 pub use_geometry: bool,
88 pub strip_placement_geometry: bool,
89}
90
91impl<R> EntityFingerprint<R> {
92 pub(crate) fn geometry_hash(&self, strip_placement: bool) -> Option<&JsString> {
93 self.geometry_hash.as_ref().filter(|hash|
94 !strip_placement || !hash.units().starts_with(&[b'p' as u16, b':' as u16]))
95 }
96}