From 190cc57033746c38584d7170861e1f1580bf0347 Mon Sep 17 00:00:00 2001 From: Alberto Nidasio <alberto.nidasio@skywarder.eu> Date: Thu, 16 Jan 2025 00:24:00 +0100 Subject: [PATCH] Fixed PID diagram centering --- src/ui/panes/pid_drawing_tool.rs | 5 ++--- src/ui/panes/pid_drawing_tool/elements.rs | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ui/panes/pid_drawing_tool.rs b/src/ui/panes/pid_drawing_tool.rs index 4fcbcf9..0ee1b86 100644 --- a/src/ui/panes/pid_drawing_tool.rs +++ b/src/ui/panes/pid_drawing_tool.rs @@ -275,7 +275,7 @@ impl PidPane { let points: Vec<Vec2> = self .elements .iter() - .map(|e| e.position()) + .map(|e| e.center()) .chain(self.connections.iter().flat_map(|conn| conn.points())) .collect(); @@ -303,8 +303,7 @@ impl PidPane { .unwrap(); let max = Vec2::new(max_x, max_y); - let center_g = (min + max) / 2.0; - self.grid.zero_pos = ui_center - center_g * self.grid.size(); + self.grid.zero_pos = ui_center - min.midpoint(max) * self.grid.size(); } fn handle_zoom(&mut self, ui: &Ui, theme: Theme, pointer_pos: Vec2) { diff --git a/src/ui/panes/pid_drawing_tool/elements.rs b/src/ui/panes/pid_drawing_tool/elements.rs index e3748a1..7db6c72 100644 --- a/src/ui/panes/pid_drawing_tool/elements.rs +++ b/src/ui/panes/pid_drawing_tool/elements.rs @@ -108,9 +108,9 @@ impl Element { self.symbol.size() } - /// Position of the element's top-left corner - pub fn position(&self) -> Vec2 { - self.position + /// Position of the element's center in grid frame + pub fn center(&self) -> Vec2 { + self.position + Mat2::from_angle(self.rotation) * self.size() * 0.5 } pub fn draw(&self, grid: &GridInfo, ui: &Ui, theme: Theme) { -- GitLab