changeset 1761:3ddd5b4964b3

fix time adjs crossing each other. more simulation steps for adjs. Ignore-this: 8a14c5c954ca1dd9dbc1180386fa875a
author drewp@bigasterisk.com
date Thu, 31 May 2018 00:47:07 +0000
parents f2f2206281c4
children a67d1a95ebf9
files light9/web/timeline/adjusters.coffee light9/web/timeline/timeline.coffee
diffstat 2 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/timeline/adjusters.coffee	Tue May 29 07:55:05 2018 +0000
+++ b/light9/web/timeline/adjusters.coffee	Thu May 31 00:47:07 2018 +0000
@@ -12,7 +12,7 @@
   ]
   constructor: ->
     super()
-    @redraw = _.throttle(@_throttledRedraw.bind(@), 60, {leading: false})
+    @redraw = _.throttle(@_throttledRedraw.bind(@), 30, {leading: false})
     @adjs = {}
     
   ready: ->
@@ -93,13 +93,13 @@
     for adjId, adj of @adjs
       ctr = adj.getHandle()
       target = adj.getTarget()
-      if target.e(1) < 0 or target.e(1) > @$.canvas.width or target.e(2) < 0 or target.e(2) > @$.canvas.height
+      if @_isOffScreen(target)
         continue
       @_drawConnector(ctr, target)
       
       @_drawAdjuster(adj.getDisplayValue(),
-                     Math.floor(ctr.e(1)) - 20, Math.floor(ctr.e(2)) - 10,
-                     Math.floor(ctr.e(1)) + 20, Math.floor(ctr.e(2)) + 10)
+                     ctr.e(1) - 20, ctr.e(2) - 10,
+                     ctr.e(1) + 20, ctr.e(2) + 10)
     console.timeEnd('adjs redraw')
 
   _layoutCenters: ->
@@ -110,9 +110,10 @@
     @qt.extent([[0,0], [8000,8000]])
 
     for _, adj of @adjs
-      adj.handle = adj.getSuggestedHandle()
-      
-    for tries in [0...5]
+      adj.handle = @_clampOnScreen(adj.getSuggestedHandle())
+
+    numTries = 8
+    for tries in [0...numTries]
       for _, adj of @adjs
         current = adj.handle
         @qt.remove(current)
@@ -120,12 +121,7 @@
         if nearest
           dist = current.distanceFrom(nearest)
           if dist < maxDist
-            away = current.subtract(nearest).toUnitVector()
-            toScreenCenter = @canvasCenter.subtract(current).toUnitVector()
-            current = current.add(away.x(20).add(toScreenCenter.x(2)))
-            marg = 10
-            current = $V([Math.max(marg, Math.min(@$.canvas.width - marg, current.e(1))),
-                         Math.max(marg, Math.min(@$.canvas.height - marg, current.e(2)))])
+            current = @_stepAway(current, nearest, 1 / numTries)
             adj.handle = current
         current.adj = adj
         @qt.add(current)
@@ -134,7 +130,21 @@
       #  output.setElements([
       #    Math.max(20, output.e(1)),
       #    output.e(2)])
-        
+
+  _stepAway: (current, nearest, dx) ->
+    away = current.subtract(nearest).toUnitVector()
+    toScreenCenter = @canvasCenter.subtract(current).toUnitVector()
+    goalSpacingPx = 20
+    @_clampOnScreen(current.add(away.x(goalSpacingPx * dx)))
+
+  _isOffScreen: (pos) ->
+    pos.e(1) < 0 or pos.e(1) > @$.canvas.width or pos.e(2) < 0 or pos.e(2) > @$.canvas.height
+
+  _clampOnScreen: (pos) ->    
+    marg = 30
+    $V([Math.max(marg, Math.min(@$.canvas.width - marg, pos.e(1))),
+        Math.max(marg, Math.min(@$.canvas.height - marg, pos.e(2)))])
+                        
   _drawConnector: (ctr, target) ->
     @ctx.strokeStyle = '#aaa'
     @ctx.lineWidth = 2
--- a/light9/web/timeline/timeline.coffee	Tue May 29 07:55:05 2018 +0000
+++ b/light9/web/timeline/timeline.coffee	Thu May 31 00:47:07 2018 +0000
@@ -243,7 +243,7 @@
       observable: @viewState.zoomSpec.t1,
       getTarget: () =>
         $V([@viewState.fullZoomX(@viewState.zoomSpec.t1()), yMid()])
-      getSuggestedTargetOffset: () => $V([50, 10])
+      getSuggestedTargetOffset: () => $V([-50, 10])
       getValueForPos: valForPos
     }))
 
@@ -251,7 +251,7 @@
       observable: @viewState.zoomSpec.t2,
       getTarget: () =>
         $V([@viewState.fullZoomX(@viewState.zoomSpec.t2()), yMid()])
-      getSuggestedTargetOffset: () => $V([-50, 10])
+      getSuggestedTargetOffset: () => $V([50, 10])
       getValueForPos: valForPos
     }))