ifc_lite_diff/
model.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Store-independent comparison inputs and key-pass results (#8042).
6use crate::JsString;
7use std::collections::HashMap;
8
9/// Component hashes by component key. Keys hash through their cached digest
10/// (#8351); build with `ComponentMap::default()` or `collect()`.
11pub 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/// Geometry hashes are opaque strings. The JS boundary converts bigint hashes
20/// to decimal strings, without interpreting string hashes as numbers.
21#[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/// Borrows the caller's entities; opaque adapter handles are never cloned or read.
57#[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    /// Ignore placement hashes without copying or mutating the resident model.
70    pub strip_placement_geometry: bool,
71    pub scope: DiffScope,
72    pub exclude_types: Vec<JsString>,
73    /// Absence differs from an explicitly supplied empty alias map.
74    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    /// Entry indices avoid cloning entities or requiring Clone on adapter handles.
83    pub by_key: HashMap<JsString, usize>,
84    pub counts: DiffCounts,
85    pub applied_key_aliases: Option<Vec<(JsString, JsString)>>,
86    /// Resolved once for the content-matching stages too.
87    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}