Created
August 8, 2020 10:32
-
-
Save Dev1an/7973cee9d960479b35b705f88b7f38c4 to your computer and use it in GitHub Desktop.
SIMD extensions for CGPoint and CGSize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct CoreGraphics.CGSize | |
import struct CoreGraphics.CGPoint | |
import struct CoreGraphics.CGFloat | |
extension CGSize: SIMD { | |
public typealias MaskStorage = SIMD2<CGFloat.NativeType.SIMDMaskScalar> | |
public subscript(index: Int) -> CGFloat { | |
get { | |
index == 0 ? width : height | |
} | |
set(newValue) { | |
if index == 0 { width = newValue } | |
else { height = newValue } | |
} | |
} | |
public var scalarCount: Int { 2 } | |
public typealias Scalar = CGFloat | |
} | |
extension CGPoint: SIMD { | |
public typealias MaskStorage = SIMD2<CGFloat.NativeType.SIMDMaskScalar> | |
public subscript(index: Int) -> CGFloat { | |
get { | |
index == 0 ? x : y | |
} | |
set(newValue) { | |
if index == 0 { x = newValue } | |
else { y = newValue } | |
} | |
} | |
public var scalarCount: Int { 2 } | |
public typealias Scalar = CGFloat | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment