Skip to content

Commit

Permalink
Use Double instead of CGFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
calda committed Oct 21, 2022
1 parent 3d5941b commit 0a28b2f
Show file tree
Hide file tree
Showing 35 changed files with 82 additions and 88 deletions.
Expand Up @@ -77,7 +77,7 @@ class AnimationPreviewViewController: UIViewController {

@objc
func updateAnimation(sender: UISlider) {
animationView.currentProgress = CGFloat(sender.value)
animationView.currentProgress = Double(sender.value)
}

@objc
Expand Down
Expand Up @@ -193,12 +193,12 @@ extension GradientShapeItem {
for colorIndex in 0..<numberOfColors {
let colorStartIndex = colorIndex * 4

let colorLocation = CGFloat(colorComponents[colorStartIndex])
let colorLocation = Double(colorComponents[colorStartIndex])

let color = CGColor.rgb(
CGFloat(colorComponents[colorStartIndex + 1]),
CGFloat(colorComponents[colorStartIndex + 2]),
CGFloat(colorComponents[colorStartIndex + 3]))
Double(colorComponents[colorStartIndex + 1]),
Double(colorComponents[colorStartIndex + 2]),
Double(colorComponents[colorStartIndex + 3]))

colors.append((color: color, location: colorLocation))
}
Expand All @@ -211,8 +211,8 @@ extension GradientShapeItem {
var alphaValues = GradientColorConfiguration()

for alphaIndex in stride(from: numberOfColors * 4, to: colorComponents.endIndex, by: 2) {
let alphaLocation = CGFloat(colorComponents[alphaIndex])
let alphaValue = CGFloat(colorComponents[alphaIndex + 1])
let alphaLocation = Double(colorComponents[alphaIndex])
let alphaValue = Double(colorComponents[alphaIndex + 1])
alphaValues.append((color: .rgba(0, 0, 0, alphaValue), location: alphaLocation))
}

Expand Down
Expand Up @@ -223,7 +223,7 @@ extension CustomizableProperty {
return nil
}

return .rgba(CGFloat(color.r), CGFloat(color.g), CGFloat(color.b), CGFloat(color.a))
return .rgba(Double(color.r), Double(color.g), Double(color.b), Double(color.a))
})
}
}
4 changes: 2 additions & 2 deletions Sources/Private/CoreAnimation/Animations/ShapeAnimation.swift
Expand Up @@ -60,7 +60,7 @@ extension CAShapeLayer {
// Lottie animation files express stoke trims as a numerical percentage value
// (e.g. 25%, 50%, 100%) so we divide by 100 to get the decimal values
// expected by Core Animation (e.g. 0.25, 0.5, 1.0).
CGFloat(strokeStart.cgFloatValue) / CGFloat(pathMultiplier) / 100
Double(strokeStart.cgFloatValue) / Double(pathMultiplier) / 100
}, context: context)

try addAnimation(
Expand All @@ -70,7 +70,7 @@ extension CAShapeLayer {
// Lottie animation files express stoke trims as a numerical percentage value
// (e.g. 25%, 50%, 100%) so we divide by 100 to get the decimal values
// expected by Core Animation (e.g. 0.25, 0.5, 1.0).
CGFloat(strokeEnd.cgFloatValue) / CGFloat(pathMultiplier) / 100
Double(strokeEnd.cgFloatValue) / Double(pathMultiplier) / 100
}, context: context)

return pathMultiplier
Expand Down
Expand Up @@ -36,7 +36,7 @@ extension CAShapeLayer {
func addStrokeAnimations(for stroke: StrokeShapeItem, context: LayerAnimationContext) throws {
lineJoin = stroke.lineJoin.caLineJoin
lineCap = stroke.lineCap.caLineCap
miterLimit = CGFloat(stroke.miterLimit)
miterLimit = Double(stroke.miterLimit)

if let strokeColor = stroke.strokeColor {
try addAnimation(
Expand Down
Expand Up @@ -117,8 +117,8 @@ extension CALayer {
// so we have to divide by the width/height of this layer to get the
// relative decimal values expected by Core Animation.
return CGPoint(
x: CGFloat(absoluteAnchorPoint.x) / bounds.width,
y: CGFloat(absoluteAnchorPoint.y) / bounds.height)
x: Double(absoluteAnchorPoint.x) / bounds.width,
y: Double(absoluteAnchorPoint.y) / bounds.height)
},
context: context)
}
Expand All @@ -142,7 +142,7 @@ extension CALayer {
// https://openradar.appspot.com/FB9862872
// - To work around this, we set up a `rotationY` animation below
// to flip the view horizontally, which gives us the desired effect.
abs(CGFloat(scale.x) / 100)
abs(Double(scale.x) / 100)
},
context: context)

Expand Down Expand Up @@ -180,7 +180,7 @@ extension CALayer {
// - Negative `scaleY` values are correctly applied (they flip the view
// vertically), so we don't have to apply an additional rotation animation
// like we do for `scaleX`.
CGFloat(scale.y) / 100
Double(scale.y) / 100
},
context: context)
}
Expand Down
Expand Up @@ -61,8 +61,8 @@ class BaseCompositionLayer: BaseAnimationLayer {
try addOpacityAnimation(for: baseLayerModel.transform, context: context)

addVisibilityAnimation(
inFrame: CGFloat(baseLayerModel.inFrame),
outFrame: CGFloat(baseLayerModel.outFrame),
inFrame: Double(baseLayerModel.inFrame),
outFrame: Double(baseLayerModel.outFrame),
context: context)
}
}
Expand Down
Expand Up @@ -49,8 +49,8 @@ final class GradientRenderLayer: CAGradientLayer {
y: referencePoint.y + CALayer.veryLargeLayerPadding)

return CGPoint(
x: CGFloat(pointInBounds.x) / bounds.width,
y: CGFloat(pointInBounds.y) / bounds.height)
x: Double(pointInBounds.x) / bounds.width,
y: Double(pointInBounds.y) / bounds.height)
}

// MARK: Private
Expand Down
4 changes: 2 additions & 2 deletions Sources/Private/CoreAnimation/Layers/ImageLayer.swift
Expand Up @@ -73,7 +73,7 @@ extension ImageLayer: CustomLayoutLayer {
bounds = CGRect(
x: superlayerBounds.origin.x,
y: superlayerBounds.origin.y,
width: CGFloat(imageAsset.width),
height: CGFloat(imageAsset.height))
width: Double(imageAsset.width),
height: Double(imageAsset.height))
}
}
6 changes: 3 additions & 3 deletions Sources/Private/CoreAnimation/Layers/PreCompLayer.swift
Expand Up @@ -98,8 +98,8 @@ extension PreCompLayer: CustomLayoutLayer {
bounds = CGRect(
x: superlayerBounds.origin.x,
y: superlayerBounds.origin.y,
width: CGFloat(preCompLayer.width),
height: CGFloat(preCompLayer.height))
width: Double(preCompLayer.width),
height: Double(preCompLayer.height))

