Use the simd types where I can

This commit is contained in:
Eryn Wells 2018-10-07 19:32:29 -07:00
parent edce32e021
commit 8f1e1335bd
9 changed files with 107 additions and 144 deletions

View file

@ -8,6 +8,7 @@
import Cocoa
import Foundation
import simd
extension UnsafeMutableRawPointer {
func writeAndAdvance<T>(value: inout T) -> UnsafeMutableRawPointer {
@ -17,38 +18,6 @@ extension UnsafeMutableRawPointer {
}
}
/// Metal's float4 type. 4 bytes per float, 16 bytes total, 16 byte aligned.
public struct Float4 {
public var x: Float = 0
public var y: Float = 0
public var z: Float = 0
public var w: Float = 0
public init() { }
public init(_ x: Float, _ y: Float, _ z: Float, _ w: Float) {
self.x = x
self.y = y
self.z = z
self.w = w
}
public init(r: Float, g: Float, b: Float, a: Float) {
x = r
y = g
z = b
w = a
}
init(color: NSColor) {
if let convertedColor = color.usingColorSpace(NSColorSpace.deviceRGB) {
self.init(Float(convertedColor.redComponent), Float(convertedColor.greenComponent), Float(convertedColor.blueComponent), Float(convertedColor.alphaComponent))
} else {
self.init()
}
}
}
extension NSColor {
convenience init(float4: Float4) {
self.init(deviceRed: CGFloat(float4.x), green: CGFloat(float4.y), blue: CGFloat(float4.z), alpha: CGFloat(float4.w))