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

Function build_fill_span

src/plot_state.rs:1184–1302  ·  view source on GitHub ↗
(
    widget: &PlotWidget,
    begin: ShapeId,
    end: ShapeId,
    color: Color,
    x_domain: Option<(f64, f64)>,
    y_domain: Option<(f64, f64)>,
    axis_ranges: ([f64; 2], [f64; 2]),
)

Source from the content-addressed store, hash-verified

1182 if a.len() < 2 || b.len() < 2 {
1183 return None;
1184 }
1185
1186 let overlap_min = a.first()?[0].max(b.first()?[0]);
1187 let overlap_max = a.last()?[0].min(b.last()?[0]);
1188 if overlap_min >= overlap_max {
1189 return None;
1190 }
1191
1192 let mut seg_a = find_segment_covering_x(&a, overlap_min)?;
1193 let mut seg_b = find_segment_covering_x(&b, overlap_min)?;
1194
1195 let mut x_curr = overlap_min;
1196 let mut y_a_curr = y_at_x_in_segment(&a, seg_a, x_curr)?;
1197 let mut y_b_curr = y_at_x_in_segment(&b, seg_b, x_curr)?;
1198
1199 let eps = 1e-12;
1200 loop {
1201 let next_a = a.get(seg_a + 1).map(|p| p[0]).unwrap_or(f64::INFINITY);
1202 let next_b = b.get(seg_b + 1).map(|p| p[0]).unwrap_or(f64::INFINITY);
1203 let x_next = next_a.min(next_b).min(overlap_max);
1204
1205 if x_next <= x_curr + eps {
1206 break;
1207 }
1208
1209 let y_a_next = y_at_x_in_segment(&a, seg_a, x_next)?;
1210 let y_b_next = y_at_x_in_segment(&b, seg_b, x_next)?;
1211
1212 push_quad_as_triangles(
1213 vertices,
1214 [x_curr, y_a_curr],
1215 [x_curr, y_b_curr],
1216 [x_next, y_a_next],
1217 [x_next, y_b_next],
1218 );
1219
1220 x_curr = x_next;
1221 y_a_curr = y_a_next;
1222 y_b_curr = y_b_next;
1223
1224 if x_curr >= overlap_max - eps {
1225 break;
1226 }
1227
1228 advance_segment_to_x(&a, &mut seg_a, x_curr);
1229 advance_segment_to_x(&b, &mut seg_b, x_curr);
1230
1231 if seg_a + 1 >= a.len() || seg_b + 1 >= b.len() {
1232 break;
1233 }
1234 }
1235
1236 Some(())
1237}
1238
1239fn build_fill_span(
1240 widget: &PlotWidget,
1241 begin: ShapeId,

Callers 1

rebuild_from_widgetMethod · 0.85

Calls 8

resolve_fill_endpointFunction · 0.85
push_quad_as_trianglesFunction · 0.85
is_emptyMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected