func coordinatePairs()

in Cyborg/DrawingCommand.swift [548:575]


    func coordinatePairs() -> Parser<[[CGPoint]]> {
        return { stream, index in
            var floats = [CGFloat]()
            floats.reserveCapacity(self * 2)
            var found = 0
            var next = index
            while case .ok(let value, let index) = number(from: stream, at: next) {
                floats.insert(value, at: found)
                next = index
                found += 1
            }
            if found % 2 == 0 && (found / 2) % self == 0 {
                let numberOfCommandsFound = (found / 2) / self
                var results = [[CGPoint]](repeating: [CGPoint](repeating: .zero, count: self), count: numberOfCommandsFound)
                for i in 0..<numberOfCommandsFound {
                    for j in 0..<self {
                        results[i][j] = CGPoint(x: floats[(i * self + j) * 2],
                                                y: floats[(i * self + j) * 2 + 1])
                    }
                }
                return .ok(results, next)
            } else {
                return .error(.tooFewNumbers(expected: self * 2,
                                             found: found,
                                             .init(index: next, stream: stream)))
            }
        }
    }