Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Add new APIs for creating springs with initial velocity. (#19)
Browse files Browse the repository at this point in the history
* Add new APIs for creating springs with initial velocity.

* Wrapping parens.
  • Loading branch information
jverkoey committed Nov 10, 2017
1 parent a601fb6 commit 326180f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
32 changes: 28 additions & 4 deletions src/MDMMotionCurve.h
Expand Up @@ -94,6 +94,21 @@ FOUNDATION_EXTERN MDMMotionCurve MDMMotionCurveMakeSpring(float mass, float tens
NS_SWIFT_NAME(MotionCurveMakeSpring(mass:tension:friction:));
// clang-format on

/**
Creates a spring curve with the provided configuration.
Tension and friction map to Core Animation's stiffness and damping, respectively.
See the documentation for CASpringAnimation for more information.
*/
// clang-format off
FOUNDATION_EXTERN MDMMotionCurve MDMMotionCurveMakeSpringWithInitialVelocity(float mass,
float tension,
float friction,
float initialVelocity)
NS_SWIFT_NAME(MotionCurveMakeSpring(mass:tension:friction:initialVelocity:));
// clang-format on

/**
For cubic bezier curves, returns a reversed cubic bezier curve. For all other curve types, a copy
of the original curve is returned.
Expand Down Expand Up @@ -136,21 +151,30 @@ typedef NS_ENUM(NSUInteger, MDMSpringMotionCurveDataIndex) {
// Objective-C-specific macros

#define _MDMBezier(p1x, p1y, p2x, p2y) \
(MDMMotionCurve) { \
((MDMMotionCurve) { \
.type = MDMMotionCurveTypeBezier, \
.data = { p1x, \
p1y, \
p2x, \
p2y } \
}
})

#define _MDMSpring(mass, tension, friction) \
(MDMMotionCurve) { \
((MDMMotionCurve) { \
.type = MDMMotionCurveTypeSpring, \
.data = { mass, \
tension, \
friction } \
}
})

#define _MDMSpringWithInitialVelocity(mass, tension, friction, initialVelocity) \
((MDMMotionCurve) { \
.type = MDMMotionCurveTypeSpring, \
.data = { mass, \
tension, \
friction, \
initialVelocity } \
})

/**
A linear bezier motion curve.
Expand Down
9 changes: 8 additions & 1 deletion src/MDMMotionCurve.m
Expand Up @@ -21,7 +21,14 @@ MDMMotionCurve MDMMotionCurveMakeBezier(float p1x, float p1y, float p2x, float p
}

MDMMotionCurve MDMMotionCurveMakeSpring(float mass, float tension, float friction) {
return _MDMSpring(mass, tension, friction);
return MDMMotionCurveMakeSpringWithInitialVelocity(mass, tension, friction, 0);
}

MDMMotionCurve MDMMotionCurveMakeSpringWithInitialVelocity(float mass,
float tension,
float friction,
float initialVelocity) {
return _MDMSpringWithInitialVelocity(mass, tension, friction, initialVelocity);
}

MDMMotionCurve MDMMotionCurveFromTimingFunction(CAMediaTimingFunction *timingFunction) {
Expand Down

0 comments on commit 326180f

Please sign in to comment.