Skip to main content

jellyflow_runtime/io/tuning/
spatial_index.rs

1use serde::{Deserialize, Serialize};
2
3/// Tuning for the optional indexed spatial-query backend.
4#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5pub struct NodeGraphSpatialIndexTuning {
6    /// Enables the spatial backend for store-level query reads.
7    #[serde(default)]
8    pub enabled: bool,
9    /// Preferred cell size in screen pixels (converted to canvas units by dividing by zoom).
10    #[serde(default = "NodeGraphSpatialIndexTuning::default_cell_size_screen_px")]
11    pub cell_size_screen_px: f32,
12    /// Minimum cell size in screen pixels (converted to canvas units by dividing by zoom).
13    #[serde(default = "NodeGraphSpatialIndexTuning::default_min_cell_size_screen_px")]
14    pub min_cell_size_screen_px: f32,
15}
16
17impl NodeGraphSpatialIndexTuning {
18    pub fn enabled(mut self, enabled: bool) -> Self {
19        self.enabled = enabled;
20        self
21    }
22
23    pub fn with_cell_size_screen_px(mut self, cell_size_screen_px: f32) -> Self {
24        self.cell_size_screen_px = cell_size_screen_px;
25        self
26    }
27
28    pub fn with_min_cell_size_screen_px(mut self, min_cell_size_screen_px: f32) -> Self {
29        self.min_cell_size_screen_px = min_cell_size_screen_px;
30        self
31    }
32
33    fn default_cell_size_screen_px() -> f32 {
34        256.0
35    }
36
37    fn default_min_cell_size_screen_px() -> f32 {
38        16.0
39    }
40}
41
42impl Default for NodeGraphSpatialIndexTuning {
43    fn default() -> Self {
44        Self {
45            enabled: false,
46            cell_size_screen_px: Self::default_cell_size_screen_px(),
47            min_cell_size_screen_px: Self::default_min_cell_size_screen_px(),
48        }
49    }
50}