From eb69cd6a28f86bb6fc5af0ef628f114b562c3db2 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Tue, 21 Nov 2023 02:32:45 +0000 Subject: Region helper to create a new region center on x y --- lib/math.tcl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/math.tcl b/lib/math.tcl index cec6eee7..c87226cc 100644 --- a/lib/math.tcl +++ b/lib/math.tcl @@ -63,6 +63,18 @@ namespace eval ::region { list $vertices $edges $angle } + proc newRegion {x y w h {angle 0}} { + set hw [expr {$w / 2.}] + set hh [expr {$h / 2.}] + set vertices [list \ + [list [expr {$x-$hw}] [expr {$y+$hh}]] \ + [list [expr {$x+$hw}] [expr {$y+$hh}]] \ + [list [expr {$x+$hw}] [expr {$y-$hh}]] \ + [list [expr {$x-$hw}] [expr {$y-$hh}]]] + set edges [list [list 0 1] [list 1 2] [list 2 3] [list 3 0]] + region rotate [region create $vertices $edges] $angle + } + proc vertices {r} { lindex $r 0 } proc edges {r} { lindex $r 1 } # Angle the region is rotated above the horizontal, in radians: -- cgit v1.2.3