Hello,
I'd like to perform some math on a fairly large number of CGPoint instances stored in an array so I thought I'd look into using Accelerate and start by conforming CGPoint to AccelerateBuffer, followed by extending Array to conform as well.
My problem is that I don't understand what to do with the requirement
How am I supposed to implement this? Are there any code examples somewhere that I can look into?
Many thanks.
I'd like to perform some math on a fairly large number of CGPoint instances stored in an array so I thought I'd look into using Accelerate and start by conforming CGPoint to AccelerateBuffer, followed by extending Array to conform as well.
My problem is that I don't understand what to do with the requirement
Code Block Swift public func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<CGFloat>) throws -> R) rethrows -> R
How am I supposed to implement this? Are there any code examples somewhere that I can look into?
Many thanks.
Follow-up...
After some more digging, and reading, and trial and error, I managed to get the implementation below, which I think is correct. However, now Xcode gives me a vDSP error that I don't understand, since CGPoint is now conforming to the types that vDSP expects its arguments and return values to have. What am I doing incorrectly?
(The code below is in a Playground)
After some more digging, and reading, and trial and error, I managed to get the implementation below, which I think is correct. However, now Xcode gives me a vDSP error that I don't understand, since CGPoint is now conforming to the types that vDSP expects its arguments and return values to have. What am I doing incorrectly?
(The code below is in a Playground)
Code Block swift import Foundation import CoreGraphics import Accelerate extension CGPoint: AccelerateMutableBuffer { public var count: Int { 2 } public func withUnsafeBufferPointer<R>( _ body: (UnsafeBufferPointer<CGFloat>) throws -> R ) rethrows -> R { var varself = self let ubp = withUnsafeBytes(of: &varself) { urbp in urbp.bindMemory(to: CGFloat.self) } return try body(ubp) } public mutating func withUnsafeMutableBufferPointer<R>( _ body: (inout UnsafeMutableBufferPointer<CGFloat>) throws -> R ) rethrows -> R { var varself = self var ubp = withUnsafeMutableBytes(of: &varself) { urbp in urbp.bindMemory(to: CGFloat.self) } return try body(&ubp) } } let p1 = CGPoint(x: 1.5, y: -3.5) let p2 = CGPoint(x: -0.5, y: 2.5) var p: CGPoint = .zero vDSP.add(p1, p2, result: &p) // Error: "No exact matches in call to static method 'add(_:_:result:)'" p