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

Method scan_best_id

src/picking.rs:580–618  ·  view source on GitHub ↗
(
        data: &[u8],
        bytes_per_row: u32,
        max_w: u32,
        max_h: u32,
        min_x: u32,
        min_y: u32,
        cx: u32,
        cy: u32,
    )

Source from the content-addressed store, hash-verified

578
579 #[allow(clippy::too_many_arguments)]
580 fn scan_best_id(
581 data: &[u8],
582 bytes_per_row: u32,
583 max_w: u32,
584 max_h: u32,
585 min_x: u32,
586 min_y: u32,
587 cx: u32,
588 cy: u32,
589 ) -> Option<(u32, i32)> {
590 let mut best: Option<(u32, i32)> = None;
591 for row in 0..max_h as usize {
592 let row_off = row as u64 * bytes_per_row as u64;
593 for col in 0..max_w as usize {
594 let off = row_off + (col as u64) * 4;
595 let id = u32::from_le_bytes([
596 data[off as usize],
597 data[off as usize + 1],
598 data[off as usize + 2],
599 data[off as usize + 3],
600 ]);
601 if id != 0 {
602 let sx = min_x as i32 + col as i32;
603 let sy = min_y as i32 + row as i32;
604 let dx = sx - cx as i32;
605 let dy = sy - cy as i32;
606 let d2 = dx * dx + dy * dy;
607 if let Some((_, bd2)) = best {
608 if d2 < bd2 {
609 best = Some((id, d2));
610 }
611 } else {
612 best = Some((id, d2));
613 }
614 }
615 }
616 }
617 best
618 }
619
620 fn ensure_staging(&mut self, device: &Device, needed: u64) {
621 if self

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected