Fix edge cases when drawing lines

This commit is contained in:
2024-10-01 22:40:21 -06:00
parent 35ae384a43
commit 8babea285f

View File

@@ -6,7 +6,7 @@ use macroquad::prelude::*;
const THICKNESS: f32 = 2.0; const THICKNESS: f32 = 2.0;
const TAIL_LEN: usize = 250; const TAIL_LEN: usize = 250;
#[derive(Clone,Copy)] #[derive(Clone,Copy, PartialEq)]
struct Point { struct Point {
x: f32, x: f32,
y: f32, y: f32,
@@ -117,9 +117,14 @@ impl Tail {
let prev = self.previous(index); let prev = self.previous(index);
if self.head == index { if self.head == index {
// Draw the head differently
draw_circle(point.x, point.y,THICKNESS*2., color); draw_circle(point.x, point.y,THICKNESS*2., color);
} else if point.x == 0. || point.y == 0. || prev.x == -1. || prev.y == -1. { } 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 { } else {
draw_line(point.x, point.y, prev.x, prev.y, THICKNESS, color); draw_line(point.x, point.y, prev.x, prev.y, THICKNESS, color);
} }
@@ -143,7 +148,7 @@ async fn main() {
// Dot params // Dot params
let mut y_displacement = 0.; let mut y_displacement = 0.;
let mut x_displacement = 0.; let mut x_displacement = 0.;
let mut tail = Tail::new(Axis::One); let mut tail = Tail::new(Axis::Two);
// Selection box // Selection box
let mut inital_x_pos = 0.; let mut inital_x_pos = 0.;