From 34fe40bd470793dd0f35a512b9e2c85ff0c8b5ee Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 10 Jul 2023 13:17:04 -0400 Subject: Actually fix stroke --- pi/Display.tcl | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/pi/Display.tcl b/pi/Display.tcl index 5804614d..def14ca6 100644 --- a/pi/Display.tcl +++ b/pi/Display.tcl @@ -289,28 +289,26 @@ namespace eval Display { } proc stroke {points width color} { - for {set i 0} {$i < [llength $points]} {incr i} { - set a [lindex $points $i] - set b [lindex $points [expr $i+1]] - if {$b == ""} break - - # if line is past edge of screen, clip it to the nearest - # point along edge of screen - clipLine a b $width - - set bMinusA [math::linearalgebra::sub $b $a] - if {[lindex $bMinusA 0] == 0.0 || [lindex $bMinusA 1] == 0.0} { - continue - } - set nudge [list [lindex $bMinusA 1] [expr {[lindex $bMinusA 0]*-1}]] - set nudge [math::linearalgebra::scale $width [math::linearalgebra::unitLengthVector $nudge]] - - set a0 [math::linearalgebra::add $a $nudge] - set a1 [math::linearalgebra::sub $a $nudge] - set b0 [math::linearalgebra::add $b $nudge] - set b1 [math::linearalgebra::sub $b $nudge] - fillTriangle $a0 $a1 $b1 [getColor $color] - fillTriangle $a0 $b0 $b1 [getColor $color] + for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} { + try { + set a [lindex $points $i] + set b [lindex $points [expr $i+1]] + + # if line is past edge of screen, clip it to the nearest + # point along edge of screen + clipLine a b $width + + set bMinusA [math::linearalgebra::sub $b $a] + set nudge [list [lindex $bMinusA 1] [expr {[lindex $bMinusA 0]*-1}]] + set nudge [math::linearalgebra::scale $width [math::linearalgebra::unitLengthVector $nudge]] + + set a0 [math::linearalgebra::add $a $nudge] + set a1 [math::linearalgebra::sub $a $nudge] + set b0 [math::linearalgebra::add $b $nudge] + set b1 [math::linearalgebra::sub $b $nudge] + fillTriangle $a0 $a1 $b1 [getColor $color] + fillTriangle $a0 $b0 $b1 [getColor $color] + } on error e {} } } -- cgit v1.2.3