Permalink
Browse files

Re-implementing start and end as functions to be relative to the layer

  • Loading branch information...
nvh committed Feb 1, 2018
1 parent 8cc82e7 commit 35dd174f1fa73cf7422e0d465d2afdf7f951258b
Showing with 14 additions and 10 deletions.
  1. +12 −8 framer/SVGPath.coffee
  2. +2 −2 test/tests/LayerAnimationTest.coffee
@@ -102,8 +102,6 @@ class exports.SVGPath extends SVGBaseLayer
path.strokeLength = (path.length - strokeStart) + strokeEnd

@define "length", get: -> @_length
@define "start", get: -> @pointAtFraction(0)
@define "end", get: -> @pointAtFraction(1)

pointAtFraction: (fraction) ->
@_path.getPointAtLength(@length * fraction)
@@ -116,21 +114,27 @@ class exports.SVGPath extends SVGBaseLayer
angle = Math.atan2(fromPoint.y - toPoint.y, fromPoint.x - toPoint.x) * 180 / Math.PI - 90
return angle

start: (relativeToLayer = null) =>
point = @pointAtFraction(0)
point = @convertPointToLayer(point, relativeToLayer?.parent)
point.rotation = @rotationAtFraction(0)
return point

convertStartToLayer: (layer) ->
@convertPointToLayer(@start, layer)
end: (relativeToLayer = null) =>
point = @pointAtFraction(0)
point = @convertPointToLayer(point, relativeToLayer?.parent)
point.rotation = @rotationAtFraction(1)
return point

convertEndToLayer: (layer) ->
@convertPointToLayer(@end, layer)

valueUpdater: (axis, target, offset) =>
switch axis
when "horizontal"
offset -= @start.x
offset -= @pointAtFraction(0).x
return (key, value) =>
target[key] = offset + @pointAtFraction(value).x
when "vertical"
offset -= @start.y
offset -= @pointAtFraction(0).y
return (key, value) =>
target[key] = offset + @pointAtFraction(value).y
when "angle"
@@ -1281,8 +1281,8 @@ describe "LayerAnimation", ->
path = svg.elements.path
l = new Layer
size: 10
midX: path.start.x + path.x
midY: path.start.y + path.y
midPoint: path.start
rotation: path.start().rotation
l.x.should.equal 95 + path.x
l.y.should.equal 45 + path.y
a = l.animate

0 comments on commit 35dd174

Please sign in to comment.