Skip to content

Instantly share code, notes, and snippets.

View seadiem's full-sized avatar

seadiem

  • Saints-Petersburg, Russia
View GitHub Profile
import CoreGraphics
import CoreImage
public struct ImageBufferMaker {
let diagonal: SIMD2<Int>
public init(diagonal: SIMD2<Int>) {
self.diagonal = diagonal
}
@seadiem
seadiem / MakeRawsFromGreed.swift
Last active December 20, 2019 15:30
Make Raws From a Greed (Generic)
public protocol TwoDimensional {
associatedtype Measure: SignedNumeric, Comparable
var xmesure: Measure { get set }
var ymesure: Measure { get set }
}
/// * (0,3)(1,3)(2,3)(3,3)
/// * (0,2)(1,2)(2,2)(3,2)
/// * (0,1)(1,1)(2,1)(3,1)
/// * (0,0)(1,0)(2,0)(3,0) -> (0,0)(1,0)(2,0)(3,0), (0,1)(1,1)(2,1)(3,1) ...
@seadiem
seadiem / EachToEach.swift
Last active September 30, 2019 13:12
Each To Each (Generic)
/// [1, 2, 3, 4, 5, 6] -> (1,2) (1,3) (1,3) (1,4) (1,5) (1, 6) (2,3) (2,4) (2,5) (2,6) ...
public func eachToEachIn<C: Collection>(c: C) -> [(left: C.Element, right: C.Element)]? where C.Element: Hashable {
guard c.count > 1 else { return nil }
var rightindex = c.startIndex
var leftindex = c.startIndex
var controlSet = Set<CoupleUnorderer<C.Element>>()
while rightindex < c.endIndex {
while leftindex < c.endIndex {
let left = c[leftindex]