masksToBounds = true
}
Expand Down Expand Up @@ -127,7 +127,7 @@ extension KeyframeInterpolator where ValueType == AnimationFrameTime {
let localTimeToGlobalTimeMapping = timeRemappingKeyframes.keyframes.map { keyframe in
Keyframe(
value: keyframe.time,
time: keyframe.value.cgFloatValue * CGFloat(context.animation.framerate),
time: keyframe.value.cgFloatValue * Double(context.animation.framerate),
isHold: keyframe.isHold,
inTangent: keyframe.inTangent,
outTangent: keyframe.outTangent,
Expand Down
8 changes: 4 additions & 4 deletions Sources/Private/CoreAnimation/Layers/TextLayer.swift
Expand Up @@ -69,15 +69,15 @@ final class TextLayer: BaseCompositionLayer {
""")
}

renderLayer.font = context.fontProvider.fontFor(family: text.fontFamily, size: CGFloat(text.fontSize))
renderLayer.font = context.fontProvider.fontFor(family: text.fontFamily, size: Double(text.fontSize))

renderLayer.alignment = text.justification.textAlignment
renderLayer.lineHeight = CGFloat(text.lineHeight)
renderLayer.tracking = (CGFloat(text.fontSize) * CGFloat(text.tracking)) / 1000
renderLayer.lineHeight = Double(text.lineHeight)
renderLayer.tracking = (Double(text.fontSize) * Double(text.tracking)) / 1000

renderLayer.fillColor = text.fillColorData?.cgColorValue
renderLayer.strokeColor = text.strokeColorData?.cgColorValue
renderLayer.strokeWidth = CGFloat(text.strokeWidth ?? 0)
renderLayer.strokeWidth = Double(text.strokeWidth ?? 0)
renderLayer.strokeOnTop = text.strokeOverFill ?? false

renderLayer.preferredSize = text.textFrameSize?.sizeValue
Expand Down
Expand Up @@ -110,16 +110,16 @@ final class TextCompositionLayer: CompositionLayer {
let text = textDocument.value(frame: frame) as! TextDocument
let strokeColor = rootNode?.textOutputNode.strokeColor ?? text.strokeColorData?.cgColorValue
let strokeWidth = rootNode?.textOutputNode.strokeWidth ?? CGFloat(text.strokeWidth ?? 0)
let tracking = (CGFloat(text.fontSize) * (rootNode?.textOutputNode.tracking ?? CGFloat(text.tracking))) / 1000.0
let tracking = (Double(text.fontSize) * (rootNode?.textOutputNode.tracking ?? CGFloat(text.tracking))) / 1000.0
let matrix = rootNode?.textOutputNode.xform ?? CATransform3DIdentity
let textString = textProvider.textFor(keypathName: keypathName, sourceText: text.text)
let ctFont = fontProvider.fontFor(family: text.fontFamily, size: CGFloat(text.fontSize))
let ctFont = fontProvider.fontFor(family: text.fontFamily, size: Double(text.fontSize))

// Set all of the text layer options
textLayer.text = textString
textLayer.font = ctFont
textLayer.alignment = text.justification.textAlignment
textLayer.lineHeight = CGFloat(text.lineHeight)
textLayer.lineHeight = Double(text.lineHeight)
textLayer.tracking = tracking

if let fillColor = rootNode?.textOutputNode.fillColor {
Expand Down
Expand Up @@ -37,7 +37,7 @@ final class MainThreadAnimationLayer: CALayer, RootAnimationLayer {
layerImageProvider: layerImageProvider,
textProvider: textProvider,
fontProvider: fontProvider,
frameRate: CGFloat(animation.framerate))
frameRate: Double(animation.framerate))

var imageLayers = [ImageCompositionLayer]()
var textLayers = [TextCompositionLayer]()
Expand Down
Expand Up @@ -241,7 +241,7 @@ final class CoreTextRenderLayer: CALayer {
let minLineHeight = -(ascent + descent + leading)

// Calculate line spacing
let lineSpacing = max(CGFloat(minLineHeight) + lineHeight, CGFloat(minLineHeight))
let lineSpacing = max(Double(minLineHeight) + lineHeight, Double(minLineHeight))
// Build Attributes
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = lineSpacing
Expand Down
Expand Up @@ -89,7 +89,7 @@ private final class GradientFillLayer: CALayer {
bytesPerRow: ctx.width,
space: maskColorSpace,
bitmapInfo: 0) else { return }
let flipVertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(maskContext.height))
let flipVertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: Double(maskContext.height))
maskContext.concatenate(flipVertical)
maskContext.concatenate(ctx.ctm)
if type == .linear {
Expand Down
Expand Up @@ -111,7 +111,7 @@ final class LegacyGradientFillRenderer: PassThroughOutputNode, Renderable {
bytesPerRow: inContext.width,
space: maskColorSpace,
bitmapInfo: 0) else { return }
let flipVertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(maskContext.height))
let flipVertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: Double(maskContext.height))
maskContext.concatenate(flipVertical)
maskContext.concatenate(inContext.ctm)
if type == .linear {
Expand Down
Expand Up @@ -26,9 +26,9 @@ final class GroupNodeProperties: NodePropertyMap, KeypathSearchable {
skewAxis = NodeProperty(provider: KeyframeInterpolator(keyframes: transform.skewAxis.keyframes))
} else {
/// Transform node missing. Default to empty transform.
anchor = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: CGFloat(0), y: CGFloat(0), z: CGFloat(0))))
position = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: CGFloat(0), y: CGFloat(0), z: CGFloat(0))))
scale = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: CGFloat(100), y: CGFloat(100), z: CGFloat(100))))
anchor = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: Double(0), y: Double(0), z: Double(0))))
position = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: Double(0), y: Double(0), z: Double(0))))
scale = NodeProperty(provider: SingleValueProvider(LottieVector3D(x: Double(100), y: Double(100), z: Double(100))))
rotation = NodeProperty(provider: SingleValueProvider(LottieVector1D(0)))
opacity = NodeProperty(provider: SingleValueProvider(LottieVector1D(100)))
skew = NodeProperty(provider: SingleValueProvider(LottieVector1D(0)))
Expand Down
Expand Up @@ -23,7 +23,7 @@ final class GradientStrokeProperties: NodePropertyMap, KeypathSearchable {
gradientType = gradientStroke.gradientType
numberOfColors = gradientStroke.numberOfColors
width = NodeProperty(provider: KeyframeInterpolator(keyframes: gradientStroke.width.keyframes))
miterLimit = CGFloat(gradientStroke.miterLimit)
miterLimit = Double(gradientStroke.miterLimit)
lineCap = gradientStroke.lineCap
lineJoin = gradientStroke.lineJoin

Expand Down
Expand Up @@ -19,7 +19,7 @@ final class StrokeNodeProperties: NodePropertyMap, KeypathSearchable {
color = NodeProperty(provider: KeyframeInterpolator(keyframes: stroke.color.keyframes))
opacity = NodeProperty(provider: KeyframeInterpolator(keyframes: stroke.opacity.keyframes))
width = NodeProperty(provider: KeyframeInterpolator(keyframes: stroke.width.keyframes))
miterLimit = CGFloat(stroke.miterLimit)
miterLimit = Double(stroke.miterLimit)
lineCap = stroke.lineCap
lineJoin = stroke.lineJoin

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Utility/Extensions/CGFloatExtensions.swift
Expand Up @@ -21,7 +21,7 @@ extension CGFloat {
}

var cubicRoot: CGFloat {
CGFloat(pow(Double(self), 1.0 / 3.0))
Double(pow(Double(self), 1.0 / 3.0))
}

func isInRangeOrEqual(_ from: CGFloat, _ to: CGFloat) -> Bool {
Expand Down
22 changes: 11 additions & 11 deletions Sources/Private/Utility/Extensions/MathKit.swift
Expand Up @@ -11,13 +11,13 @@ import Foundation

extension Int {
var cgFloat: CGFloat {
CGFloat(self)
Double(self)
}
}

extension Double {
var cgFloat: CGFloat {
CGFloat(self)
Double(self)
}
}

Expand All @@ -37,7 +37,7 @@ extension CGFloat {
///
/// 1. The order of arguments does not matter.
func clamp(_ a: CGFloat, _ b: CGFloat) -> CGFloat {
CGFloat(Double(self).clamp(Double(a), Double(b)))
Double(Double(self).clamp(Double(a), Double(b)))
}

/// Returns the difference between the receiver and the given number.
Expand Down Expand Up @@ -272,12 +272,12 @@ extension CGPoint {

/// Operator convenience to divide points with /
static func / (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
CGPoint(x: lhs.x / CGFloat(rhs), y: lhs.y / CGFloat(rhs))
CGPoint(x: lhs.x / Double(rhs), y: lhs.y / Double(rhs))
}

/// Operator convenience to multiply points with *
static func * (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
CGPoint(x: lhs.x * CGFloat(rhs), y: lhs.y * CGFloat(rhs))
CGPoint(x: lhs.x * Double(rhs), y: lhs.y * Double(rhs))
}

/// Operator convenience to add points with +
Expand All @@ -302,7 +302,7 @@ extension CGPoint {
func distanceTo(_ a: CGPoint) -> CGFloat {
let xDist = a.x - x
let yDist = a.y - y
return CGFloat(sqrt((xDist * xDist) + (yDist * yDist)))
return Double(sqrt((xDist * xDist) + (yDist * yDist)))
}

func rounded(decimal: CGFloat) -> CGPoint {
Expand Down Expand Up @@ -333,13 +333,13 @@ extension CGPoint {
return interpolate(to: to, amount: amount)
}

let step = 1 / CGFloat(samples)
let step = 1 / Double(samples)

var points: [(point: CGPoint, distance: CGFloat)] = [(point: self, distance: 0)]
var totalLength: CGFloat = 0

var previousPoint = self
var previousAmount = CGFloat(0)
var previousAmount = Double(0)

var closestPoint = 0

Expand All @@ -362,7 +362,7 @@ extension CGPoint {

var foundPoint = false

var pointAmount = CGFloat(closestPoint) * step
var pointAmount = Double(closestPoint) * step
var nextPointAmount: CGFloat = pointAmount + step

var refineIterations = 0
Expand All @@ -373,7 +373,7 @@ extension CGPoint {
if nextPoint.distance < accurateDistance {
point = nextPoint
closestPoint = closestPoint + 1
pointAmount = CGFloat(closestPoint) * step
pointAmount = Double(closestPoint) * step
nextPointAmount = pointAmount + step
if closestPoint == points.count {
foundPoint = true
Expand All @@ -387,7 +387,7 @@ extension CGPoint {
continue
}
point = points[closestPoint]
pointAmount = CGFloat(closestPoint) * step
pointAmount = Double(closestPoint) * step
nextPointAmount = pointAmount + step
continue
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Private/Utility/Extensions/StringExtensions.swift
Expand Up @@ -30,9 +30,9 @@ extension String {
Scanner(string: cString).scanHexInt64(&rgbValue)

return (
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0)
red: Double((rgbValue & 0xFF0000) >> 16) / 255.0,
green: Double((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: Double(rgbValue & 0x0000FF) / 255.0)
}

}
Expand Up @@ -39,13 +39,13 @@ extension KeyframeGroup where T == LottieVector1D {
// Create one interpolated keyframe for each time in the duration
for t in 0 ... duration {
let progress = timingFunction.value(
for: CGFloat(t) / CGFloat(duration),
for: Double(t) / Double(duration),
epsilon: 0.005)
let value = startValue + Double(progress) * difference
output.append(
Keyframe<LottieVector1D>(
value: LottieVector1D(value),
time: startTime + CGFloat(t),
time: startTime + Double(t),
isHold: false,
inTangent: nil,
outTangent: nil,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/Utility/Primitives/ColorExtension.swift
Expand Up @@ -103,6 +103,6 @@ extension LottieColor {
var cgColorValue: CGColor {
// TODO: Fix color spaces
let colorspace = CGColorSpaceCreateDeviceRGB()
return CGColor(colorSpace: colorspace, components: [CGFloat(r), CGFloat(g), CGFloat(b), CGFloat(a)]) ?? LottieColor.clearColor
return CGColor(colorSpace: colorspace, components: [Double(r), Double(g), Double(b), Double(a)]) ?? LottieColor.clearColor
}
}

0 comments on commit 0a28b2f

Please sign in to comment.