nearestDot

$canvaseditor nearestDot
returns dotObj nearest to pointer, preferring constraint gravity.
$canvaseditor nearestDot -gravity
returns dotObj nearest to pointer, preferred constraint gravity
$canvaseditor nearestDot -x
returns dotObj horizontally nearest to pointer
$canvaseditor nearestDot -y
returns dotObj vertically nearest to pointer

For options -selected, -unselected see dots


obj method canvaseditor nearestDot args {
  lappend options
  lappend dotOptions
  while {[string index $args 0] eq "-"} {
    set args [lassign $args option]
    if {$option in { -x -y -far }} then {
      lappend options $option
    } else {
      lappend dotOptions $option
    }
  }
  set dots [$self dots {*}$dotOptions]
  lassign [pointerXY] px py
  set li [lmap dot $dots {
      lassign [$dot xy pointer] dotx doty
      set dx [abs [- $dotx $px]]
      set dy [abs [- $doty $py]]
      set hyp [hypot $dx $dy]
      list $dot $dx $dy $hyp
    }]
  if {"-x" in $options} then {
    set li1 [lsort -real -index 1 $li]
  } elseif {"-y" in $options} then {
    set li1 [lsort -real -index 2 $li]
  } else {
    set li1 [lsort -real -index 3 $li]
  }
  if {"-far" in $options} then {
    [lindex $li1 end 0] {*}$args
  } else {
    [lindex $li1 0 0] {*}$args
  }
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z