From 01b3635c582bb616d48e85c0d99d93e836c3f6f3 Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Wed, 16 Jul 2025 10:57:52 -0300 Subject: [PATCH] Shorter variant of dynamic segment width computation --- Cargo.lock | 2 +- tools/twix/Cargo.toml | 2 +- tools/twix/src/panels/image_segments.rs | 36 ++++++++++++------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58f684f4bb..c6d5ca58c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8968,7 +8968,7 @@ dependencies = [ [[package]] name = "twix" -version = "0.12.0" +version = "0.12.1" dependencies = [ "aliveness", "argument_parsers", diff --git a/tools/twix/Cargo.toml b/tools/twix/Cargo.toml index 87c8cb7ffc..cf876b6ecd 100644 --- a/tools/twix/Cargo.toml +++ b/tools/twix/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "twix" -version = "0.12.0" +version = "0.12.1" edition.workspace = true license.workspace = true homepage.workspace = true diff --git a/tools/twix/src/panels/image_segments.rs b/tools/twix/src/panels/image_segments.rs index c8d9c91785..81848fc4eb 100644 --- a/tools/twix/src/panels/image_segments.rs +++ b/tools/twix/src/panels/image_segments.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{iter::once, sync::Arc}; use eframe::{ egui::{ComboBox, Response, Ui, Widget}, @@ -13,7 +13,7 @@ use serde_json::{json, Value}; use types::{ camera_position::CameraPosition, color::{Hsv, RgChromaticity, Rgb}, - image_segments::{Direction, EdgeType, ImageSegments, Segment}, + image_segments::{Direction, EdgeType, ImageSegments, ScanLine, Segment}, }; use crate::{ @@ -218,16 +218,22 @@ impl Widget for &mut ImageSegmentsPanel { Direction::Horizontal => image_segments.scan_grid.horizontal_scan_lines, Direction::Vertical => image_segments.scan_grid.vertical_scan_lines, }; + let max = match self.direction { + Direction::Horizontal => 480, + Direction::Vertical => 640, + }; - if let Some([left, right]) = scan_lines.get(0..2) { - let width = (right.position - left.position) as f32 / 2.0; - let position = left.position as f32 + width / 2.0; - for segment in &left.segments { - self.draw_segment(position, width, self.direction, segment, &painter); - } - } - - for (left, center, right) in scan_lines.iter().tuple_windows() { + for (left, center, right) in once(ScanLine { + position: 0, + segments: Vec::new(), + }) + .chain(scan_lines) + .chain(once(ScanLine { + position: max, + segments: Vec::new(), + })) + .tuple_windows() + { let start = left.position as f32 + (center.position - left.position) as f32 / 2.0; let end = center.position as f32 + (right.position - center.position) as f32 / 2.0; let width = end - start; @@ -238,14 +244,6 @@ impl Widget for &mut ImageSegmentsPanel { } } - if let Some([left, right]) = scan_lines.windows(2).last() { - let width = (right.position - left.position) as f32 / 2.0; - let position = left.position as f32 + width / 2.0; - for segment in &left.segments { - self.draw_segment(position, width, self.direction, segment, &painter); - } - } - response } }