Skip to content

Instantly share code, notes, and snippets.

@Dev1an
Created August 8, 2020 10:32
Show Gist options
  • Save Dev1an/7973cee9d960479b35b705f88b7f38c4 to your computer and use it in GitHub Desktop.
Save Dev1an/7973cee9d960479b35b705f88b7f38c4 to your computer and use it in GitHub Desktop.
SIMD extensions for CGPoint and CGSize
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