$line intersect
subdivides line to two, reduces own length to first half, returns newly created second half

obj method line intersect {{factor 0.5}} {
  if {[$self cget -smooth]} then {
    lassign [my dots] a b c d
    set firstHalf [bezier segment [$self xy true] 0 $factor]
    set secondHalf [bezier segment [$self xy true] $factor 1]
    lassign $firstHalf - - x y
    $b configure -x $x -y $y
    lassign $firstHalf - - - - x y
    $c configure -x $x -y $y
    lassign $firstHalf - - - - - - x y
    set middle [new dot -x $x -y $y]
    $self remove $d
    $self add $middle
    set newLine [new line $middle]
    lassign $secondHalf - - x y
    $newLine add [new dot -x $x -y $y]
    lassign $secondHalf - - - - x y
    $newLine add [new dot -x $x -y $y] $d
  } else {
    set firstDot [$self firstDot]
    set lastDot [$self lastDot]
    lassign [$self xy true] x0 y0 x1 y1
    set xMid [expr {$x0 + ($x1 - $x0) * $factor}]
    set yMid [expr {$y0 + ($y1 - $y0) * $factor}]
    set midDot [new dot -x $xMid -y $yMid]
    $self remove all
    $self add $firstDot $midDot
    set newLine [new line $midDot $lastDot]
  $newLine configure\
    -width [$self cget -width]\
    -outline [$self cget -outline]\
    -fill [$self cget -fill]\
    -smooth [$self cget -smooth]\
    -constraint [$self cget -constraint]
  set newLine

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