From 567fd94d8f350a5a3a83d30385d43b79572f8bd6 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sun, 24 Sep 2023 14:00:58 -0400 Subject: [PATCH 1/4] Don't rescale twice --- lib/math.tcl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/math.tcl b/lib/math.tcl index 23efc57b..3e7eab01 100644 --- a/lib/math.tcl +++ b/lib/math.tcl @@ -222,6 +222,7 @@ namespace eval ::region { if {[llength $args] == 1} { set args [list width [lindex $args 0] height [lindex $args 0]] } + set sxp 1; set syp 1 foreach {dim value} $args { set theta [angle $r] set c [centroid $r] @@ -230,7 +231,6 @@ namespace eval ::region { error "region scale: Invalid scale value $value" } - set sxp 1; set syp 1 if {$dim eq "width"} { if {$unit eq "px"} { set sxp [/ $value [width $r]] @@ -250,17 +250,17 @@ namespace eval ::region { } else { error "region scale: Invalid dimension $dim" } - - # TODO: Optimize - set r [mapVertices v $r { - set v [vec2 sub $v $c] - set v [vec2 rotate $v [* -1 $theta]] - set v [vec2 scale $v $sxp $syp] - set v [vec2 rotate $v $theta] - set v [vec2 add $v $c] - set v - }] } + + # TODO: Optimize + set r [mapVertices v $r { + set v [vec2 sub $v $c] + set v [vec2 rotate $v [* -1 $theta]] + set v [vec2 scale $v $sxp $syp] + set v [vec2 rotate $v $theta] + set v [vec2 add $v $c] + set v + }] set r } From 938a0cbe4dc96335f004a7f102fbf32ffa1a471f Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sun, 24 Sep 2023 14:09:03 -0400 Subject: [PATCH 2/4] Fix percentage move and allow region moves of 0x0 --- lib/math.tcl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/math.tcl b/lib/math.tcl index 3e7eab01..d38674c6 100644 --- a/lib/math.tcl +++ b/lib/math.tcl @@ -274,7 +274,6 @@ namespace eval ::region { error "region move: Invalid distance $distance" } if {$unit eq "%"} { - set distance [* $distance 0.01] set unit "" } if {$unit eq ""} { @@ -291,9 +290,6 @@ namespace eval ::region { set dyp [if {$direction eq "up"} {- $distance} \ elseif {$direction eq "down"} {+ $distance} \ else {+ 0}] - if {$dxp == 0 && $dyp == 0} { - error "region move: Invalid direction $direction" - } set dv [vec2 rotate [list $dxp $dyp] $theta] set r [mapVertices v $r {vec2 add $v $dv}] } From 674d1b1652fcb131fafb070355e640c7644e63fd Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 25 Sep 2023 17:40:07 -0400 Subject: [PATCH 3/4] math/region scale: Allow stacking multiple scale actions again --- lib/math.tcl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/math.tcl b/lib/math.tcl index d38674c6..ef6e846e 100644 --- a/lib/math.tcl +++ b/lib/math.tcl @@ -233,19 +233,19 @@ namespace eval ::region { if {$dim eq "width"} { if {$unit eq "px"} { - set sxp [/ $value [width $r]] + set sxp [* $sxp [/ $value [width $r]]] } elseif {$unit eq "%"} { - set sxp [* $value 0.01] + set sxp [* $sxp $value 0.01] } elseif {$unit eq ""} { - set sxp $value + set sxp [* $sxp $value] } } elseif {$dim eq "height"} { if {$unit eq "px"} { - set syp [/ $value [height $r]] + set syp [* $syp [/ $value [height $r]]] } elseif {$unit eq "%"} { - set syp [* $value 0.01] + set syp [* $syp [* $value 0.01]] } elseif {$unit eq ""} { - set syp $value + set syp [* $syp $value] } } else { error "region scale: Invalid dimension $dim" From d94d7ec4f7984a666028982101d38d3fd1ac071a Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 25 Sep 2023 17:43:31 -0400 Subject: [PATCH 4/4] math/region move: Allow unitless scaling again, convert % to that Check direction separately and report error if not valid --- lib/math.tcl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/math.tcl b/lib/math.tcl index ef6e846e..d3869358 100644 --- a/lib/math.tcl +++ b/lib/math.tcl @@ -273,15 +273,21 @@ namespace eval ::region { if {![regexp {([0-9\.]+)(px|%)?} $distance -> distance unit]} { error "region move: Invalid distance $distance" } + if {$direction ne "left" && $direction ne "right" && + $direction ne "up" && $direction ne "down"} { + error "region move: Invalid direction $direction" + } + if {$unit eq "%"} { + set distance [* $distance 0.01] set unit "" } if {$unit eq ""} { # Convert to pixels if {$direction eq "left" || $direction eq "right"} { - set distance [expr {[width $r] * $distance * 0.01}] + set distance [expr {[width $r] * $distance}] } elseif {$direction eq "up" || $direction eq "down"} { - set distance [expr {[height $r] * $distance * 0.01}] + set distance [expr {[height $r] * $distance}] } } set dxp [if {$direction eq "left"} {- $distance} \