ifc_lite_geometry/router/
config.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//! The router's value-type configuration: everything a caller decides before
6//! any geometry is produced (C2-4, #7781). [`GeometryRouter::from_config`]
7//! builds a router from one; [`GeometryRouter::config`] reads the effective one
8//! back. The `with_*` constructors and `set_*` methods stay as thin delegates.
9//!
10//! Configuration changes advance the router's execution generation, so a
11//! change made while a product holds the router's execution lease refuses
12//! that product's publication (`ExecutionLeaseError::ConfigurationChanged`).
13//! Build the router with `from_config`, inject the shared caches, and only then
14//! lease it for the first product.
15
16use crate::tessellation::TessellationQuality;
17use crate::GeometryRouter;
18
19/// How a [`GeometryRouter`] meshes. Plain data: `Clone`, comparable, built once
20/// per load and handed to every per-element or per-batch router. Resource
21/// budgets, deadlines and live cache accounts belong to the execution domain
22/// and are not copied or reset by this configuration.
23#[derive(Clone, Debug, PartialEq)]
24pub struct RouterConfig {
25    /// Unit scale factor (e.g. 0.001 for millimetres to metres), applied to all
26    /// mesh positions after processing. A non-finite or non-positive scale
27    /// refuses the router (see [`GeometryRouter::length_unit_refused`]) and the
28    /// effective scale reads back as 1.0.
29    pub unit_scale: f64,
30    /// RTC (Relative-to-Center) offset, subtracted from world positions in f64
31    /// before converting to f32 to preserve precision (e.g. Swiss UTM).
32    pub rtc_offset: (f64, f64, f64),
33    /// Tessellation detail level, passed to every processor's `process`.
34    pub tessellation_quality: TessellationQuality,
35    /// Per-router local-frame choice. `None` retains the target/env default;
36    /// appearance authoring sets this explicitly so its canonical surface
37    /// identity cannot vary between native and wasm builds (#4550). Mesh caches
38    /// are frame-dependent, so it is fixed before any geometry is produced.
39    pub local_frame: Option<bool>,
40    /// Per-build small-cut skip (#1286): a solid-solid DIFFERENCE with a tiny
41    /// cutter is dropped without forcing a preview tessellation tier. Scoped to
42    /// the router, so concurrent native builds never bleed the flag into one
43    /// another. `false` keeps every cut.
44    pub skip_small_cuts: bool,
45    /// #1623 Phase 3 template-selection mode for the don't-bake path. `false`
46    /// (NATIVE): the deterministic global template is the plan's min-id
47    /// occurrence, so every occurrence resolves against ONE model-wide template
48    /// across the rayon pool. `true` (the WASM per-BATCH path): the router
49    /// meshes one batch serially and the FIRST occurrence of each source it
50    /// sees is the template, so each per-batch shard is self-contained. Both
51    /// emit geometrically identical world triangles.
52    pub instancing_batch_local: bool,
53}
54
55impl Default for RouterConfig {
56    fn default() -> Self {
57        Self {
58            unit_scale: 1.0, // base metres
59            rtc_offset: (0.0, 0.0, 0.0),
60            tessellation_quality: TessellationQuality::Medium,
61            local_frame: None,
62            skip_small_cuts: false,
63            instancing_batch_local: false, // native global-template mode
64        }
65    }
66}
67
68impl GeometryRouter {
69    /// A router with `config` applied. Like [`GeometryRouter::new`] it arms no
70    /// caches: inject the shared ones (`enable_content_dedup_shared`,
71    /// `enable_shared_mapped_item_cache`, ...) afterwards, before the first
72    /// product leases the router.
73    // Let constructor delegates initialize their destination in place instead
74    // of copying the full router through a second configuration return slot.
75    #[inline(always)]
76    pub fn from_config(config: RouterConfig) -> Self {
77        // Destructured so a new field cannot be added without being applied.
78        let RouterConfig {
79            unit_scale,
80            rtc_offset,
81            tessellation_quality,
82            local_frame,
83            skip_small_cuts,
84            instancing_batch_local,
85        } = config;
86        let mut router = Self::new();
87        router.set_unit_scale(unit_scale);
88        router.set_rtc_offset(rtc_offset);
89        router.set_tessellation_quality(tessellation_quality);
90        router.config.local_frame = local_frame;
91        router.set_skip_small_cuts(skip_small_cuts);
92        router.set_instancing_batch_local(instancing_batch_local);
93        router
94    }
95
96    /// The effective configuration, including later `set_*` changes. This is
97    /// not a full router snapshot: length-unit refusal is deliberately not
98    /// serialized, and a refused unit reads back as `unit_scale == 1.0`.
99    /// Rebuilding with `from_config(router.config().clone())` does not preserve
100    /// refusal. Callers must pass the raw invalid scale or call
101    /// [`Self::refuse_length_unit`] on each rebuilt router before meshing.
102    #[inline]
103    pub fn config(&self) -> &RouterConfig {
104        &self.config
105    }
106}
107
108#[cfg(test)]
109#[path = "config_tests.rs"]
110mod config_tests;