MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / sample_catmull_rom

Function sample_catmull_rom

examples/interactive_spline.rs:146–170  ·  view source on GitHub ↗
(control_points: &[[f64; 2]], samples_per_segment: usize)

Source from the content-addressed store, hash-verified

144}
145
146fn sample_catmull_rom(control_points: &[[f64; 2]], samples_per_segment: usize) -> Vec<[f64; 2]> {
147 if control_points.len() < 2 {
148 return control_points.to_vec();
149 }
150
151 let mut out = Vec::new();
152
153 for i in 0..(control_points.len() - 1) {
154 let p0 = control_points[i.saturating_sub(1)];
155 let p1 = control_points[i];
156 let p2 = control_points[i + 1];
157 let p3 = control_points[(i + 2).min(control_points.len() - 1)];
158
159 for s in 0..samples_per_segment {
160 let t = s as f64 / samples_per_segment as f64;
161 out.push(catmull_rom_point(p0, p1, p2, p3, t));
162 }
163 }
164
165 if let Some(last) = control_points.last().copied() {
166 out.push(last);
167 }
168
169 out
170}
171
172fn catmull_rom_point(p0: [f64; 2], p1: [f64; 2], p2: [f64; 2], p3: [f64; 2], t: f64) -> [f64; 2] {
173 let t2 = t * t;

Callers 2

newMethod · 0.85
move_control_pointMethod · 0.85

Calls 2

catmull_rom_pointFunction · 0.85
newFunction · 0.70

Tested by

no test coverage detected