From 8babea285fb976f35efc6cfe6936af9038d4b096 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 1 Oct 2024 22:40:21 -0600 Subject: [PATCH] Fix edge cases when drawing lines --- src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 265045d..427095b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use macroquad::prelude::*; const THICKNESS: f32 = 2.0; const TAIL_LEN: usize = 250; -#[derive(Clone,Copy)] +#[derive(Clone,Copy, PartialEq)] struct Point { x: f32, y: f32, @@ -117,9 +117,14 @@ impl Tail { let prev = self.previous(index); if self.head == index { + // Draw the head differently draw_circle(point.x, point.y,THICKNESS*2., color); } else if point.x == 0. || point.y == 0. || prev.x == -1. || prev.y == -1. { - draw_circle(point.x, point.y,THICKNESS/2., color); + // Don't have lines that cross the whole screen while using 1D graph + draw_circle(point.x, point.y,THICKNESS, color); + } else if prev == self.points[self.head] { + // Prevent the tail from connecting to the head + draw_circle(point.x, point.y,THICKNESS, color); } else { draw_line(point.x, point.y, prev.x, prev.y, THICKNESS, color); } @@ -143,7 +148,7 @@ async fn main() { // Dot params let mut y_displacement = 0.; let mut x_displacement = 0.; - let mut tail = Tail::new(Axis::One); + let mut tail = Tail::new(Axis::Two); // Selection box let mut inital_x_pos = 0.;