-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsimulation_params.rs
More file actions
executable file
·150 lines (137 loc) · 5.13 KB
/
Copy pathsimulation_params.rs
File metadata and controls
executable file
·150 lines (137 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use serde::{Deserialize, Serialize};
use bytemuck::{Pod, Zeroable};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum SimulationMode {
Remote, // GPU-accelerated remote computation (default)
GPU, // Local GPU computation (deprecated)
Local, // CPU-based computation (disabled)
}
impl Default for SimulationMode {
fn default() -> Self {
SimulationMode::Remote
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum SimulationPhase {
Initial, // Heavy computation for initial layout
Dynamic, // Lighter computation for dynamic updates
Finalize, // Final positioning and cleanup
}
impl Default for SimulationPhase {
fn default() -> Self {
SimulationPhase::Initial
}
}
// GPU-compatible simulation parameters
#[repr(C)]
#[derive(Default, Clone, Copy, Pod, Zeroable, Debug)]
pub struct GPUSimulationParams {
pub iterations: u32,
pub spring_strength: f32,
pub repulsion: f32,
pub damping: f32,
pub max_repulsion_distance: f32,
pub viewport_bounds: f32,
pub mass_scale: f32,
pub boundary_damping: f32,
}
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SimulationParams {
// Core iteration parameters
pub iterations: u32, // Range: 1-500, Default: varies by phase
pub time_step: f32, // Range: 0.01-1, Default: 0.2 (5fps)
// Force parameters
pub spring_strength: f32, // Range: 0.1-10, Default: 0.5
pub repulsion: f32, // Default: 100
pub max_repulsion_distance: f32, // Default: 500
// Mass and damping
pub mass_scale: f32, // Default: 1.0, Affects force scaling
pub damping: f32, // Range: 0-1, Default: 0.5
pub boundary_damping: f32, // Range: 0.5-1, Default: 0.9
// Boundary control
pub viewport_bounds: f32, // Range: 100-5000, Default: 1000
pub enable_bounds: bool, // Default: true
// Simulation state
pub phase: SimulationPhase, // Current simulation phase
pub mode: SimulationMode, // Computation mode
}
impl SimulationParams {
pub fn new() -> Self {
Self {
iterations: 100,
time_step: 0.2,
spring_strength: 0.5,
repulsion: 100.0,
max_repulsion_distance: 500.0,
mass_scale: 1.0,
damping: 0.5,
boundary_damping: 0.9,
viewport_bounds: 1000.0,
enable_bounds: true,
phase: SimulationPhase::Initial,
mode: SimulationMode::Remote,
}
}
pub fn with_phase(phase: SimulationPhase) -> Self {
match phase {
SimulationPhase::Initial => Self {
iterations: 300,
time_step: 0.2,
spring_strength: 0.3, // Reduced for initial spread
repulsion: 200.0, // Increased for better separation
max_repulsion_distance: 800.0, // Larger range for initial layout
mass_scale: 1.2, // Slightly higher mass influence
damping: 0.95, // High damping for stability
boundary_damping: 0.95,
viewport_bounds: 1000.0,
enable_bounds: true,
phase,
mode: SimulationMode::Remote,
},
SimulationPhase::Dynamic => Self {
iterations: 50,
time_step: 0.2,
spring_strength: 0.5,
repulsion: 100.0,
max_repulsion_distance: 500.0,
mass_scale: 1.0,
damping: 0.5,
boundary_damping: 0.9,
viewport_bounds: 1000.0,
enable_bounds: true,
phase,
mode: SimulationMode::Remote,
},
SimulationPhase::Finalize => Self {
iterations: 200,
time_step: 0.2,
spring_strength: 0.1, // Minimal spring forces
repulsion: 50.0, // Reduced repulsion
max_repulsion_distance: 300.0, // Tighter packing
mass_scale: 0.8, // Reduced mass influence
damping: 0.95, // High damping for stability
boundary_damping: 0.95,
viewport_bounds: 1000.0,
enable_bounds: true,
phase,
mode: SimulationMode::Remote,
},
}
}
// Convert to GPU-compatible parameters
pub fn to_gpu_params(&self) -> GPUSimulationParams {
GPUSimulationParams {
iterations: self.iterations,
spring_strength: self.spring_strength,
repulsion: self.repulsion,
damping: self.damping,
max_repulsion_distance: self.max_repulsion_distance,
viewport_bounds: if self.enable_bounds { self.viewport_bounds } else { 0.0 },
mass_scale: self.mass_scale,
boundary_damping: self.boundary_damping,
}
}
}