Permalink
Browse files

normalize rotation

  • Loading branch information...
J.P.P Treub
J.P.P Treub committed Feb 4, 2016
1 parent e57ec36 commit 1bc5caa840f4f60e92cfa7fa7fdb60346fe556c7
Showing with 21 additions and 0 deletions.
  1. +2 −0 framer/LayerPinchable.coffee
  2. +19 −0 framer/Utils.coffee
@@ -69,6 +69,7 @@ class exports.LayerPinchable extends BaseClass
_pinchStart: (event) =>
@_reset()
@_centerOrigin(event) if @centerOrigin
@normalizeRotation = Utils.rotationNormalizer()
_pinch: (event) =>
@@ -105,6 +106,7 @@ class exports.LayerPinchable extends BaseClass
@_rotationOffset ?= event.rotation
rotation = event.rotation - @_rotationOffset + @_rotationStart
rotation = rotation * @rotateFactor
rotation = @normalizeRotation(rotation)
rotation = Utils.clamp(rotation, @rotateMin, @rotateMax) if (@rotateMin and @rotateMax)
rotation = Utils.nearestIncrement(rotation, @rotateIncrements) if @rotateIncrements
@layer.rotation = rotation
@@ -793,6 +793,25 @@ Utils.frameCenterPoint = (frame) ->
x: Utils.frameGetMidX(frame)
y: Utils.frameGetMidY(frame)
# Rotation
Utils.rotationNormalizer = ->
lastValue = null
return (value) =>
lastValue = value if not lastValue?
diff = lastValue - value
maxDiff = Math.abs(diff) + 180
nTimes = Math.floor(maxDiff / 360)
value -= (nTimes * 360) if diff < 180
value += (nTimes * 360) if diff > 180
lastValue = value
return value
# Coordinate system

0 comments on commit 1bc5caa

Please sign in to comment.