Not sure if this is the right place to post this stuff.
Currently I'm doing some stuff that requires a certain understanding of the implementation of the speed sliders in AXIS.
There are two procs involved that I'm failing to make real sense of. Additionally they seem to either be buggy or the codes purpose is even more obscure than it seems.
It would be great if a dev could have a look at my annotations and check the respective comments on potential bugs.
Also I would appreciate if you could shed some light on what the purpose of the code is.
Thanks.
Code:
# purpose?
# gets two numeric strings, returns an index
# last return stmt out of bounds of s1
proc places {s1 s2} {
# returns index of last int digit of s1
# when s1 > 1 (numeric gt op if s1 is numeric)
# and integer part of s1 and s2 differ
if {$s1 > 1 && int($s1) != int($s2)} {
return [expr {[string first . $s1]-1}]
}
set l1 [string length $s1]
set l2 [string length $s2]
# iterate s1 and s2 starting at pos 15, till end of shorter string
# why start @15? -> val2vel formats with %32.5f so there's a bunch of leading spaces
for {set i 15} {$i < $l1 && $i < $l2} {incr i} {
set c1 [string index $s1 $i]
set c2 [string index $s2 $i]
# return current index
# when
# s1 @ idx isn't a 0 or decimal sep
# s1 and s2 differ @ pos
if {$c1 != "0" && $c1 != "." && $c1 != $c2} { return $i }
}
# just return the len of s1
# all other return values are related to 0-based positions
# is this intentional or -1 is missing?
return [string length $s1]
}
# purpose?
# translates slider val to speed value
# but wiggles the slider val slightly left and right and
# decides what value to return based on 'places'
# bugged, last_... never set / prev_... set but not used
proc val2vel_show {val maxvel} {
# translate slider value [.0, 1.] to speed value
set this_vel [val2vel $val $maxvel]
# prep some vars
set next_places 0
set last_places 0
# get speed value and 'places(current vel, offseted vel)' when offsetting slider by 0.005
# to the left if possible -> next_...
# to the right if possible -> prev_...
if {$val > .005} {
set next_vel [val2vel [expr {$val - .005}] $maxvel]
set next_places [places $this_vel $next_vel]
}
if {$val < .995} {
# this should be last_... there is no prev_...
set prev_vel [val2vel [expr {$val + .005}] $maxvel]
set prev_places [places $this_vel $prev_vel]
}
# compare 'places' and return adjusted string
# last_places still is 0
if {$next_places > $last_places} {
string trim [string range $this_vel 0 $next_places]
} {
string trim [string range $this_vel 0 $last_places]
}
}