From c79a2968d7a38871d90e9cd6a861803a749fca93 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 25 Apr 2023 17:09:18 -0400 Subject: Support explicit lexical envs. Narrow envs for tags-and-calibration Another 5ms performance improvement, I think? --- virtual-programs/tags-and-calibration.folk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index dd0622be..497d5ecd 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -74,9 +74,9 @@ proc ::projectorToCamera {projectorPoint} { When tag /tag/ has center /c/ size /size/ { Claim tag $tag is a tag - lassign [cameraToProjector $c] px py + lassign [::cameraToProjector $c] px py Claim $tag is a rectangle with x [expr $px-20] y [expr $py-10] width [expr $size*2] height [expr $size*2] -} +} with environment {} When tag /tag/ is a tag { puts "Added tag $tag" @@ -91,7 +91,7 @@ When tag /tag/ is a tag { When tag /tag/ has corners /corners/ { - set tagcorners [lmap p $corners {cameraToProjector $p}] + set tagcorners [lmap p $corners {::cameraToProjector $p}] foreach tagcorner $tagcorners { Display::text fb {*}$tagcorner 10 "$tag" } set tagbottom [sub [lindex $tagcorners 1] [lindex $tagcorners 0]] set tagright [sub [lindex $tagcorners 2] [lindex $tagcorners 1]] @@ -105,4 +105,8 @@ When tag /tag/ has corners /corners/ { lappend edges [list [expr {[llength $corners] - 1}] 0] set region [list $corners $edges [::tcl::mathfunc::atan2 {*}$tagright]] Claim $tag has region $region +} with environment { + %matmul ::math::linearalgebra::matmul + %sub ::math::linearalgebra::sub + %add ::math::linearalgebra::add } -- cgit v1.2.3 From 00811146559879c300b4cde80c2a6e82712ca31d Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 25 Apr 2023 17:12:50 -0400 Subject: Some label optimizations: think this buys us another 2ms --- virtual-programs/label.folk | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 52bfae11..3d7d7524 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -1,25 +1,24 @@ Wish $this has filename "label.folk" When /thing/ has region /region/ { - set bbox [regionToBbox $region] - lassign [boxCentroid $bbox] x y - set width [boxWidth $bbox] - set height [boxHeight $bbox] + set bbox [regionToBbox $region] + lassign [boxCentroid $bbox] x y - set radians [lindex $region 2] - if {$radians eq ""} {set radians 0} + set radians [lindex $region 2] + if {$radians eq ""} {set radians 0} - When the collected matches for [list /someone/ wishes $thing is labelled /text/] are /matches/ { - set text [join [lmap match $matches {dict get $match text}] "\n"] - if {$text eq ""} { return } + set shouldFlip [expr {abs($radians) < 1.57}] + if {$::isLaptop} { set shouldFlip false } - set lines [split $text "\n"] - set fontSize 12 - for {set lineNum 0} {$lineNum < [llength $lines]} {incr lineNum} { - set shouldFlip [expr {abs($radians) < 1.57}] - if {$::isLaptop} { set shouldFlip false} - set ly [expr {$shouldFlip ? $y+$lineNum*18 : $y+$lineNum*18}] - Display::text device $x $ly $fontSize [lindex [expr {$shouldFlip ? [lreverse $lines] : $lines }] $lineNum] $radians - } - } + When the collected matches for [list /someone/ wishes $thing is labelled /text/] are /matches/ { + set text [join [lmap match $matches {dict get $match text}] "\n"] + if {$text eq ""} { return } + + set lines [split $text "\n"] + set fontSize 12 + for {set lineNum 0} {$lineNum < [llength $lines]} {incr lineNum} { + set ly [expr {$shouldFlip ? $y+$lineNum*18 : $y+$lineNum*18}] + Display::text device $x $ly $fontSize [lindex [expr {$shouldFlip ? [lreverse $lines] : $lines }] $lineNum] $radians + } + } with environment [dict create x $x y $y radians $radians shouldFlip $shouldFlip] } -- cgit v1.2.3 From 55b6a3145b59be3f136463ad2e4299c4707a6584 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 25 Apr 2023 17:19:51 -0400 Subject: More label microoptimization. This is like 0.4ms? --- virtual-programs/label.folk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 3d7d7524..39c2d901 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -15,10 +15,11 @@ When /thing/ has region /region/ { if {$text eq ""} { return } set lines [split $text "\n"] + if {$shouldFlip} {set lines [lreverse $lines]} set fontSize 12 for {set lineNum 0} {$lineNum < [llength $lines]} {incr lineNum} { set ly [expr {$shouldFlip ? $y+$lineNum*18 : $y+$lineNum*18}] - Display::text device $x $ly $fontSize [lindex [expr {$shouldFlip ? [lreverse $lines] : $lines }] $lineNum] $radians + Display::text device $x $ly $fontSize [lindex $lines $lineNum] $radians } } with environment [dict create x $x y $y radians $radians shouldFlip $shouldFlip] } -- cgit v1.2.3 From 9e864bea352d6b6f5abfec45bf858d98409c987f Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 25 Apr 2023 17:20:09 -0400 Subject: Shrink page size. Increase max edges from match so we can hot patch. Page size is now closer to 1/2 of a letter page --- virtual-programs/tags-and-calibration.folk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index 497d5ecd..4a798390 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -96,7 +96,7 @@ When tag /tag/ has corners /corners/ { set tagbottom [sub [lindex $tagcorners 1] [lindex $tagcorners 0]] set tagright [sub [lindex $tagcorners 2] [lindex $tagcorners 1]] - set offsets {{-4.7 -3.5} {1 -3.5} {1 0.8} {-4.7 0.8}} + set offsets {{-4.7 -2.6} {1 -2.6} {1 0.8} {-4.7 0.8}} set corners [add $tagcorners [matmul $offsets [list $tagbottom $tagright]]] set edges [list] for {set i 0} {$i < [llength $corners]} {incr i} { -- cgit v1.2.3 From 450748d213b9d2761a737372749bc48b99e9b86f Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 1 Jun 2023 23:06:11 -0400 Subject: Partly add fn. Laptop GUI mostly works, except label broken --- virtual-programs/label.folk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 137b2ff0..1bb891c1 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -24,7 +24,7 @@ When /thing/ has region /region/ { } with environment [dict create x $x y $y radians $radians shouldFlip $shouldFlip] } -proc text {coords text angle} { +fn text {coords text angle} { Display::text Display::fb [lindex $coords 0] [lindex $coords 1] 2 $text $angle } -- cgit v1.2.3 From 86870a5f33cfb637bd6da0886d5ff362b324e27e Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 1 Jun 2023 23:56:16 -0400 Subject: Fix laptop label --- virtual-programs/label.folk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 1bb891c1..29745a5a 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -21,7 +21,8 @@ When /thing/ has region /region/ { set ly [expr {$shouldFlip ? $y+$lineNum*$fontSize*18 : $y+$lineNum*$fontSize*18}] Display::text device $x $ly $fontSize [lindex $lines $lineNum] $radians } - } with environment [dict create x $x y $y radians $radians shouldFlip $shouldFlip] + } + # with environment [dict create x $x y $y radians $radians shouldFlip $shouldFlip] } fn text {coords text angle} { -- cgit v1.2.3 From a468ae75a835ea2d465e3b140f2b03731e2b2cd8 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 2 Jun 2023 11:47:24 -0400 Subject: Fixes to Pi behavior -- works on table! except music I think --- virtual-programs/tags-and-calibration.folk | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index 28abc644..2015e961 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -71,12 +71,13 @@ proc ::projectorToCamera {projectorPoint} { } # Wish $this is highlighted white -Say when tag /tag/ has center /c/ size /size/ { +When tag /tag/ has center /c/ size /size/ { Claim tag $tag is a tag lassign [::cameraToProjector $c] px py Claim $tag is a rectangle with x [expr $px-20] y [expr $py-10] width [expr $size*2] height [expr $size*2] -} with environment {} +} +# with environment {} When tag /tag/ is a tag { puts "Added tag $tag" @@ -90,7 +91,7 @@ When tag /tag/ is a tag { } -Say when tag /tag/ has corners /corners/ { +When tag /tag/ has corners /corners/ { set tagcorners [lmap p $corners {::cameraToProjector $p}] # foreach tagcorner $tagcorners { Display::text fb {*}$tagcorner 10 "$tag" } Display::fillQuad {*}$tagcorners white @@ -107,8 +108,9 @@ Say when tag /tag/ has corners /corners/ { lappend edges [list [expr {[llength $corners] - 1}] 0] set region [list $corners $edges [::tcl::mathfunc::atan2 {*}$tagright]] Claim $tag has region $region -} with environment { - %matmul ::math::linearalgebra::matmul - %sub ::math::linearalgebra::sub - %add ::math::linearalgebra::add } +# with environment { +# %matmul ::math::linearalgebra::matmul +# %sub ::math::linearalgebra::sub +# %add ::math::linearalgebra::add +# } -- cgit v1.2.3 From 0d01a6696322c972c04e589f71649121bb49a995 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 2 Jun 2023 12:00:12 -0400 Subject: Add (non-capturing) and suppress capture for expensive tag/cal things Improves performance by another few ms --- virtual-programs/tags-and-calibration.folk | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index 2015e961..0d52edf7 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -71,15 +71,14 @@ proc ::projectorToCamera {projectorPoint} { } # Wish $this is highlighted white -When tag /tag/ has center /c/ size /size/ { +When (non-capturing) tag /tag/ has center /c/ size /size/ { Claim tag $tag is a tag lassign [::cameraToProjector $c] px py Claim $tag is a rectangle with x [expr $px-20] y [expr $py-10] width [expr $size*2] height [expr $size*2] } -# with environment {} -When tag /tag/ is a tag { +When (non-capturing) tag /tag/ is a tag { puts "Added tag $tag" set fp [open "$::env(HOME)/folk-printed-programs/$tag.folk" r] @@ -91,7 +90,7 @@ When tag /tag/ is a tag { } -When tag /tag/ has corners /corners/ { +When (non-capturing) tag /tag/ has corners /corners/ { set tagcorners [lmap p $corners {::cameraToProjector $p}] # foreach tagcorner $tagcorners { Display::text fb {*}$tagcorner 10 "$tag" } Display::fillQuad {*}$tagcorners white @@ -109,8 +108,3 @@ When tag /tag/ has corners /corners/ { set region [list $corners $edges [::tcl::mathfunc::atan2 {*}$tagright]] Claim $tag has region $region } -# with environment { -# %matmul ::math::linearalgebra::matmul -# %sub ::math::linearalgebra::sub -# %add ::math::linearalgebra::add -# } -- cgit v1.2.3