git.iko.soy/metal-metaballs
on master help sign in
.gitignore+1
since splitsnapshots
unifiedsplit
@@ -1,6 +1,7 @@
1.DS*
1.DS*
2PixelImage.xcodeproj/xcuserdata/*
2PixelImage.xcodeproj/xcuserdata/*
3PixelImage.xcodeproj/project.xcworkspace/xcuserdata/*
3PixelImage.xcodeproj/project.xcworkspace/xcuserdata/*
4+PixelImage.xcworkspace/xcuserdata/*
4
5
5Pods/*
6Pods/*
6
7
.tailor.ymlnew file+14
@@ -0,0 +1,14 @@
1+
2+
3+# Tailor will check for violations to all rules except for the following ones
4+except:
5+ - constant-k-prefix
6+ - function-whitespace
7+ - leading-whitespace
8+
9+# include:
10+# - Source # Inspect all Swift files under "Source/"
11+exclude:
12+ - Pods # Ignore Swift files under "Pods/"
13+ - PixelImage/SwiftSugar/SwiftSequences
14+
Examples/Animation.gifnew file

Binary file not shown.

PixelImage.xcodeproj/project.pbxproj+83−205
@@ -22,38 +22,15 @@
22 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */; };
22 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */; };
23 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */; };
23 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */; };
24 24ED21CD1C6C2397009C40FC /* MetaballDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */; };
24 24ED21CD1C6C2397009C40FC /* MetaballDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */; };
25− 24FFA86B1C6BA038005ACD60 /* ApproximationOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */; };
25+ 24FC38341C7F931E0085C04A /* Metaball.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FC38331C7F931E0085C04A /* Metaball.swift */; };
26− 24FFA86C1C6BA038005ACD60 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84D1C6BA038005ACD60 /* Collections.swift */; };
26+ 24FC38361C7F9ABE0085C04A /* Dispatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FC38351C7F9ABE0085C04A /* Dispatch.swift */; };
27− 24FFA86D1C6BA038005ACD60 /* ComparatorChains.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */; };
28− 24FFA86E1C6BA038005ACD60 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */; };
29− 24FFA86F1C6BA038005ACD60 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8511C6BA038005ACD60 /* NSNumber.swift */; };
30 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8521C6BA038005ACD60 /* Numeric.swift */; };
27 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8521C6BA038005ACD60 /* Numeric.swift */; };
31 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */; };
28 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */; };
32− 24FFA8721C6BA038005ACD60 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8541C6BA038005ACD60 /* Sequence.swift */; };
33− 24FFA8731C6BA038005ACD60 /* Memoize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8561C6BA038005ACD60 /* Memoize.swift */; };
34− 24FFA8741C6BA038005ACD60 /* SignOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8571C6BA038005ACD60 /* SignOperator.swift */; };
35− 24FFA8751C6BA038005ACD60 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8581C6BA038005ACD60 /* String.swift */; };
36− 24FFA8761C6BA038005ACD60 /* Categorise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85A1C6BA038005ACD60 /* Categorise.swift */; };
37− 24FFA8771C6BA038005ACD60 /* ChunkWindowSplit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */; };
38− 24FFA8781C6BA038005ACD60 /* Combinations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85C1C6BA038005ACD60 /* Combinations.swift */; };
39− 24FFA8791C6BA038005ACD60 /* Cycle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85D1C6BA038005ACD60 /* Cycle.swift */; };
40− 24FFA87A1C6BA038005ACD60 /* Enumerate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */; };
41− 24FFA87B1C6BA038005ACD60 /* Finding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85F1C6BA038005ACD60 /* Finding.swift */; };
42− 24FFA87C1C6BA038005ACD60 /* FlatMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8601C6BA038005ACD60 /* FlatMap.swift */; };
43− 24FFA87D1C6BA038005ACD60 /* Hopping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8611C6BA038005ACD60 /* Hopping.swift */; };
44− 24FFA87E1C6BA038005ACD60 /* Interpose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8621C6BA038005ACD60 /* Interpose.swift */; };
45− 24FFA87F1C6BA038005ACD60 /* Iterate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8631C6BA038005ACD60 /* Iterate.swift */; };
46− 24FFA8801C6BA038005ACD60 /* NestedSequences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */; };
47− 24FFA8811C6BA038005ACD60 /* Permutations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8651C6BA038005ACD60 /* Permutations.swift */; };
48− 24FFA8821C6BA038005ACD60 /* ScanReduce.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */; };
49− 24FFA8831C6BA038005ACD60 /* Slicing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8671C6BA038005ACD60 /* Slicing.swift */; };
50− 24FFA8841C6BA038005ACD60 /* TakeDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */; };
51− 24FFA8851C6BA038005ACD60 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8691C6BA038005ACD60 /* Zip.swift */; };
52− 24FFA8861C6BA038005ACD60 /* TestCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */; };
53− 2BF7957B6518CA68241BB2CE /* Pods_PixelImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C55F9558B3B267413C3A07A6 /* Pods_PixelImage.framework */; };
29+ 400CECBA73C835B415805169 /* Pods_PixelImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93D10DBF530542A19EEF699A /* Pods_PixelImage.framework */; };
54/* End PBXBuildFile section */
30/* End PBXBuildFile section */
55
31
56/* Begin PBXFileReference section */
32/* Begin PBXFileReference section */
33+ 0C9CE70F7D2C2896912B7B14 /* Pods-PixelImage.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PixelImage.release.xcconfig"; path = "Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage.release.xcconfig"; sourceTree = "<group>"; };
57 242686841C63B72A00D62456 /* PixelImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PixelImage.app; sourceTree = BUILT_PRODUCTS_DIR; };
34 242686841C63B72A00D62456 /* PixelImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PixelImage.app; sourceTree = BUILT_PRODUCTS_DIR; };
58 242686871C63B72A00D62456 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
35 242686871C63B72A00D62456 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
59 242686891C63B72A00D62456 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
36 242686891C63B72A00D62456 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -71,37 +48,12 @@
71 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Metal.swift; sourceTree = "<group>"; };
48 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Metal.swift; sourceTree = "<group>"; };
72 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = shaders.metal; sourceTree = "<group>"; };
49 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = shaders.metal; sourceTree = "<group>"; };
73 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaballDataSource.swift; sourceTree = "<group>"; };
50 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaballDataSource.swift; sourceTree = "<group>"; };
74− 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApproximationOperator.swift; sourceTree = "<group>"; };
51+ 24FC38331C7F931E0085C04A /* Metaball.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Metaball.swift; sourceTree = "<group>"; };
75− 24FFA84D1C6BA038005ACD60 /* Collections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Collections.swift; sourceTree = "<group>"; };
52+ 24FC38351C7F9ABE0085C04A /* Dispatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dispatch.swift; sourceTree = "<group>"; };
76− 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparatorChains.swift; sourceTree = "<group>"; };
77− 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
78− 24FFA8511C6BA038005ACD60 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = "<group>"; };
79− 24FFA8521C6BA038005ACD60 /* Numeric.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Numeric.swift; sourceTree = "<group>"; };
53+ 24FFA8521C6BA038005ACD60 /* Numeric.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Numeric.swift; path = SwiftSugar/Numeric.swift; sourceTree = "<group>"; };
80− 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PowerOperator.swift; sourceTree = "<group>"; };
54+ 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PowerOperator.swift; path = SwiftSugar/PowerOperator.swift; sourceTree = "<group>"; };
81− 24FFA8541C6BA038005ACD60 /* Sequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = "<group>"; };
82− 24FFA8561C6BA038005ACD60 /* Memoize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Memoize.swift; sourceTree = "<group>"; };
83− 24FFA8571C6BA038005ACD60 /* SignOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignOperator.swift; sourceTree = "<group>"; };
84− 24FFA8581C6BA038005ACD60 /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
85− 24FFA85A1C6BA038005ACD60 /* Categorise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Categorise.swift; sourceTree = "<group>"; };
86− 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChunkWindowSplit.swift; sourceTree = "<group>"; };
87− 24FFA85C1C6BA038005ACD60 /* Combinations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinations.swift; sourceTree = "<group>"; };
88− 24FFA85D1C6BA038005ACD60 /* Cycle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cycle.swift; sourceTree = "<group>"; };
89− 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enumerate.swift; sourceTree = "<group>"; };
90− 24FFA85F1C6BA038005ACD60 /* Finding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Finding.swift; sourceTree = "<group>"; };
91− 24FFA8601C6BA038005ACD60 /* FlatMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlatMap.swift; sourceTree = "<group>"; };
92− 24FFA8611C6BA038005ACD60 /* Hopping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hopping.swift; sourceTree = "<group>"; };
93− 24FFA8621C6BA038005ACD60 /* Interpose.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Interpose.swift; sourceTree = "<group>"; };
94− 24FFA8631C6BA038005ACD60 /* Iterate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Iterate.swift; sourceTree = "<group>"; };
95− 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedSequences.swift; sourceTree = "<group>"; };
96− 24FFA8651C6BA038005ACD60 /* Permutations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Permutations.swift; sourceTree = "<group>"; };
97− 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanReduce.swift; sourceTree = "<group>"; };
98− 24FFA8671C6BA038005ACD60 /* Slicing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Slicing.swift; sourceTree = "<group>"; };
99− 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TakeDrop.swift; sourceTree = "<group>"; };
100− 24FFA8691C6BA038005ACD60 /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
101− 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCommons.swift; sourceTree = "<group>"; };
102− B1A755EFC03DA2A172C2B82F /* Pods-PixelImage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PixelImage.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage.debug.xcconfig"; sourceTree = "<group>"; };
55+ 6659D12A5984961F335BDF69 /* Pods-PixelImage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PixelImage.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage.debug.xcconfig"; sourceTree = "<group>"; };
103− C419D37C90A6BE8B5139806A /* Pods-PixelImage.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PixelImage.release.xcconfig"; path = "Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage.release.xcconfig"; sourceTree = "<group>"; };
104− C55F9558B3B267413C3A07A6 /* Pods_PixelImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PixelImage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
56+ 93D10DBF530542A19EEF699A /* Pods_PixelImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PixelImage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
105/* End PBXFileReference section */
57/* End PBXFileReference section */
106
58
107/* Begin PBXFrameworksBuildPhase section */
59/* Begin PBXFrameworksBuildPhase section */
@@ -111,13 +63,22 @@
111 files = (
63 files = (
112 24E1E7E41C67D39300ECF1C4 /* MetalKit.framework in Frameworks */,
64 24E1E7E41C67D39300ECF1C4 /* MetalKit.framework in Frameworks */,
113 24E1E7E21C67D37F00ECF1C4 /* Metal.framework in Frameworks */,
65 24E1E7E21C67D37F00ECF1C4 /* Metal.framework in Frameworks */,
114− 2BF7957B6518CA68241BB2CE /* Pods_PixelImage.framework in Frameworks */,
66+ 400CECBA73C835B415805169 /* Pods_PixelImage.framework in Frameworks */,
115 );
67 );
116 runOnlyForDeploymentPostprocessing = 0;
68 runOnlyForDeploymentPostprocessing = 0;
117 };
69 };
118/* End PBXFrameworksBuildPhase section */
70/* End PBXFrameworksBuildPhase section */
119
71
120/* Begin PBXGroup section */
72/* Begin PBXGroup section */
73+ 0C205AE1A1A55E89EFAEE593 /* Pods */ = {
74+ isa = PBXGroup;
75+ children = (
76+ 6659D12A5984961F335BDF69 /* Pods-PixelImage.debug.xcconfig */,
77+ 0C9CE70F7D2C2896912B7B14 /* Pods-PixelImage.release.xcconfig */,
78+ );
79+ name = Pods;
80+ sourceTree = "<group>";
81+ };
121 2426867B1C63B72A00D62456 = {
82 2426867B1C63B72A00D62456 = {
122 isa = PBXGroup;
83 isa = PBXGroup;
123 children = (
84 children = (
@@ -125,8 +86,8 @@
125 24E1E7E11C67D37F00ECF1C4 /* Metal.framework */,
86 24E1E7E11C67D37F00ECF1C4 /* Metal.framework */,
126 242686861C63B72A00D62456 /* PixelImage */,
87 242686861C63B72A00D62456 /* PixelImage */,
127 242686851C63B72A00D62456 /* Products */,
88 242686851C63B72A00D62456 /* Products */,
128− F1933B48ED44BA9FCD7A4A1F /* Pods */,
89+ 0C205AE1A1A55E89EFAEE593 /* Pods */,
129− 588576572D7A188031904848 /* Frameworks */,
90+ 8C02F866C2C0C9A954BB9375 /* Frameworks */,
130 );
91 );
131 sourceTree = "<group>";
92 sourceTree = "<group>";
132 };
93 };
@@ -141,16 +102,20 @@
141 242686861C63B72A00D62456 /* PixelImage */ = {
102 242686861C63B72A00D62456 /* PixelImage */ = {
142 isa = PBXGroup;
103 isa = PBXGroup;
143 children = (
104 children = (
144− 24FFA84B1C6BA038005ACD60 /* SwiftSugar */,
105+ 2461651A1C6DA4F400A913C8 /* Interpolation.swift */,
106+ 24FFA8521C6BA038005ACD60 /* Numeric.swift */,
107+ 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */,
145 242686871C63B72A00D62456 /* AppDelegate.swift */,
108 242686871C63B72A00D62456 /* AppDelegate.swift */,
146− 242686891C63B72A00D62456 /* ViewController.swift */,
109+ 24FC38351C7F9ABE0085C04A /* Dispatch.swift */,
147 24E1E7D61C67C8B200ECF1C4 /* UIKit.swift */,
110 24E1E7D61C67C8B200ECF1C4 /* UIKit.swift */,
148 246B0F821C70635D00A71D05 /* UIColor.swift */,
111 246B0F821C70635D00A71D05 /* UIColor.swift */,
149− 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */,
112+ 24FC38331C7F931E0085C04A /* Metaball.swift */,
150− 24E1E7EA1C67D70300ECF1C4 /* MetalMetaballRenderer.swift */,
151 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */,
113 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */,
152 249CF84B1C6D113C008B0C78 /* Matrix.swift */,
114 249CF84B1C6D113C008B0C78 /* Matrix.swift */,
115+ 24ED21CC1C6C2397009C40FC /* MetaballDataSource.swift */,
116+ 24E1E7EA1C67D70300ECF1C4 /* MetalMetaballRenderer.swift */,
153 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */,
117 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */,
118+ 242686891C63B72A00D62456 /* ViewController.swift */,
154 2426868B1C63B72A00D62456 /* Main.storyboard */,
119 2426868B1C63B72A00D62456 /* Main.storyboard */,
155 2426868E1C63B72A00D62456 /* Assets.xcassets */,
120 2426868E1C63B72A00D62456 /* Assets.xcassets */,
156 242686901C63B72A00D62456 /* LaunchScreen.storyboard */,
121 242686901C63B72A00D62456 /* LaunchScreen.storyboard */,
@@ -159,83 +124,14 @@
159 path = PixelImage;
124 path = PixelImage;
160 sourceTree = "<group>";
125 sourceTree = "<group>";
161 };
126 };
162− 24FFA84B1C6BA038005ACD60 /* SwiftSugar */ = {
127+ 8C02F866C2C0C9A954BB9375 /* Frameworks */ = {
163 isa = PBXGroup;
128 isa = PBXGroup;
164 children = (
129 children = (
165− 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */,
166− 2461651A1C6DA4F400A913C8 /* Interpolation.swift */,
167− 24FFA84D1C6BA038005ACD60 /* Collections.swift */,
168− 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */,
169− 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */,
170− 24FFA8501C6BA038005ACD60 /* Foundation */,
171− 24FFA8521C6BA038005ACD60 /* Numeric.swift */,
172− 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */,
173− 24FFA8541C6BA038005ACD60 /* Sequence.swift */,
174− 24FFA8551C6BA038005ACD60 /* Sequences */,
175− 24FFA8571C6BA038005ACD60 /* SignOperator.swift */,
176− 24FFA8581C6BA038005ACD60 /* String.swift */,
177− 24FFA8591C6BA038005ACD60 /* SwiftSequences */,
178− 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */,
179− );
180− path = SwiftSugar;
181− sourceTree = "<group>";
182− };
183− 24FFA8501C6BA038005ACD60 /* Foundation */ = {
184− isa = PBXGroup;
185− children = (
186− 24FFA8511C6BA038005ACD60 /* NSNumber.swift */,
187− );
188− path = Foundation;
189− sourceTree = "<group>";
190− };
191− 24FFA8551C6BA038005ACD60 /* Sequences */ = {
192− isa = PBXGroup;
193− children = (
194− 24FFA8561C6BA038005ACD60 /* Memoize.swift */,
195− );
196− path = Sequences;
197− sourceTree = "<group>";
198− };
199− 24FFA8591C6BA038005ACD60 /* SwiftSequences */ = {
200− isa = PBXGroup;
201− children = (
202− 24FFA85A1C6BA038005ACD60 /* Categorise.swift */,
203− 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */,
204− 24FFA85C1C6BA038005ACD60 /* Combinations.swift */,
205− 24FFA85D1C6BA038005ACD60 /* Cycle.swift */,
206− 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */,
207− 24FFA85F1C6BA038005ACD60 /* Finding.swift */,
208− 24FFA8601C6BA038005ACD60 /* FlatMap.swift */,
209− 24FFA8611C6BA038005ACD60 /* Hopping.swift */,
210− 24FFA8621C6BA038005ACD60 /* Interpose.swift */,
211− 24FFA8631C6BA038005ACD60 /* Iterate.swift */,
212− 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */,
213− 24FFA8651C6BA038005ACD60 /* Permutations.swift */,
214− 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */,
215− 24FFA8671C6BA038005ACD60 /* Slicing.swift */,
216− 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */,
217− 24FFA8691C6BA038005ACD60 /* Zip.swift */,
218− );
219− path = SwiftSequences;
220− sourceTree = "<group>";
221− };
222− 588576572D7A188031904848 /* Frameworks */ = {
223− isa = PBXGroup;
224− children = (
225− C55F9558B3B267413C3A07A6 /* Pods_PixelImage.framework */,
130+ 93D10DBF530542A19EEF699A /* Pods_PixelImage.framework */,
226 );
131 );
227 name = Frameworks;
132 name = Frameworks;
228 sourceTree = "<group>";
133 sourceTree = "<group>";
229 };
134 };
230− F1933B48ED44BA9FCD7A4A1F /* Pods */ = {
231− isa = PBXGroup;
232− children = (
233− B1A755EFC03DA2A172C2B82F /* Pods-PixelImage.debug.xcconfig */,
234− C419D37C90A6BE8B5139806A /* Pods-PixelImage.release.xcconfig */,
235− );
236− name = Pods;
237− sourceTree = "<group>";
238− };
239/* End PBXGroup section */
135/* End PBXGroup section */
240
136
241/* Begin PBXNativeTarget section */
137/* Begin PBXNativeTarget section */
@@ -243,13 +139,11 @@
243 isa = PBXNativeTarget;
139 isa = PBXNativeTarget;
244 buildConfigurationList = 242686961C63B72A00D62456 /* Build configuration list for PBXNativeTarget "PixelImage" */;
140 buildConfigurationList = 242686961C63B72A00D62456 /* Build configuration list for PBXNativeTarget "PixelImage" */;
245 buildPhases = (
141 buildPhases = (
246− EF55C7246917A184756D93D8 /* Check Pods Manifest.lock */,
142+ 041D2472535A642E23154A31 /* [CP] Check Pods Manifest.lock */,
247 242686801C63B72A00D62456 /* Sources */,
143 242686801C63B72A00D62456 /* Sources */,
248 242686811C63B72A00D62456 /* Frameworks */,
144 242686811C63B72A00D62456 /* Frameworks */,
249 242686821C63B72A00D62456 /* Resources */,
145 242686821C63B72A00D62456 /* Resources */,
250− C7A2DF67265A9D17DEFBD193 /* Embed Pods Frameworks */,
146+ 3CA888DC160972BAEB74EC52 /* [CP] Embed Pods Frameworks */,
251− FADC01F75BFAC01F0260D1C9 /* Copy Pods Resources */,
252− DD0396CE594E3EAC8D18CC6C /* Tailor */,
253 );
147 );
254 buildRules = (
148 buildRules = (
255 );
149 );
@@ -267,12 +161,13 @@
267 isa = PBXProject;
161 isa = PBXProject;
268 attributes = {
162 attributes = {
269 LastSwiftUpdateCheck = 0720;
163 LastSwiftUpdateCheck = 0720;
270− LastUpgradeCheck = 0720;
164+ LastUpgradeCheck = 1020;
271 ORGANIZATIONNAME = "Vinicius Vendramini";
165 ORGANIZATIONNAME = "Vinicius Vendramini";
272 TargetAttributes = {
166 TargetAttributes = {
273 242686831C63B72A00D62456 = {
167 242686831C63B72A00D62456 = {
274 CreatedOnToolsVersion = 7.2;
168 CreatedOnToolsVersion = 7.2;
275− DevelopmentTeam = HHT774898M;
169+ DevelopmentTeam = 8J63JZYYHZ;
170+ LastSwiftMigration = 1020;
276 };
171 };
277 };
172 };
278 };
173 };
@@ -281,6 +176,7 @@
281 developmentRegion = English;
176 developmentRegion = English;
282 hasScannedForEncodings = 0;
177 hasScannedForEncodings = 0;
283 knownRegions = (
178 knownRegions = (
179+ English,
284 en,
180 en,
285 Base,
181 Base,
286 );
182 );
@@ -308,63 +204,40 @@
308/* End PBXResourcesBuildPhase section */
204/* End PBXResourcesBuildPhase section */
309
205
310/* Begin PBXShellScriptBuildPhase section */
206/* Begin PBXShellScriptBuildPhase section */
311− C7A2DF67265A9D17DEFBD193 /* Embed Pods Frameworks */ = {
207+ 041D2472535A642E23154A31 /* [CP] Check Pods Manifest.lock */ = {
312− isa = PBXShellScriptBuildPhase;
313− buildActionMask = 2147483647;
314− files = (
315− );
316− inputPaths = (
317− );
318− name = "Embed Pods Frameworks";
319− outputPaths = (
320− );
321− runOnlyForDeploymentPostprocessing = 0;
322− shellPath = /bin/sh;
323− shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage-frameworks.sh\"\n";
324− showEnvVarsInLog = 0;
325− };
326− DD0396CE594E3EAC8D18CC6C /* Tailor */ = {
327 isa = PBXShellScriptBuildPhase;
208 isa = PBXShellScriptBuildPhase;
328 buildActionMask = 2147483647;
209 buildActionMask = 2147483647;
329 files = (
210 files = (
330 );
211 );
331 inputPaths = (
212 inputPaths = (
213+ "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
214+ "${PODS_ROOT}/Manifest.lock",
332 );
215 );
333− name = Tailor;
216+ name = "[CP] Check Pods Manifest.lock";
334 outputPaths = (
217 outputPaths = (
218+ "$(DERIVED_FILE_DIR)/Pods-PixelImage-checkManifestLockResult.txt",
335 );
219 );
336 runOnlyForDeploymentPostprocessing = 0;
220 runOnlyForDeploymentPostprocessing = 0;
337 shellPath = /bin/sh;
221 shellPath = /bin/sh;
338− shellScript = "if hash tailor 2>/dev/null; then\n tailor --except=function-whitespace,leading-whitespace,constant-k-prefix --max-severity error\nelse\n echo \"warning: Please install Tailor from https://tailor.sh\"\nfi";
339− };
340− EF55C7246917A184756D93D8 /* Check Pods Manifest.lock */ = {
341− isa = PBXShellScriptBuildPhase;
342− buildActionMask = 2147483647;
343− files = (
344− );
345− inputPaths = (
346− );
347− name = "Check Pods Manifest.lock";
348− outputPaths = (
349− );
350− runOnlyForDeploymentPostprocessing = 0;
351− shellPath = /bin/sh;
352− shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
222+ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
353 showEnvVarsInLog = 0;
223 showEnvVarsInLog = 0;
354 };
224 };
355− FADC01F75BFAC01F0260D1C9 /* Copy Pods Resources */ = {
225+ 3CA888DC160972BAEB74EC52 /* [CP] Embed Pods Frameworks */ = {
356 isa = PBXShellScriptBuildPhase;
226 isa = PBXShellScriptBuildPhase;
357 buildActionMask = 2147483647;
227 buildActionMask = 2147483647;
358 files = (
228 files = (
359 );
229 );
360 inputPaths = (
230 inputPaths = (
231+ "${SRCROOT}/Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage-frameworks.sh",
232+ "${BUILT_PRODUCTS_DIR}/ChameleonFramework/ChameleonFramework.framework",
361 );
233 );
362− name = "Copy Pods Resources";
234+ name = "[CP] Embed Pods Frameworks";
363 outputPaths = (
235 outputPaths = (
236+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ChameleonFramework.framework",
364 );
237 );
365 runOnlyForDeploymentPostprocessing = 0;
238 runOnlyForDeploymentPostprocessing = 0;
366 shellPath = /bin/sh;
239 shellPath = /bin/sh;
367− shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage-resources.sh\"\n";
240+ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PixelImage/Pods-PixelImage-frameworks.sh\"\n";
368 showEnvVarsInLog = 0;
241 showEnvVarsInLog = 0;
369 };
242 };
370/* End PBXShellScriptBuildPhase section */
243/* End PBXShellScriptBuildPhase section */
@@ -374,44 +247,20 @@
374 isa = PBXSourcesBuildPhase;
247 isa = PBXSourcesBuildPhase;
375 buildActionMask = 2147483647;
248 buildActionMask = 2147483647;
376 files = (
249 files = (
377− 24FFA87B1C6BA038005ACD60 /* Finding.swift in Sources */,
378− 24FFA8751C6BA038005ACD60 /* String.swift in Sources */,
379− 24FFA8781C6BA038005ACD60 /* Combinations.swift in Sources */,
380− 24FFA87E1C6BA038005ACD60 /* Interpose.swift in Sources */,
381 2426868A1C63B72A00D62456 /* ViewController.swift in Sources */,
250 2426868A1C63B72A00D62456 /* ViewController.swift in Sources */,
382− 24FFA8841C6BA038005ACD60 /* TakeDrop.swift in Sources */,
383− 24FFA8771C6BA038005ACD60 /* ChunkWindowSplit.swift in Sources */,
384− 24FFA86F1C6BA038005ACD60 /* NSNumber.swift in Sources */,
385 2461651B1C6DA4F400A913C8 /* Interpolation.swift in Sources */,
251 2461651B1C6DA4F400A913C8 /* Interpolation.swift in Sources */,
386− 24FFA8861C6BA038005ACD60 /* TestCommons.swift in Sources */,
252+ 24FC38341C7F931E0085C04A /* Metaball.swift in Sources */,
387− 24FFA8741C6BA038005ACD60 /* SignOperator.swift in Sources */,
388− 24FFA8821C6BA038005ACD60 /* ScanReduce.swift in Sources */,
389 24ED21CD1C6C2397009C40FC /* MetaballDataSource.swift in Sources */,
253 24ED21CD1C6C2397009C40FC /* MetaballDataSource.swift in Sources */,
390− 24FFA8831C6BA038005ACD60 /* Slicing.swift in Sources */,
254+ 24FC38361C7F9ABE0085C04A /* Dispatch.swift in Sources */,
391− 24FFA8721C6BA038005ACD60 /* Sequence.swift in Sources */,
392− 24FFA87F1C6BA038005ACD60 /* Iterate.swift in Sources */,
393− 24FFA8761C6BA038005ACD60 /* Categorise.swift in Sources */,
394− 24FFA86D1C6BA038005ACD60 /* ComparatorChains.swift in Sources */,
395 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */,
255 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */,
396 24E1E7D71C67C8B200ECF1C4 /* UIKit.swift in Sources */,
256 24E1E7D71C67C8B200ECF1C4 /* UIKit.swift in Sources */,
397− 24FFA8851C6BA038005ACD60 /* Zip.swift in Sources */,
398 249CF84C1C6D113C008B0C78 /* Matrix.swift in Sources */,
257 249CF84C1C6D113C008B0C78 /* Matrix.swift in Sources */,
399− 24FFA8791C6BA038005ACD60 /* Cycle.swift in Sources */,
400 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */,
258 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */,
401− 24FFA86E1C6BA038005ACD60 /* Dictionary.swift in Sources */,
402− 24FFA87D1C6BA038005ACD60 /* Hopping.swift in Sources */,
403 24E1E7EB1C67D70300ECF1C4 /* MetalMetaballRenderer.swift in Sources */,
259 24E1E7EB1C67D70300ECF1C4 /* MetalMetaballRenderer.swift in Sources */,
404 246B0F831C70635D00A71D05 /* UIColor.swift in Sources */,
260 246B0F831C70635D00A71D05 /* UIColor.swift in Sources */,
405− 24FFA87A1C6BA038005ACD60 /* Enumerate.swift in Sources */,
406 242686881C63B72A00D62456 /* AppDelegate.swift in Sources */,
261 242686881C63B72A00D62456 /* AppDelegate.swift in Sources */,
407 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */,
262 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */,
408− 24FFA87C1C6BA038005ACD60 /* FlatMap.swift in Sources */,
409 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */,
263 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */,
410− 24FFA8811C6BA038005ACD60 /* Permutations.swift in Sources */,
411− 24FFA86B1C6BA038005ACD60 /* ApproximationOperator.swift in Sources */,
412− 24FFA8801C6BA038005ACD60 /* NestedSequences.swift in Sources */,
413− 24FFA8731C6BA038005ACD60 /* Memoize.swift in Sources */,
414− 24FFA86C1C6BA038005ACD60 /* Collections.swift in Sources */,
415 );
264 );
416 runOnlyForDeploymentPostprocessing = 0;
265 runOnlyForDeploymentPostprocessing = 0;
417 };
266 };
@@ -441,17 +290,28 @@
441 isa = XCBuildConfiguration;
290 isa = XCBuildConfiguration;
442 buildSettings = {
291 buildSettings = {
443 ALWAYS_SEARCH_USER_PATHS = NO;
292 ALWAYS_SEARCH_USER_PATHS = NO;
293+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
444 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
294 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
445 CLANG_CXX_LIBRARY = "libc++";
295 CLANG_CXX_LIBRARY = "libc++";
446 CLANG_ENABLE_MODULES = YES;
296 CLANG_ENABLE_MODULES = YES;
447 CLANG_ENABLE_OBJC_ARC = YES;
297 CLANG_ENABLE_OBJC_ARC = YES;
298+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
448 CLANG_WARN_BOOL_CONVERSION = YES;
299 CLANG_WARN_BOOL_CONVERSION = YES;
300+ CLANG_WARN_COMMA = YES;
449 CLANG_WARN_CONSTANT_CONVERSION = YES;
301 CLANG_WARN_CONSTANT_CONVERSION = YES;
302+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
450 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
303 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
451 CLANG_WARN_EMPTY_BODY = YES;
304 CLANG_WARN_EMPTY_BODY = YES;
452 CLANG_WARN_ENUM_CONVERSION = YES;
305 CLANG_WARN_ENUM_CONVERSION = YES;
306+ CLANG_WARN_INFINITE_RECURSION = YES;
453 CLANG_WARN_INT_CONVERSION = YES;
307 CLANG_WARN_INT_CONVERSION = YES;
308+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
309+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
310+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
454 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
311 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
312+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
313+ CLANG_WARN_STRICT_PROTOTYPES = YES;
314+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
455 CLANG_WARN_UNREACHABLE_CODE = YES;
315 CLANG_WARN_UNREACHABLE_CODE = YES;
456 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
316 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
457 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
317 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -478,6 +338,7 @@
478 ONLY_ACTIVE_ARCH = YES;
338 ONLY_ACTIVE_ARCH = YES;
479 SDKROOT = iphoneos;
339 SDKROOT = iphoneos;
480 SWIFT_OPTIMIZATION_LEVEL = "-Onone";
340 SWIFT_OPTIMIZATION_LEVEL = "-Onone";
341+ SWIFT_SWIFT3_OBJC_INFERENCE = Off;
481 TARGETED_DEVICE_FAMILY = "1,2";
342 TARGETED_DEVICE_FAMILY = "1,2";
482 };
343 };
483 name = Debug;
344 name = Debug;
@@ -486,17 +347,28 @@
486 isa = XCBuildConfiguration;
347 isa = XCBuildConfiguration;
487 buildSettings = {
348 buildSettings = {
488 ALWAYS_SEARCH_USER_PATHS = NO;
349 ALWAYS_SEARCH_USER_PATHS = NO;
350+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
489 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
351 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
490 CLANG_CXX_LIBRARY = "libc++";
352 CLANG_CXX_LIBRARY = "libc++";
491 CLANG_ENABLE_MODULES = YES;
353 CLANG_ENABLE_MODULES = YES;
492 CLANG_ENABLE_OBJC_ARC = YES;
354 CLANG_ENABLE_OBJC_ARC = YES;
355+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
493 CLANG_WARN_BOOL_CONVERSION = YES;
356 CLANG_WARN_BOOL_CONVERSION = YES;
357+ CLANG_WARN_COMMA = YES;
494 CLANG_WARN_CONSTANT_CONVERSION = YES;
358 CLANG_WARN_CONSTANT_CONVERSION = YES;
359+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
495 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
360 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
496 CLANG_WARN_EMPTY_BODY = YES;
361 CLANG_WARN_EMPTY_BODY = YES;
497 CLANG_WARN_ENUM_CONVERSION = YES;
362 CLANG_WARN_ENUM_CONVERSION = YES;
363+ CLANG_WARN_INFINITE_RECURSION = YES;
498 CLANG_WARN_INT_CONVERSION = YES;
364 CLANG_WARN_INT_CONVERSION = YES;
365+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
366+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
367+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
499 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
368 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
369+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
370+ CLANG_WARN_STRICT_PROTOTYPES = YES;
371+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
500 CLANG_WARN_UNREACHABLE_CODE = YES;
372 CLANG_WARN_UNREACHABLE_CODE = YES;
501 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
373 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
502 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
374 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -515,6 +387,8 @@
515 IPHONEOS_DEPLOYMENT_TARGET = 9.2;
387 IPHONEOS_DEPLOYMENT_TARGET = 9.2;
516 MTL_ENABLE_DEBUG_INFO = NO;
388 MTL_ENABLE_DEBUG_INFO = NO;
517 SDKROOT = iphoneos;
389 SDKROOT = iphoneos;
390+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
391+ SWIFT_SWIFT3_OBJC_INFERENCE = Off;
518 TARGETED_DEVICE_FAMILY = "1,2";
392 TARGETED_DEVICE_FAMILY = "1,2";
519 VALIDATE_PRODUCT = YES;
393 VALIDATE_PRODUCT = YES;
520 };
394 };
@@ -522,25 +396,29 @@
522 };
396 };
523 242686971C63B72A00D62456 /* Debug */ = {
397 242686971C63B72A00D62456 /* Debug */ = {
524 isa = XCBuildConfiguration;
398 isa = XCBuildConfiguration;
525− baseConfigurationReference = B1A755EFC03DA2A172C2B82F /* Pods-PixelImage.debug.xcconfig */;
399+ baseConfigurationReference = 6659D12A5984961F335BDF69 /* Pods-PixelImage.debug.xcconfig */;
526 buildSettings = {
400 buildSettings = {
527 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
401 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
402+ DEVELOPMENT_TEAM = 8J63JZYYHZ;
528 INFOPLIST_FILE = PixelImage/Info.plist;
403 INFOPLIST_FILE = PixelImage/Info.plist;
529 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
404 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
530 PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
405 PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
531 PRODUCT_NAME = "$(TARGET_NAME)";
406 PRODUCT_NAME = "$(TARGET_NAME)";
407+ SWIFT_VERSION = 5.0;
532 };
408 };
533 name = Debug;
409 name = Debug;
534 };
410 };
535 242686981C63B72A00D62456 /* Release */ = {
411 242686981C63B72A00D62456 /* Release */ = {
536 isa = XCBuildConfiguration;
412 isa = XCBuildConfiguration;
537− baseConfigurationReference = C419D37C90A6BE8B5139806A /* Pods-PixelImage.release.xcconfig */;
413+ baseConfigurationReference = 0C9CE70F7D2C2896912B7B14 /* Pods-PixelImage.release.xcconfig */;
538 buildSettings = {
414 buildSettings = {
539 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
415 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
416+ DEVELOPMENT_TEAM = 8J63JZYYHZ;
540 INFOPLIST_FILE = PixelImage/Info.plist;
417 INFOPLIST_FILE = PixelImage/Info.plist;
541 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
418 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
542 PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
419 PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
543 PRODUCT_NAME = "$(TARGET_NAME)";
420 PRODUCT_NAME = "$(TARGET_NAME)";
421+ SWIFT_VERSION = 5.0;
544 };
422 };
545 name = Release;
423 name = Release;
546 };
424 };
PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcschemes/PixelImage.xcscheme+1−1
@@ -1,6 +1,6 @@
1<?xml version="1.0" encoding="UTF-8"?>
1<?xml version="1.0" encoding="UTF-8"?>
2<Scheme
2<Scheme
3− LastUpgradeVersion = "0720"
3+ LastUpgradeVersion = "0830"
4 version = "1.3">
4 version = "1.3">
5 <BuildAction
5 <BuildAction
6 parallelizeBuildables = "YES"
6 parallelizeBuildables = "YES"
PixelImage.xcworkspace/xcuserdata/vini.xcuserdatad/UserInterfaceState.xcuserstatedeleted

Binary file not shown.

PixelImage/AppDelegate.swift+6−6
@@ -13,30 +13,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
13
13
14 var window: UIWindow?
14 var window: UIWindow?
15
15
16− func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17 // Override point for customization after application launch.
17 // Override point for customization after application launch.
18 return true
18 return true
19 }
19 }
20
20
21− func applicationWillResignActive(application: UIApplication) {
21+ func applicationWillResignActive(_ application: UIApplication) {
22 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
22 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
23 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
23 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
24 }
24 }
25
25
26− func applicationDidEnterBackground(application: UIApplication) {
26+ func applicationDidEnterBackground(_ application: UIApplication) {
27 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
27 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
28 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
28 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
29 }
29 }
30
30
31− func applicationWillEnterForeground(application: UIApplication) {
31+ func applicationWillEnterForeground(_ application: UIApplication) {
32 // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
32 // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
33 }
33 }
34
34
35− func applicationDidBecomeActive(application: UIApplication) {
35+ func applicationDidBecomeActive(_ application: UIApplication) {
36 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
36 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
37 }
37 }
38
38
39− func applicationWillTerminate(application: UIApplication) {
39+ func applicationWillTerminate(_ application: UIApplication) {
40 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
40 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
41 }
41 }
42}
42}
PixelImage/Dispatch.swiftnew file+10
@@ -0,0 +1,10 @@
1+
2+import Dispatch
3+
4+func delay(_ duration: Float = 1, block: @escaping () -> ()) {
5+ DispatchQueue.main.asyncAfter(
6+ deadline: DispatchTime.now() +
7+ Double(duration * Float(NSEC_PER_SEC)) /
8+ Double(NSEC_PER_SEC),
9+ execute: block)
10+}
PixelImage/Interpolation.swift+57−5
@@ -1,15 +1,67 @@
1+
2+import Darwin
3+
1−func interpolateCubeEaseIn<T: Numeric>(linear: T) -> T {
4+func interpolateCubeEaseIn<T: Numeric>(_ linear: T) -> T {
2 return linear ^ 3
5 return linear ^ 3
3}
6}
4
7
5−func interpolateSquareEaseIn<T: Numeric>(linear: T) -> T {
8+func interpolateSquareEaseIn<T: Numeric>(_ linear: T) -> T {
6 return linear ^ 2
9 return linear ^ 2
7}
10}
8
11
9−func interpolateSquareEaseOut<T: Numeric>(linear: T) -> T {
12+func interpolateSquareEaseOut<T: Numeric>(_ linear: T) -> T {
10 return 1 - (1 - linear) * (1 - linear)
13 return 1 - (1 - linear) * (1 - linear)
11}
14}
12
15
13−func interpolateSmooth<T: Numeric>(linear: T) -> T {
16+func interpolateSmooth<T: Numeric>(_ linear: T) -> T {
14− return ((linear) * (linear) * (linear) * ((linear) * ((linear) * 6 - 15) + 10))
17+ let cube = (linear) * (linear) * (linear)
18+ return (cube * ((linear) * ((linear) * 6 - 15) + 10))
19+}
20+
21+func createStringKeyframes(_ bounces: Int = 2, elasticity: Double = 1.1, bounceSpeed: Double) -> [(time: Double, position: Double)] {
22+ // Setup keyframes
23+ var keyFrames: [(time: Double, position: Double)] = [(1, 1)]
24+
25+ let overreach = elasticity - 1
26+
27+ var currentBounceTime: Double = overreach / (bounceSpeed ^ Double(bounces))
28+ var bounceDirection = Double((bounces % 2) * 2 - 1)
29+ var bounceReach = overreach / (2 ^ Double(bounces - 1))
30+ var currentBouncePosition: Double = 1.0 + bounceDirection * bounceReach
31+
32+ keyFrames.append((1.0 - currentBounceTime, currentBouncePosition))
33+
34+ for i in (1..<bounces).reversed() {
35+ currentBounceTime += overreach / (bounceSpeed ^ Double(i + 1))
36+ currentBounceTime += overreach / (bounceSpeed ^ Double(i))
37+ bounceDirection = Double((i % 2) * 2 - 1)
38+ bounceReach = overreach / (2 ^ Double(i - 1))
39+ currentBouncePosition = 1.0 + bounceDirection * bounceReach
40+
41+ keyFrames.append((1.0 - currentBounceTime, currentBouncePosition))
42+ }
43+
44+ keyFrames.append((0, 0))
45+
46+ var reversed = [(time: Double, position: Double)]()
47+ for keyFrame in keyFrames.reversed() {
48+ reversed.append(keyFrame)
49+ }
50+
51+ return reversed
52+}
53+
54+func interpolateSpring<T: Numeric>(_ linear: T, bounces: Int = 2, elasticity: Double = 1.1, bounceSpeed: Double = 1.0) -> T {
55+ let keyFrames: [(time: Double, position: Double)]
56+ keyFrames = createStringKeyframes(bounces, elasticity: elasticity, bounceSpeed: bounceSpeed)
57+
58+ let x = linear.toDouble
59+
60+ let startFrame = keyFrames.filter { $0.time < x }.last ?? (0, 0)
61+ let endFrame = keyFrames.filter { $0.time > x }.first ?? (1, 1)
62+ let adjustedX = (x - startFrame.time) / (endFrame.time - startFrame.time)
63+ let interpolatedX = interpolateSmooth(adjustedX)
64+ let position = startFrame.position + interpolatedX * (endFrame.position - startFrame.position)
65+
66+ return T.fromDouble(position)
15}
67}
PixelImage/Matrix.swift+8−28
@@ -17,12 +17,12 @@ class Graph<T> {
17 self.adjacencyMatrix = Matrix(size: size)
17 self.adjacencyMatrix = Matrix(size: size)
18 }
18 }
19
19
20− func addEdge(i: Int, _ j: Int) {
20+ func addEdge(_ i: Int, _ j: Int) {
21 adjacencyMatrix.set(i, j)
21 adjacencyMatrix.set(i, j)
22 adjacencyMatrix.set(j, i)
22 adjacencyMatrix.set(j, i)
23 }
23 }
24
24
25− func removeEdge(i: Int, _ j: Int) {
25+ func removeEdge(_ i: Int, _ j: Int) {
26 adjacencyMatrix.reset(i, j)
26 adjacencyMatrix.reset(i, j)
27 adjacencyMatrix.reset(j, i)
27 adjacencyMatrix.reset(j, i)
28 }
28 }
@@ -35,30 +35,30 @@ struct Matrix: CustomStringConvertible {
35 let size: Int
35 let size: Int
36
36
37 init(size: Int) {
37 init(size: Int) {
38− buffer = [Float](count: size * size, repeatedValue: 0.0)
38+ buffer = [Float](repeating: 0.0, count: size * size)
39 self.size = size
39 self.size = size
40 }
40 }
41
41
42− func get(i: Int, j: Int) -> Float {
42+ func get(_ i: Int, j: Int) -> Float {
43 return buffer[index(i, j)]
43 return buffer[index(i, j)]
44 }
44 }
45
45
46− mutating func set(i: Int, _ j: Int, value: Float = 1.0) {
46+ mutating func set(_ i: Int, _ j: Int, value: Float = 1.0) {
47 buffer[index(i, j)] = value
47 buffer[index(i, j)] = value
48 }
48 }
49
49
50− mutating func reset(i: Int, _ j: Int) {
50+ mutating func reset(_ i: Int, _ j: Int) {
51 buffer[index(i, j)] = 0.0
51 buffer[index(i, j)] = 0.0
52 }
52 }
53
53
54− private func index(i: Int, _ j: Int) -> Int {
54+ fileprivate func index(_ i: Int, _ j: Int) -> Int {
55 return j * size + i
55 return j * size + i
56 }
56 }
57
57
58 var description: String {
58 var description: String {
59 get {
59 get {
60 var result = ""
60 var result = ""
61− for (index, value) in buffer.enumerate() {
61+ for (index, value) in buffer.enumerated() {
62 result = result + "\(value)"
62 result = result + "\(value)"
63 if index % size == size - 1 {
63 if index % size == size - 1 {
64 result = result + "\n"
64 result = result + "\n"
@@ -70,23 +70,3 @@ struct Matrix: CustomStringConvertible {
70 }
70 }
71 }
71 }
72}
72}
73−
74−class EdgeAnimationParameters {
75− let startDate: NSDate
76− let duration: Float
77− let fadeIn: Bool
78− let i: Int
79− let j: Int
80−
81− func unpack() -> (startDate: NSDate, duration: Float, fadeIn: Bool, i: Int, j: Int) {
82− return (startDate, duration, fadeIn, i, j)
83− }
84−
85− init(startDate: NSDate, duration: Float, fadeIn: Bool, i: Int, j: Int) {
86− self.startDate = startDate
87− self.duration = duration
88− self.fadeIn = fadeIn
89− self.i = i
90− self.j = j
91− }
92−}
PixelImage/Metaball.swiftnew file+67
@@ -0,0 +1,67 @@
1+
2+import UIKit
3+
4+class Metaball: UIView {
5+
6+ var color: UIColor
7+
8+ init(position: CGPoint,
9+ color: UIColor = UIColor(randomFlatColorOf: .light)) {
10+ self.color = color
11+ super.init(frame: CGRect.zero)
12+
13+ size = CGSize(50)
14+ middle = position
15+ }
16+
17+ required init?(coder aDecoder: NSCoder) {
18+ self.color = UIColor(randomFlatColorOf: .light)
19+ super.init(coder: aDecoder)
20+ }
21+}
22+
23+class EdgeAnimationParameters {
24+ let startDate: Date
25+ let duration: Float
26+ let fadeIn: Bool
27+ let i: Int
28+ let j: Int
29+
30+ func unpack() -> (startDate: Date, duration: Float, fadeIn: Bool,
31+ i: Int, j: Int)
32+ {
33+ return (startDate, duration, fadeIn, i, j)
34+ }
35+
36+ init(startDate: Date, duration: Float, fadeIn: Bool, i: Int, j: Int) {
37+ self.startDate = startDate
38+ self.duration = duration
39+ self.fadeIn = fadeIn
40+ self.i = i
41+ self.j = j
42+ }
43+}
44+
45+class VertexAnimationParameters {
46+ let startDate: Date
47+ let duration: Float
48+ let origin: CGPoint
49+ let destination: CGPoint
50+ let metaball: Metaball
51+
52+ func unpack() -> (startDate: Date, duration: Float, origin: CGPoint,
53+ destination: CGPoint, metaball: Metaball)
54+ {
55+ return (startDate, duration, origin, destination, metaball)
56+ }
57+
58+ init(startDate: Date, duration: Float, origin: CGPoint,
59+ destination: CGPoint, metaball: Metaball)
60+ {
61+ self.startDate = startDate
62+ self.duration = duration
63+ self.origin = origin
64+ self.destination = destination
65+ self.metaball = metaball
66+ }
67+}
PixelImage/Metal.swift+4−4
@@ -8,14 +8,14 @@ class MTLContext {
8
8
9 init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
9 init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
10 self.device = device
10 self.device = device
11− self.library = device.newDefaultLibrary()!
11+ self.library = device.makeDefaultLibrary()!
12− self.commandQueue = device.newCommandQueue()
12+ self.commandQueue = device.makeCommandQueue()!
13 }
13 }
14}
14}
15
15
16class MTLComputeContext {
16class MTLComputeContext {
17 var texture: MTLTexture
17 var texture: MTLTexture
18− var imageBuffer: UnsafeMutablePointer<Void>
18+ var imageBuffer: UnsafeMutableRawPointer
19
19
20 init(size: CGSize, texture: MTLTexture) {
20 init(size: CGSize, texture: MTLTexture) {
21 let width = Int(size.width)
21 let width = Int(size.width)
@@ -26,7 +26,7 @@ class MTLComputeContext {
26 self.texture = texture
26 self.texture = texture
27 }
27 }
28
28
29− func updateToSize(size: CGSize, texture: MTLTexture) {
29+ func updateToSize(_ size: CGSize, texture: MTLTexture) {
30 free(imageBuffer)
30 free(imageBuffer)
31
31
32 let width = Int(size.width)
32 let width = Int(size.width)
PixelImage/MetalMetaballRenderer.swift+100−69
@@ -2,7 +2,7 @@ import Metal
2import UIKit
2import UIKit
3import ChameleonFramework
3import ChameleonFramework
4
4
5−class MetalMetaballRenderer {
5+@objc class MetalMetaballRenderer: NSObject {
6
6
7 typealias TargetView = UIImageView
7 typealias TargetView = UIImageView
8
8
@@ -14,18 +14,18 @@ class MetalMetaballRenderer {
14
14
15 let dataSource: MetaballDataSource
15 let dataSource: MetaballDataSource
16
16
17− let semaphore = dispatch_semaphore_create(2)
17+ let semaphore = DispatchSemaphore(value: 2)
18
18
19 enum RendererState {
19 enum RendererState {
20− case Idle
20+ case idle
21− case Running
21+ case running
22− case Ending
22+ case ending
23 }
23 }
24
24
25− var state: RendererState = .Idle {
25+ var state: RendererState = .idle {
26 willSet {
26 willSet {
27− if state == .Idle {
27+ if state == .idle {
28− if newValue == .Running {
28+ if newValue == .running {
29 updateTargetView()
29 updateTargetView()
30 }
30 }
31 }
31 }
@@ -39,32 +39,39 @@ class MetalMetaballRenderer {
39
39
40 let width = Int(frame.width)
40 let width = Int(frame.width)
41 let height = Int(frame.height)
41 let height = Int(frame.height)
42− let textureDescriptor = MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(.BGRA8Unorm, width: width, height: height, mipmapped: false)
42+ let textureDescriptor =
43−
43+ MTLTextureDescriptor.texture2DDescriptor(
44+ pixelFormat: .bgra8Unorm,
45+ width: width,
46+ height: height,
47+ mipmapped: false)
48+ textureDescriptor.usage = .shaderWrite
49+
50+ let texture1 =
44− let texture1 = context.device.newTextureWithDescriptor(textureDescriptor)
51+ context.device.makeTexture(descriptor: textureDescriptor)
45− activeComputeContext = MTLComputeContext(size: targetView.size, texture: texture1)
52+ activeComputeContext = MTLComputeContext(size: targetView.size,
53+ texture: texture1!)
54+ let texture2 =
46− let texture2 = context.device.newTextureWithDescriptor(textureDescriptor)
55+ context.device.makeTexture(descriptor: textureDescriptor)
47− idleComputeContext = MTLComputeContext(size: targetView.size, texture: texture2)
56+ idleComputeContext = MTLComputeContext(size: targetView.size,
57+ texture: texture2!)
48 }
58 }
49
59
50− func updateTargetView() {
60+ internal func updateTargetView() {
51−
61+ let timeout = DispatchTime.now() + Double(1000000000) / Double(NSEC_PER_SEC)
52− let timeout = dispatch_time(DISPATCH_TIME_NOW, 1000000000)
53− dispatch_semaphore_wait(semaphore, timeout)
62+ _ = semaphore.wait(timeout: timeout)
54−
55− state = .Ending
56
63
57− let userInteractiveQueue = dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)
64+ state = .ending
58− dispatch_async(userInteractiveQueue) { () -> Void in
59
65
66+ DispatchQueue.main.async { () -> Void in
60 let computeContext = self.activeComputeContext
67 let computeContext = self.activeComputeContext
61 swap(&self.activeComputeContext, &self.idleComputeContext)
68 swap(&self.activeComputeContext, &self.idleComputeContext)
62
69
63 // Render graphics to metal texture
70 // Render graphics to metal texture
64 self.renderToContext(computeContext)
71 self.renderToContext(computeContext)
65
72
66− if self.state != .Running {
73+ if self.state != .running {
67− self.state = .Idle
74+ self.state = .idle
68 } else {
75 } else {
69 self.updateTargetView()
76 self.updateTargetView()
70 }
77 }
@@ -72,16 +79,16 @@ class MetalMetaballRenderer {
72 // Transform metal texture into image
79 // Transform metal texture into image
73 let uiimage = self.createImageFromContext(computeContext)
80 let uiimage = self.createImageFromContext(computeContext)
74
81
75− dispatch_semaphore_signal(self.semaphore)
82+ self.semaphore.signal()
76
83
77− dispatch_async(dispatch_get_main_queue()) { () -> Void in
84+ DispatchQueue.main.async { () -> Void in
78 // Send image to view
85 // Send image to view
79 self.targetView.image = uiimage
86 self.targetView.image = uiimage
80 }
87 }
81 }
88 }
82 }
89 }
83
90
84− func renderToContext(computeContext: MTLComputeContext) {
91+ internal func renderToContext(_ computeContext: MTLComputeContext) {
85 let width = Int(targetView.width)
92 let width = Int(targetView.width)
86 let height = Int(targetView.height)
93 let height = Int(targetView.height)
87
94
@@ -89,97 +96,119 @@ class MetalMetaballRenderer {
89 let pipeline: MTLComputePipelineState
96 let pipeline: MTLComputePipelineState
90 do {
97 do {
91 // Get long-lived objects
98 // Get long-lived objects
99+ kernelFunction =
92− kernelFunction = context.library.newFunctionWithName("drawMetaballs")
100+ context.library.makeFunction(name: "drawMetaballs")
93− pipeline = try context.device.newComputePipelineStateWithFunction(kernelFunction!)
101+ pipeline = try context.device.makeComputePipelineState(
102+ function: kernelFunction!)
94
103
95 // Configure info for computing
104 // Configure info for computing
96 let threadGroupCounts = MTLSizeMake(8, 8, 1)
105 let threadGroupCounts = MTLSizeMake(8, 8, 1)
97− let threadGroups = MTLSizeMake(width / threadGroupCounts.width, height / threadGroupCounts.height, 1)
106+ let threadGroups = MTLSizeMake(width / threadGroupCounts.width,
107+ height / threadGroupCounts.height,
108+ 1)
98
109
99 // Send commands to metal and render
110 // Send commands to metal and render
100− let commandBuffer = context.commandQueue.commandBuffer()
111+ let commandBuffer = context.commandQueue.makeCommandBuffer()
101
112
102− let commandEncoder = commandBuffer.computeCommandEncoder()
113+ let commandEncoder = commandBuffer!.makeComputeCommandEncoder()
103− commandEncoder.setComputePipelineState(pipeline)
114+ commandEncoder!.setComputePipelineState(pipeline)
104− commandEncoder.setTexture(computeContext.texture, atIndex: 0)
115+ commandEncoder!.setTexture(computeContext.texture, index: 0)
105 let metaballInfoBuffer = metaballBuffer()
116 let metaballInfoBuffer = metaballBuffer()
106− commandEncoder.setBuffer(metaballInfoBuffer, offset: 0, atIndex: 0)
117+ commandEncoder!.setBuffer(metaballInfoBuffer, offset: 0, index: 0)
107 let edgesBuffer = metaballEdgesBuffer()
118 let edgesBuffer = metaballEdgesBuffer()
108− commandEncoder.setBuffer(edgesBuffer, offset: 0, atIndex: 1)
119+ commandEncoder!.setBuffer(edgesBuffer, offset: 0, index: 1)
109− commandEncoder.dispatchThreadgroups(threadGroups,
120+ commandEncoder!.dispatchThreadgroups(threadGroups,
110 threadsPerThreadgroup: threadGroupCounts)
121 threadsPerThreadgroup: threadGroupCounts)
111− commandEncoder.endEncoding()
122+ commandEncoder!.endEncoding()
112
123
113− commandBuffer.commit()
124+ commandBuffer!.commit()
114− commandBuffer.waitUntilCompleted()
125+ commandBuffer!.waitUntilCompleted()
115 } catch _ {
126 } catch _ {
116− print("Error!")
127+ assertionFailure()
117 }
128 }
118 }
129 }
119
130
120− func createImageFromContext(computeContext: MTLComputeContext) -> UIImage {
131+ internal func createImageFromContext(_ computeContext: MTLComputeContext)
132+ -> UIImage
133+ {
121 let texture = computeContext.texture
134 let texture = computeContext.texture
122
135
123 // Get image info
136 // Get image info
124− let imageSize = CGSizeMake(CGFloat(texture.width), CGFloat(texture.height))
137+ let imageSize = CGSize(width: CGFloat(texture.width),
138+ height: CGFloat(texture.height))
125 let width = Int(imageSize.width)
139 let width = Int(imageSize.width)
126 let height = Int(imageSize.height)
140 let height = Int(imageSize.height)
127 let imageByteCount = width * height * 4
141 let imageByteCount = width * height * 4
128 let bytesPerRow = width * 4
142 let bytesPerRow = width * 4
129 let region = MTLRegionMake2D(0, 0, width, height)
143 let region = MTLRegionMake2D(0, 0, width, height)
130
144
131− // Allocate the buffer if needed
132− if computeContext.imageBuffer == nil {
133− computeContext.imageBuffer = malloc(imageByteCount)
134− }
135−
136 // Transfer texture info into image buffer
145 // Transfer texture info into image buffer
137− texture.getBytes(computeContext.imageBuffer, bytesPerRow: bytesPerRow, fromRegion: region, mipmapLevel: 0)
146+ texture.getBytes(computeContext.imageBuffer,
147+ bytesPerRow: bytesPerRow,
148+ from: region,
149+ mipmapLevel: 0)
138
150
139 // Get info for UIImage
151 // Get info for UIImage
152+ let provider = CGDataProvider(dataInfo: nil,
140− let provider = CGDataProviderCreateWithData(nil, computeContext.imageBuffer, imageByteCount, nil)
153+ data: computeContext.imageBuffer,
154+ size: imageByteCount) {
155+ (_, _, _) in }
141− let bitsPerComponent = 8
156+ let bitsPerComponent = 8
142 let bitsperPixel = 32
157 let bitsperPixel = 32
143 let colorSpaceRef = CGColorSpaceCreateDeviceRGB()
158 let colorSpaceRef = CGColorSpaceCreateDeviceRGB()
144− let bitmapInfoRaw = CGImageAlphaInfo.PremultipliedLast.rawValue | CGBitmapInfo.ByteOrder32Big.rawValue
159+ let bitmapInfoRaw = CGImageAlphaInfo.premultipliedLast.rawValue |
160+ CGBitmapInfo.byteOrder32Big.rawValue
145 let bitmapInfo = CGBitmapInfo(rawValue: bitmapInfoRaw)
161 let bitmapInfo = CGBitmapInfo(rawValue: bitmapInfoRaw)
146− let renderingIntent = CGColorRenderingIntent.RenderingIntentDefault
162+ let renderingIntent = CGColorRenderingIntent.defaultIntent
147
163
148 // Create UIImage from image buffer
164 // Create UIImage from image buffer
149− let imageRef = CGImageCreate(width, height, bitsPerComponent, bitsperPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, nil, false, renderingIntent)
165+ let imageRef = CGImage(width: width, height: height,
166+ bitsPerComponent: bitsPerComponent,
167+ bitsPerPixel: bitsperPixel,
168+ bytesPerRow: bytesPerRow,
169+ space: colorSpaceRef,
170+ bitmapInfo: bitmapInfo,
171+ provider: provider!,
172+ decode: nil, shouldInterpolate: false,
173+ intent: renderingIntent)
150− let image = UIImage(CGImage: imageRef!, scale: 0.0, orientation: .Up)
174+ let image = UIImage(cgImage: imageRef!, scale: 0.0, orientation: .up)
151
175
152 return image
176 return image
153 }
177 }
154
178
155− func metaballEdgesBuffer() -> MTLBuffer {
179+ internal func metaballEdgesBuffer() -> MTLBuffer {
156 let floats = dataSource.metaballGraph.adjacencyMatrix.buffer
180 let floats = dataSource.metaballGraph.adjacencyMatrix.buffer
157
181
158− let bufferLength = floats.count * sizeof(Float)
182+ let bufferLength = floats.count * MemoryLayout<Float>.size
159 let device = context.device
183 let device = context.device
160− let buffer = device.newBufferWithBytes(floats, length: bufferLength, options: .StorageModeShared)
184+ let buffer = device.makeBuffer(bytes: floats,
185+ length: bufferLength,
186+ options: MTLResourceOptions())
161
187
162− return buffer
188+ return buffer!
163 }
189 }
164
190
165− func metaballBuffer() -> MTLBuffer {
191+ internal func metaballBuffer() -> MTLBuffer {
166 // Create Float array for buffer
192 // Create Float array for buffer
167 // Exclude metaballs far from the view's bounds
193 // Exclude metaballs far from the view's bounds
168 let border: CGFloat = 100
194 let border: CGFloat = 100
169− let metaballs = self.dataSource.metaballs
195+ let metaballs = self.dataSource.metaballs!
170
196
171− var floats = [Float](count: 5, repeatedValue: 0)
197+ var floats = [Float](repeating: 0, count: 5)
172 floats = metaballs.reduce(floats) {
198 floats = metaballs.reduce(floats) {
173− (var array, metaball) -> [Float] in
199+ (array, metaball) -> [Float] in
200+ var array = array
174
201
175 let x = CGFloat(metaball.midX)
202 let x = CGFloat(metaball.midX)
176 let y = CGFloat(metaball.midY)
203 let y = CGFloat(metaball.midY)
204+ if -border < x,
177− if -border < x ≤ targetView.width + border &&
205+ x < targetView.width + border,
206+ -border < y,
178− -border < y ≤ targetView.height + border {
207+ y < targetView.height + border {
179 array.append(Float(x))
208 array.append(Float(x))
180 array.append(Float(y))
209 array.append(Float(y))
181
210
182− let color = metaball.backgroundColor!
211+ let color = metaball.color
183 let components = color.components
212 let components = color.components
184 array.append(Float(components.red))
213 array.append(Float(components.red))
185 array.append(Float(components.green))
214 array.append(Float(components.green))
@@ -192,10 +221,12 @@ class MetalMetaballRenderer {
192 floats[0] = Float(floats.count) / 5
221 floats[0] = Float(floats.count) / 5
193
222
194 // Create buffer
223 // Create buffer
195− let bufferLength = floats.count * sizeof(Float)
224+ let bufferLength = floats.count * MemoryLayout<Float>.size
196 let device = context.device
225 let device = context.device
197− let buffer = device.newBufferWithBytes(floats, length: bufferLength, options: .StorageModeShared)
226+ let buffer = device.makeBuffer(bytes: floats,
227+ length: bufferLength,
228+ options: MTLResourceOptions())
198
229
199− return buffer
230+ return buffer!
200 }
231 }
201}
232}
PixelImage/SwiftSugar/ApproximationOperator.swiftdeleted−12
@@ -1,12 +0,0 @@
1−import Darwin
2−
3−infix operator ==~ { associativity right precedence 130 }
4−
5−func ==~ (left: DoubleValuable, right: DoubleValuable) -> Bool {
6− let leftDouble = left.toDouble
7− let rightDouble = right.toDouble
8− let epsilon = abs(leftDouble/10000)
9−
10− return (leftDouble <= rightDouble + epsilon) &&
11− (leftDouble >= rightDouble - epsilon)
12−}
PixelImage/SwiftSugar/Collections.swiftdeleted−6
@@ -1,6 +0,0 @@
1−func iterate<C, R>(collection: C, block: (String?, Any) -> R) {
2− let mirror = Mirror(reflecting: collection)
3− for child in mirror.children {
4− block(child.0, child.1)
5− }
6−}
PixelImage/SwiftSugar/ComparatorChains.swiftdeleted−57
@@ -1,57 +0,0 @@
1−let doubleMax: Double = 1E+37
2−let doubleMin: Double = -1E+37
3−let floatMax: Float = 1E+37
4−let floatMin: Float = -1E+37
5−let int32Max: Int = 0x7fffffff
6−let int32Min: Int = -0x7fffffff - 1
7−
8−infix operator ≤ { associativity right precedence 131 }
9−
10−func ≤ <T: Numeric>
11− (left: T, right: T) -> T {
12−
13− if left < right {
14− return left
15− } else {
16− return -0x7fffffff
17− }
18−}
19−
20−//
21−infix operator ≤= { associativity right precedence 131 }
22−
23−func ≤= <T: Numeric>
24− (left: T, right: T) -> T {
25−
26− if left <= right {
27− return left
28− } else {
29− return -0x7fffffff
30− }
31−}
32−
33−//
34−infix operator ≥ { associativity right precedence 131 }
35−
36−func ≥ <T: Numeric>
37− (left: T, right: T) -> T {
38−
39− if left > right {
40− return left
41− } else {
42− return 0x7fffffff
43− }
44−}
45−
46−//
47−infix operator ≥= { associativity right precedence 131 }
48−
49−func ≥= <T: Numeric>
50− (left: T, right: T) -> T {
51−
52− if left >= right {
53− return left
54− } else {
55− return 0x7fffffff
56− }
57−}
PixelImage/SwiftSugar/Dictionary.swiftdeleted−12
@@ -1,12 +0,0 @@
1−extension Dictionary {
2− subscript(keys: [Key]) -> [Value] {
3− get {
4− return keys.unwrappedMap { self[$0] }
5− }
6− set (values) {
7− for (key, value) in zip(keys, values) {
8− self[key] = value
9− }
10− }
11− }
12−}
PixelImage/SwiftSugar/Foundation/NSNumber.swiftdeleted−14
@@ -1,14 +0,0 @@
1−import Foundation
2−
3−extension NSNumber: DoubleValuable {
4− var toDouble: Double {
5− get {
6− return self.doubleValue
7− }
8− }
9−
10− static func fromDouble(double: Double) -> Self {
11− return self.init(double: double)
12− }
13−
14−}
PixelImage/SwiftSugar/Numeric.swift+10−28
@@ -1,23 +1,16 @@
1protocol DoubleValuable {
1protocol DoubleValuable {
2 var toDouble: Double { get }
2 var toDouble: Double { get }
3
3
4− static func fromDouble(double: Double) -> Self
4+ static func fromDouble(_ double: Double) -> Self
5}
5}
6
6
7−postfix operator ++ { }
7+protocol Numeric: DoubleValuable, Comparable,
8+ ExpressibleByIntegerLiteral {
8
9
9−protocol Incrementable {
10− postfix func ++ (inout _: Self) -> Self
11−}
12−
13−protocol Numeric: DoubleValuable, Incrementable, Comparable,
14− IntegerLiteralConvertible {
15−
16− @warn_unused_result func / (lhs: Self, rhs: Self) -> Self
10+ static func / (lhs: Self, rhs: Self) -> Self
17− @warn_unused_result func - (lhs: Self, rhs: Self) -> Self
11+ static func - (lhs: Self, rhs: Self) -> Self
18− @warn_unused_result func + (lhs: Self, rhs: Self) -> Self
12+ static func + (lhs: Self, rhs: Self) -> Self
19− @warn_unused_result func * (lhs: Self, rhs: Self) -> Self
13+ static func * (lhs: Self, rhs: Self) -> Self
20− postfix func ++ (inout _: Self) -> Self
21}
14}
22
15
23protocol FastNumeric: Numeric {}
16protocol FastNumeric: Numeric {}
@@ -29,7 +22,7 @@ extension Double: FastNumeric {
29 }
22 }
30 }
23 }
31
24
32− static func fromDouble(double: Double) -> Double {
25+ static func fromDouble(_ double: Double) -> Double {
33 return double
26 return double
34 }
27 }
35
28
@@ -42,7 +35,7 @@ extension Float: FastNumeric {
42 }
35 }
43 }
36 }
44
37
45− static func fromDouble(double: Double) -> Float {
38+ static func fromDouble(_ double: Double) -> Float {
46 return Float(double)
39 return Float(double)
47 }
40 }
48
41
@@ -55,19 +48,8 @@ extension Int: FastNumeric {
55 }
48 }
56 }
49 }
57
50
58− static func fromDouble(double: Double) -> Int {
51+ static func fromDouble(_ double: Double) -> Int {
59 return Int(double)
52 return Int(double)
60 }
53 }
61
54
62}
55}
63−
64−//
65−extension Int {
66−
67− func times(@noescape block: () throws -> ()) rethrows {
68− for _ in 1...self {
69− try block()
70− }
71− }
72−
73−}
PixelImage/SwiftSugar/PowerOperator.swift+7−1
@@ -1,6 +1,12 @@
1import Darwin
1import Darwin
2
2
3+precedencegroup PowerPrecedence {
4+ higherThan: MultiplicationPrecedence
3−infix operator ^ { associativity right precedence 131 }
5+ associativity: right
6+}
7+
8+//
9+infix operator ^: PowerPrecedence
4
10
5func ^ <T: DoubleValuable>(left: T, right: T) -> T {
11func ^ <T: DoubleValuable>(left: T, right: T) -> T {
6 return T.fromDouble(pow(left.toDouble, right.toDouble))
12 return T.fromDouble(pow(left.toDouble, right.toDouble))
PixelImage/SwiftSugar/Sequence.swiftdeleted−16
@@ -1,16 +0,0 @@
1−extension SequenceType {
2− func unwrappedMap<T>
3− (@noescape transform: (Self.Generator.Element) throws -> T?) rethrows
4− -> [T] {
5− return try self.reduce( [T]() ) {
6− (var accumulator: [T], element: Self.Generator.Element) -> [T] in
7−
8− let transformed = try transform(element)
9− if let unwrapped = transformed {
10− accumulator.append(unwrapped)
11− }
12−
13− return accumulator
14− }
15− }
16−}
PixelImage/SwiftSugar/Sequences/Memoize.swiftdeleted−167
@@ -1,167 +0,0 @@
1−protocol MemoizedSequence: LazySequenceType {
2− typealias IndexType: Hashable
3− typealias ReturnType
4−
5− init(first: IndexType,
6− incrementer: ((inout IndexType) -> Void),
7− memoizedFunction: (IndexType -> ReturnType))
8−}
9−
10−struct HashMemoizedSequence<IndexType: Hashable, ReturnType>:
11− MemoizedSequence {
12−
13− let memoizedFunction: (IndexType -> ReturnType)
14− let increment: ((inout IndexType) -> Void)
15− let firstIndex: IndexType
16−
17− var index: IndexType
18−
19− init(first: IndexType,
20− incrementer: ((inout IndexType) -> Void),
21− memoizedFunction: (IndexType -> ReturnType)) {
22−
23− self.firstIndex = first
24−
25− self.index = first
26− self.increment = incrementer
27− self.memoizedFunction = memoizedFunction
28− }
29−
30− init(first: IndexType,
31− incrementer: ((inout IndexType) -> Void),
32− closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
33− let memoizedFunction = memoize(closure)
34−
35− self.init(first: first, incrementer: incrementer,
36− memoizedFunction: memoizedFunction)
37− }
38−
39− init(first: IndexType,
40− incrementer: ((inout IndexType) -> Void),
41− function: (IndexType -> ReturnType)) {
42−
43− let memoizedFunction = memoize(function)
44−
45− self.init(first: first, incrementer: incrementer,
46− memoizedFunction: memoizedFunction)
47− }
48−}
49−
50−extension HashMemoizedSequence: GeneratorType {
51−
52− mutating func next() -> ReturnType? {
53− let result = memoizedFunction(index)
54− increment(&index)
55− return result
56− }
57−
58−}
59−
60−extension HashMemoizedSequence: LazySequenceType {
61−
62− func generate() -> HashMemoizedSequence {
63− return self
64− }
65−
66−}
67−
68−extension HashMemoizedSequence where ReturnType: Comparable {
69−
70− @warn_unused_result
71− func contains(element: ReturnType) -> Bool {
72− var index = firstIndex
73−
74− while true {
75− let value = memoizedFunction(index)
76−
77− if value == element {
78− return true
79− } else if value > element {
80− return false
81− }
82−
83− increment(&index)
84− }
85− }
86−
87−}
88−
89−extension HashMemoizedSequence where IndexType: Incrementable {
90− init(first: IndexType,
91− closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
92− self.firstIndex = first
93− self.index = first
94− self.increment = { (inout index: IndexType) in
95− index++
96− }
97− self.memoizedFunction = memoize(closure)
98− }
99−
100− init(first: IndexType,
101− function: (IndexType -> ReturnType)) {
102− self.firstIndex = first
103− self.index = first
104− self.increment = { (inout index: IndexType) in
105− index++
106− }
107− self.memoizedFunction = memoize(function)
108− }
109−}
110−
111−extension HashMemoizedSequence where IndexType: Incrementable,
112−IndexType: IntegerLiteralConvertible {
113− init(_ closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
114− self.firstIndex = 1
115− self.index = 1
116− self.increment = { (inout index: IndexType) in
117− index++
118− }
119− self.memoizedFunction = memoize(closure)
120− }
121−
122− init(_ function: (IndexType -> ReturnType)) {
123− self.firstIndex = 1
124− self.index = 1
125− self.increment = { (inout index: IndexType) in
126− index++
127− }
128− self.memoizedFunction = memoize(function)
129− }
130−}
131−
132−func memoize<H: Hashable, R>(closure: ((H -> R, H) -> R)) -> (H -> R) {
133−
134− var table = [H: R]()
135−
136− var auxiliaryFunction: (H -> R)!
137− auxiliaryFunction = { index in
138− if let result = table[index] {
139− return result
140− }
141−
142− let result = closure(auxiliaryFunction, index)
143− table[index] = result
144−
145− return result
146− }
147−
148− return auxiliaryFunction
149−}
150−
151−func memoize<H: Hashable, R>(function: (H -> R)) -> (H -> R) {
152−
153− var table = [H: R]()
154−
155− let result: (H -> R) = { index in
156− if let result = table[index] {
157− return result
158− }
159−
160− let result = function(index)
161− table[index] = result
162−
163− return result
164− }
165−
166− return result
167−}
PixelImage/SwiftSugar/SignOperator.swiftdeleted−12
@@ -1,12 +0,0 @@
1−prefix operator ± { }
2−
3−prefix func ± <T: Numeric>(number: T) -> T {
4−
5− if number > 0 {
6− return 1
7− } else if number == 0 {
8− return 0
9− } else {
10− return -1
11− }
12−}
PixelImage/SwiftSugar/String.swiftdeleted−12
@@ -1,12 +0,0 @@
1−extension String: DoubleValuable {
2− var toDouble: Double {
3− get {
4− return Double(self) ?? Double(0)
5− }
6− }
7−
8− static func fromDouble(double: Double) -> String {
9− return "\(double)"
10− }
11−
12−}
PixelImage/SwiftSugar/SwiftSequences/Categorise.swiftdeleted−211
@@ -1,211 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: Categorise
4−
5−public extension SequenceType {
6−
7− /**
8− Categorises elements of `self` into a dictionary, with the keys
9− given by `keyFunc`
10− ```swift
11− struct Person : CustomStringConvertible {
12− let name: String
13− let age : Int
14− init(_ name: String, _ age: Int) {
15− self.name = name
16− self.age = age
17− }
18− var description: String { return name }
19− }
20−
21− let people = [
22− Person("Jo", 20),
23− Person("An", 20),
24− Person("Cthulu", 4000)
25− ]
26−
27− people.categorise { p in p.age }
28−
29− //[20: [Jo, An], 4000: [Cthulu]]
30− ```
31− */
32− @warn_unused_result
33− func categorise<U : Hashable>(@noescape keyFunc: Generator.Element throws -> U)
34− rethrows -> [U:[Generator.Element]] {
35− var dict: [U:[Generator.Element]] = [:]
36− for el in self {
37− let key = try keyFunc(el)
38− if case nil = dict[key]?.append(el) { dict[key] = [el] }
39− }
40− return dict
41− }
42−}
43−
44−public extension SequenceType where Generator.Element : Hashable {
45−
46− // MARK: Frequencies
47−
48− /**
49− Returns a dictionary where the keys are the elements of self, and
50− the values are their respective frequencies
51− ```swift
52− [0, 3, 0, 1, 1, 3, 2, 3, 1, 0].freqs()
53− // [2: 1, 0: 3, 3: 3, 1: 3]
54− ```
55− */
56− @warn_unused_result
57− func freqs() -> [Generator.Element:Int] {
58− var freqs: [Generator.Element:Int] = [:]
59− for el in self { freqs[el] = freqs[el]?.successor() ?? 1 }
60− return freqs
61− }
62−
63− // MARK: Uniques
64−
65− /**
66− Returns an array of the elements of `self`, in order, with
67− duplicates removed
68− ```swift
69− [3, 1, 2, 3, 2, 1, 1, 2, 3, 3].uniques()
70− // [3, 1, 2]
71− ```
72− */
73− @warn_unused_result
74− public func uniques() -> [Generator.Element] {
75− var prevs: Set<Generator.Element> = []
76− var uniqs: [Generator.Element] = []
77− for el in self where !prevs.contains(el) {
78− prevs.insert(el)
79− uniqs.append(el)
80− }
81− return uniqs
82− }
83−
84− /// Returns the element which occurs most frequently in `self`
85− @warn_unused_result
86− public func mostFrequent() -> Generator.Element? {
87− var g = generate()
88− guard let b = g.next() else { return nil }
89− var be = b
90− var bn = 1
91− var freqs: [Generator.Element:Int] = [:]
92− for e in self {
93− let n = (freqs[e] ?? 0) + 1
94− if n > bn { (be,bn) = (e,n) }
95− freqs[e] = n
96− }
97− return be
98− }
99−}
100−
101−// MARK: - Lazy
102−
103−// MARK: Uniques
104−/// :nodoc:
105−public struct UniquesGen<G : GeneratorType where G.Element : Hashable> : GeneratorType {
106−
107− private var prevs: Set<G.Element>
108− private var g: G
109− /// :nodoc:
110− public mutating func next() -> G.Element? {
111− while let next = g.next() {
112− if !prevs.contains(next) {
113− prevs.insert(next)
114− return next
115− }
116− }
117− return nil
118− }
119−}
120−/// :nodoc:
121−public struct UniquesSeq<
122− S : SequenceType where
123− S.Generator.Element : Hashable
124− > : LazySequenceType {
125− private let seq: S
126− /// :nodoc:
127− public func generate() -> UniquesGen<S.Generator> {
128− return UniquesGen(prevs: [], g: seq.generate())
129− }
130−}
131−
132−public extension LazySequenceType where Generator.Element : Hashable {
133−
134− /// returns a `LazySequence` of the elements of `self`, in order, with
135− /// duplicates removed
136− @warn_unused_result
137− func uniques() -> UniquesSeq<Self> {
138− return UniquesSeq(seq: self)
139− }
140−}
141−
142−// MARK: Grouping
143−
144−/// :nodoc:
145−
146−public struct GroupByGen<G : GeneratorType> : GeneratorType {
147−
148− private var genr: G
149− private var last: G.Element?
150− private let isEq: (G.Element, G.Element) -> Bool
151− /// :nodoc:
152− mutating public func next() -> [G.Element]? {
153− guard let head = last else { return nil }
154− var group = [head]
155− last = nil
156− while let next = genr.next() {
157− guard isEq(group.last!, next) else {
158− last = next
159− return group
160− }
161− group.append(next)
162− }
163− return group
164− }
165− private init(g : G, isEquivalent: (G.Element, G.Element) -> Bool) {
166− genr = g
167− last = genr.next()
168− isEq = isEquivalent
169− }
170−}
171−
172−/// :nodoc:
173−
174−public struct GroupBySeq<S : SequenceType> : LazySequenceType {
175− private let seq: S
176− private let isEquivalent: (S.Generator.Element, S.Generator.Element) -> Bool
177− /// :nodoc:
178− public func generate() -> GroupByGen<S.Generator> {
179− return GroupByGen(g: seq.generate(), isEquivalent: isEquivalent)
180− }
181−}
182−
183−public extension LazySequenceType where Generator.Element : Equatable {
184−
185− /// Returns a lazy sequence of self, chunked into arrays of adjacent equal values
186− /// ```swift
187− /// [1, 2, 2, 3, 1, 1, 3, 4, 2].lazy.group()
188− ///
189− /// [1], [2, 2], [3], [1, 1], [3], [4], [2]
190− /// ```
191− @warn_unused_result
192− func group() -> GroupBySeq<Self> {
193− return GroupBySeq(seq: self, isEquivalent: ==)
194− }
195−}
196−
197−public extension LazySequenceType {
198−
199− /// Returns a lazy sequence of self, chunked into arrays of adjacent equal values
200− /// - Parameter isEquivalent: a function that returns true if its two parameters are equal
201− /// ```swift
202− /// [1, 3, 5, 20, 22, 18, 6, 7].lazy.groupBy { (a,b) in abs(a - b) < 5 }
203− ///
204− /// [1, 3, 5], [20, 22, 18], [6, 7]
205− /// ```
206− @warn_unused_result
207− func group(isEquivalent: (Generator.Element, Generator.Element) -> Bool)
208− -> GroupBySeq<Self> {
209− return GroupBySeq(seq: self, isEquivalent: isEquivalent)
210− }
211−}
PixelImage/SwiftSugar/SwiftSequences/ChunkWindowSplit.swiftdeleted−146
@@ -1,146 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: Chunk
4−
5−public extension CollectionType {
6−
7− /// Returns an array of arrays of n non-overlapping elements of self
8− /// - Parameter n: The size of the chunk
9− /// - Precondition: `n > 0`
10− /// - SeeAlso: `func window(n: Int) -> [[Self.Generator.Element]]`
11− /// ```swift
12− /// [1, 2, 3, 4, 5].chunk(2)
13− ///
14− /// [[1, 2], [3, 4], [5]]
15− /// ```
16− @warn_unused_result
17− public func chunk(n: Index.Distance) -> [SubSequence] {
18− var res: [SubSequence] = []
19− var i = startIndex
20− var j: Index
21− while i != endIndex {
22− j = i.advancedBy(n, limit: endIndex)
23− res.append(self[i..<j])
24− i = j
25− }
26− return res
27− }
28−}
29−
30−// MARK: Window
31−
32−public extension CollectionType {
33−
34− /// Returns an array of arrays of n overlapping elements of self
35− /// - Parameter n: The size of the window
36− /// - SeeAlso: `func chunk(n: Int) -> [[Self.Generator.Element]]`
37− /// ```swift
38− /// [1, 2, 3, 4].window(2)
39− ///
40− /// [[1, 2], [2, 3], [3, 4]]
41− /// ```
42− @warn_unused_result
43− func window(n: Index.Distance) -> [SubSequence] {
44− var ret: [SubSequence] = []
45− ret.reserveCapacity(underestimateCount() - numericCast(n))
46− var i = startIndex
47− var j = i.advancedBy(n, limit: endIndex)
48− while true {
49− ret.append(self[i..<j])
50− i = i.successor()
51− if j == endIndex { return ret }
52− j = j.successor()
53− }
54− }
55−}
56−
57−// MARK: - Lazy
58−
59−// MARK: Chunk
60−/// :nodoc:
61−public struct ChunkGen<C: CollectionType> : GeneratorType {
62−
63− private var c: C
64− private let n: C.Index.Distance
65− private var i: C.Index
66−
67− public mutating func next() -> C.SubSequence? {
68− if i == c.endIndex { return nil }
69− let j = i.advancedBy(n, limit: c.endIndex)
70− defer { i = j }
71− return c[i..<j]
72− }
73−}
74−/// :nodoc:
75−public struct ChunkSeq<C: CollectionType> : LazySequenceType {
76−
77− private let c: C
78− private let n: C.Index.Distance
79− /// :nodoc:
80− public func generate() -> ChunkGen<C> {
81− return ChunkGen(c: c, n: n, i: c.startIndex)
82− }
83−}
84−
85−public extension LazyCollectionType {
86−
87− /// Returns lazily-generated arrays of n non-overlapping elements of self
88− /// - Parameter n: The size of the chunk
89− /// - SeeAlso: `func window(n: Int) -> WindowSeq<Self>`
90− /// ```swift
91− /// lazy([1, 2, 3, 4, 5]).chunk(2)
92− ///
93− /// [1, 2], [3, 4], [5]
94− /// ```
95− @warn_unused_result
96− func chunk(n: Index.Distance) -> ChunkSeq<Self> {
97− return ChunkSeq(c: self, n: n)
98− }
99−}
100−
101−// MARK: Window
102−/// :nodoc:
103−public struct WindowGen<C: CollectionType> : GeneratorType {
104−
105− private let c: C
106− private var i, j: C.Index
107− private var s: Bool
108− /// :nodoc:
109− mutating public func next() -> C.SubSequence? {
110− if s { return nil }
111− if j == c.endIndex {
112− s = true
113− return c[i..<j]
114− }
115− defer { (i,j) = (i.successor(),j.successor()) }
116− return c[i..<j]
117− }
118−}
119−
120−/// :nodoc:
121−
122−public struct WindowSeq<C: CollectionType> : LazySequenceType {
123−
124− private let c: C
125− private let n: C.Index.Distance
126− /// :nodoc:
127− public func generate() -> WindowGen<C> {
128− return WindowGen(c: c, i: c.startIndex, j: c.startIndex.advancedBy(n, limit: c.endIndex), s: false)
129− }
130−}
131−
132−public extension LazyCollectionType {
133−
134− /// Returns lazily-generated arrays of n overlapping elements of self
135− /// - Parameter n: The size of the window
136− /// - SeeAlso: `func chunk(n: Int) -> ChunkSeq<Self>`
137− /// ```swift
138− /// lazy([1, 2, 3, 4]).window(2)
139− ///
140− /// [1, 2], [2, 3], [3, 4]
141− /// ```
142− @warn_unused_result
143− func window(n: Index.Distance) -> WindowSeq<Self> {
144− return WindowSeq(c: self, n: n)
145− }
146−}
PixelImage/SwiftSugar/SwiftSequences/Combinations.swiftdeleted−114
@@ -1,114 +0,0 @@
1−/// :nodoc:
2−public struct ComboGen<SubElement> : GeneratorType {
3−
4− private let coll: [SubElement]
5− private var curr: [SubElement]
6− private var inds: [Int]
7− /// :nodoc:
8− mutating public func next() -> [SubElement]? {
9− for (max, curInd) in zip(coll.indices.reverse(), inds.indices.reverse())
10− where max != inds[curInd] {
11− curr[curInd] = coll[++inds[curInd]]
12− for j in inds.indices.suffixFrom(curInd+1) {
13− inds[j] = inds[j-1].successor()
14− curr[j] = coll[inds[j]]
15− }
16− return curr
17− }
18− return nil
19− }
20−}
21−/// :nodoc:
22−public struct ComboSeq<Element> : LazySequenceType {
23−
24− private let start: [Element]
25− private let col : [Element]
26− private let inds : [Int]
27− /// :nodoc:
28− public func generate() -> ComboGen<Element> {
29− return ComboGen<Element>(coll: col, curr: start, inds: inds)
30− }
31−
32− internal init(n: Int, col: [Element]) {
33− self.col = col
34− start = Array(col.prefixUpTo(n))
35− var inds = Array(col.indices.prefixUpTo(n))
36− if !inds.isEmpty { --inds[n.predecessor()] }
37− self.inds = inds
38− }
39−}
40−/// :nodoc:
41−public struct ComboRepGen<Element> : GeneratorType {
42−
43− private let coll: [Element]
44− private var curr: [Element]
45− private var inds: [Int]
46− private let max : Int
47− /// :nodoc:
48− mutating public func next() -> [Element]? {
49− for curInd in inds.indices.reverse() where max != inds[curInd] {
50− curr[curInd] = coll[++inds[curInd]]
51− for j in (curInd+1)..<inds.count {
52− inds[j] = inds[j-1]
53− curr[j] = coll[inds[j]]
54− }
55− return curr
56− }
57− return nil
58− }
59−}
60−/// :nodoc:
61−public struct ComboRepSeq<Element> : LazySequenceType {
62−
63− private let start: [Element]
64− private let inds : [Int]
65− private let col : [Element]
66− private let max : Int
67− /// :nodoc:
68− public func generate() -> ComboRepGen<Element> {
69− return ComboRepGen(coll: col, curr: start, inds: inds, max: max)
70− }
71−
72− internal init(n: Int, col: [Element]) {
73− self.col = col
74− start = col.first.map { x in Array(count: n, repeatedValue: x) } ?? []
75− var inds = Array(count: n, repeatedValue: col.startIndex)
76− if !inds.isEmpty { --inds[n-1] }
77− self.inds = inds
78− max = col.endIndex.predecessor()
79− }
80−}
81−
82−
83−extension SequenceType {
84− /**
85− Returns the combinations without repetition of length `n` of `self`
86− */
87− @warn_unused_result
88− public func combos(n: Int = 2) -> [[Generator.Element]] {
89− return Array(ComboSeq(n: n, col: Array(self)))
90− }
91− /**
92− Returns the combinations with repetition of length `n` of `self`
93− */
94− @warn_unused_result
95− public func combosWithRep(n: Int) -> [[Generator.Element]] {
96− return Array(ComboRepSeq(n: n, col: Array(self)))
97− }
98− /**
99− Returns the combinations without repetition of length `n` of `self`, generated lazily
100− and on-demand
101− */
102− @warn_unused_result
103− public func lazyCombos(n: Int) -> ComboSeq<Generator.Element> {
104− return ComboSeq(n: n, col: Array(self))
105− }
106− /**
107− Returns the combinations with repetition of length `n` of `self`, generated lazily and
108− on-demand
109− */
110− @warn_unused_result
111− public func lazyCombosWithRep(n: Int) -> ComboRepSeq<Generator.Element> {
112− return ComboRepSeq(n: n, col: Array(self))
113− }
114−}
PixelImage/SwiftSugar/SwiftSequences/Cycle.swiftdeleted−86
@@ -1,86 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: Cycle n
4−
5−public extension CollectionType {
6−
7− /// Returns an array of n cycles of self.
8− /// ```swift
9− /// [1, 2, 3].cycle(2)
10− ///
11− /// [1, 2, 3, 1, 2, 3]
12− /// ```
13− @warn_unused_result
14− func cycle(n: Int) -> [Generator.Element] {
15− var cycled: [Generator.Element] = []
16− cycled.reserveCapacity(underestimateCount() * n)
17− for _ in 0..<n {
18− cycled.appendContentsOf(self)
19− }
20− return cycled
21− }
22−}
23−
24−// MARK: - Lazy
25−
26−// MARK: Cycle n
27−/// :nodoc:
28−public struct CycleNGen<C: CollectionType> : GeneratorType, LazySequenceType {
29−
30− private let inner: C
31− private var innerGen: C.Generator
32− private var n: Int
33− /// :nodoc:
34− public mutating func next() -> C.Generator.Element? {
35− while true {
36− if let next = innerGen.next() { return next }
37− n -= 1
38− if n > 0 { innerGen = inner.generate() }
39− else { return nil }
40− }
41− }
42−}
43−
44−public extension LazySequenceType where Self : CollectionType {
45−
46− /// Returns a generator of n cycles of self.
47− /// ```swift
48− /// [1, 2, 3].lazy.cycle(2)
49− ///
50− /// 1, 2, 3, 1, 2, 3
51− /// ```
52− @warn_unused_result
53− func cycle(n: Int) -> CycleNGen<Self> {
54− return CycleNGen(inner: self, innerGen: generate(), n: n)
55− }
56−}
57−
58−// MARK: Cycle infinite
59−/// :nodoc:
60−public struct CycleGen<C: CollectionType> : GeneratorType, LazySequenceType {
61−
62− private let inner: C
63− private var innerGen: C.Generator
64− /// :nodoc:
65− public mutating func next() -> C.Generator.Element? {
66− for ;;innerGen = inner.generate() {
67− if let next = innerGen.next() {
68− return next
69− }
70− }
71− }
72−}
73−
74−public extension CollectionType {
75−
76− /// Returns an infinite generator of cycles of self.
77− /// ```swift
78− /// [1, 2, 3].cycle()
79− ///
80− /// 1, 2, 3, 1, 2, 3, 1...
81− /// ```
82− @warn_unused_result
83− func cycle() -> CycleGen<Self> {
84− return CycleGen(inner: self, innerGen: generate())
85− }
86−}
PixelImage/SwiftSugar/SwiftSequences/Enumerate.swiftdeleted−33
@@ -1,33 +0,0 @@
1−/// :nodoc:
2−public struct SpecEnumerateGen<Base : CollectionType> : GeneratorType {
3−
4− private let base: Base
5− private var i: Base.Index
6− /// :nodoc:
7− public mutating func next() -> (Base.Index, Base.Generator.Element)? {
8− return i == base.endIndex ? nil : (i, base[i++])
9− }
10−}
11−/// :nodoc:
12−public struct SpecEnumerateSeq<Base : CollectionType> : SequenceType {
13−
14− private let col: Base
15− /// :nodoc:
16− public func generate() -> SpecEnumerateGen<Base> {
17− return SpecEnumerateGen(base: col, i: col.startIndex)
18− }
19−}
20−
21−public extension CollectionType {
22−
23− /// Returns a lazy generator of tuples `(i, e)` where `i` is successive indices of self,
24− /// and `e` is the respective elements. Effectively the same as `.enumerate()`, but the
25− /// indices returned are `Self.Index`s, rather than `Int`s
26− /// - SeeAlso: `enumerate()`
27− @warn_unused_result
28− func specEnumerate() -> SpecEnumerateSeq<Self> {
29− return SpecEnumerateSeq(col: self)
30− }
31−}
32−
33−
PixelImage/SwiftSugar/SwiftSequences/Finding.swiftdeleted−80
@@ -1,80 +0,0 @@
1−prefix operator ! {}
2−public prefix func !<A>(f: A -> Bool) -> A -> Bool {
3− return { x in !f(x) }
4−}
5−
6−public extension SequenceType {
7−
8− /// Returns the first element in self that satisfies a predicate, or nil if it doesn't
9− /// exist
10− @warn_unused_result
11− func first(@noescape thatSatisfies: Generator.Element throws -> Bool) rethrows -> Generator.Element? {
12− for el in self where try thatSatisfies(el) { return el }
13− return nil
14− }
15−
16− /// Returns the number of elements in `self` that satisfy `predicate`
17− @warn_unused_result
18− func count(@noescape predicate: Generator.Element throws -> Bool) rethrows -> Int {
19− var i = 0
20− for el in self where try predicate(el) { i += 1 }
21− return i
22− }
23−
24− /// Returns true iff every element in `self` satisfies `predicate`
25− @warn_unused_result
26− func all(@noescape predicate: Generator.Element throws -> Bool) rethrows -> Bool {
27− for x in self { guard try predicate(x) else { return false } }
28− return true
29− }
30−}
31−
32−public extension CollectionType where Index : BidirectionalIndexType {
33−
34−
35− /// Returns the last element in self that satisfies a predicate, or nil if it doesn't
36− /// exist
37− @warn_unused_result
38− func last(@noescape predicate: Generator.Element throws -> Bool) rethrows -> Generator.Element? {
39− for el in reverse() {
40− if try predicate(el) {
41− return el
42− }
43− }
44− return nil
45− }
46−
47− /**
48− Returns the index of the final element in `self` which satisfies
49− `isElement`, or `nil` if it doesn't exist.
50− */
51− @warn_unused_result
52− func lastIndexOf(@noescape isElement: Generator.Element throws -> Bool) rethrows -> Index? {
53− for i in indices.reverse() where try isElement(self[i]) {
54− return i
55− }
56− return nil
57− }
58−}
59−
60−extension CollectionType {
61− /**
62− Returns the indices of elements of `self` that satisfy the predicate `isElement`
63− */
64− @warn_unused_result
65− func indicesOf(@noescape isElement: Generator.Element throws -> Bool) rethrows -> [Index] {
66− return try indices.filter { i in try isElement(self[i]) }
67− }
68−}
69−
70−public extension SequenceType {
71− @warn_unused_result
72− func partition(@noescape predicate: Generator.Element throws -> Bool) rethrows -> ([Generator.Element], [Generator.Element]) {
73− var t,f: [Generator.Element]
74− (t,f) = ([],[])
75− for e in self {
76− if try predicate(e) { t.append(e) } else { f.append(e) }
77− }
78− return (t,f)
79− }
80−}
PixelImage/SwiftSugar/SwiftSequences/FlatMap.swiftdeleted−23
@@ -1,23 +0,0 @@
1−extension LazySequenceType {
2−
3− @warn_unused_result
4− public func flatMap<T>(transform: Elements.Generator.Element -> T?)
5− -> LazyMapSequence<LazyFilterSequence<LazyMapSequence<Elements, T?>>, T> {
6− return self
7− .map(transform)
8− .filter { opt in opt != nil }
9− .map { notNil in notNil! }
10− }
11−}
12−
13−extension LazyCollectionType {
14−
15− @warn_unused_result
16− public func flatMap<T>(transform: Elements.Generator.Element -> T?)
17− -> LazyMapCollection<LazyFilterCollection<LazyMapCollection<Elements, T?>>, T> {
18− return self
19− .map(transform)
20− .filter { opt in opt != nil }
21− .map { notNil in notNil! }
22− }
23−}
PixelImage/SwiftSugar/SwiftSequences/Hopping.swiftdeleted−78
@@ -1,78 +0,0 @@
1−public struct RandomAccessHopCollection<
2− Base: CollectionType where
3− Base.Index : RandomAccessIndexType,
4− Base.Index.Distance : ForwardIndexType
5− >: CollectionType {
6−
7− private let base: Base
8− private let by : Base.Index.Stride
9− private let fac : Base.Index.Distance
10−
11− public let startIndex: Base.Index.Distance
12− public let endIndex: Base.Index.Distance
13−
14− public typealias SubSequence = RandomAccessHopCollection<Base>
15−
16− public subscript(i: Base.Index.Distance) -> Base.Generator.Element {
17− return base[base.startIndex.advancedBy(fac * i)]
18− }
19−
20− public func generate() -> IndexingGenerator<RandomAccessHopCollection<Base>> {
21− return IndexingGenerator(self)
22− }
23−
24− private init(_ b: Base, _ by: Base.Index.Stride) {
25− base = b
26− self.by = by
27− fac = base.startIndex.distanceTo(base.startIndex.advancedBy(by))
28− if base.isEmpty { endIndex = 0 }
29− else { endIndex = (base.startIndex.distanceTo(base.endIndex.predecessor()) / fac).successor() }
30− startIndex = 0
31− }
32−
33− private init(_ b: Base, _ by: Base.Index.Stride, from: Base.Index.Distance, to: Base.Index.Distance) {
34− base = b
35− self.by = by
36− fac = base.startIndex.distanceTo(base.startIndex.advancedBy(by))
37− startIndex = from
38− endIndex = to
39− }
40−
41− public subscript(r: Range<Base.Index.Distance>) -> RandomAccessHopCollection<Base> {
42− return RandomAccessHopCollection(base, by, from: r.startIndex, to: r.endIndex)
43− }
44−}
45−
46−extension CollectionType where Index: RandomAccessIndexType, Index.Distance: ForwardIndexType {
47− public subscript(by by: Index.Stride) -> RandomAccessHopCollection<Self> {
48− return RandomAccessHopCollection(self, by)
49− }
50−}
51−
52−extension RandomAccessHopCollection: CustomStringConvertible, CustomDebugStringConvertible {
53− public var debugDescription: String {
54− return Array(self).debugDescription
55− }
56− public var description: String {
57− return String(Array(self))
58− }
59−}
60−
61−public extension CollectionType where
62− SubSequence: CollectionType,
63− Index == SubSequence.Index,
64− SubSequence.Index: RandomAccessIndexType,
65− SubSequence.Index.Distance: ForwardIndexType {
66− subscript(r: Range<Index>, by by: Index.Stride) -> RandomAccessHopCollection<SubSequence> {
67− return self[r][by: by]
68− }
69− subscript(r: OpenEndedRange<Index>, by by: Index.Stride) -> RandomAccessHopCollection<SubSequence> {
70− return suffixFrom(r.val)[by: by]
71− }
72− subscript(r: OpenStartedRangeTo<Index>, by by: Index.Stride) -> RandomAccessHopCollection<SubSequence> {
73− return prefixUpTo(r.val)[by: by]
74− }
75− subscript(r: OpenStartedRangeThrough<Index>, by by: Index.Stride) -> RandomAccessHopCollection<SubSequence> {
76− return prefixThrough(r.val)[by: by]
77− }
78−}
PixelImage/SwiftSugar/SwiftSequences/Interpose.swiftdeleted−366
@@ -1,366 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: Interpose with single element
4−
5−public extension SequenceType {
6−
7− /// Returns an array that alternates between successive elements of self and element
8− /// ```swift
9− /// [1, 2, 3].interpose(10)
10− ///
11− /// [1, 10, 2, 10, 3]
12− /// ```
13− @warn_unused_result
14− func interpose(element: Generator.Element) -> [Generator.Element] {
15− var g = generate()
16−
17− return g.next().map {
18− var ret = [$0]
19− while let next = g.next() {
20− ret.append(element)
21− ret.append(next)
22− }
23− return ret
24− } ?? []
25− }
26−
27− /// Returns an array that alternates between n successive elements of self and element
28− /// ```swift
29− /// [1, 2, 3, 4, 5].interpose(10, n: 2)
30− ///
31− /// [1, 2, 10, 3, 4, 10, 5]
32− /// ```
33− @warn_unused_result
34− func interpose(element: Generator.Element, n: Int) -> [Generator.Element] {
35−
36− var ret: [Generator.Element] = []
37− var g = generate()
38− var i = n + 1
39−
40− while let next = g.next() {
41− if --i == 0 {
42− ret.append(element)
43− i = n
44− }
45− ret.append(next)
46− }
47− return ret
48− }
49−}
50−
51−// MARK: Interpose with collection
52−
53−public extension SequenceType {
54−
55− /// Returns an array that alternates between successive elements of self and elements of
56− /// a colletion
57− /// ```swift
58− /// [1, 2, 3].interpose([10, 20])
59− ///
60− /// [1, 10, 20, 2, 10, 20, 3]
61− /// ```
62− @warn_unused_result
63− func interpose<C : CollectionType where C.Generator.Element == Generator.Element>
64− (col: C) -> [Generator.Element] {
65− var g = generate()
66− return g.next().map {
67− var ret = [$0]
68− while let next = g.next() {
69− ret.appendContentsOf(col)
70− ret.append(next)
71− }
72− return ret
73− } ?? []
74− }
75−
76− /// Returns an array that alternates between n successive elements of self and elements
77− /// of a colletion
78− /// ```swift
79− /// [1, 2, 3, 4, 5].interpose([10, 20], n: 2)
80− ///
81− /// [1, 2, 10, 20, 3, 4, 10, 20, 5]
82− /// ```
83−
84− func interpose<C : CollectionType where C.Generator.Element == Generator.Element>
85− (col: C, n: Int) -> [Generator.Element] {
86− var g = generate()
87− return g.next().map {
88− var i = n
89− var ret = [$0]
90− while let next = g.next() {
91− if --i == 0 {
92− ret.appendContentsOf(col)
93− i = n
94− }
95− ret.append(next)
96− }
97− return ret
98− } ?? []
99− }
100−}
101−
102−// MARK: Interdigitate
103−
104−/// Returns an array of two sequences interdigitated
105−/// ```swift
106−/// interdig([1, 2, 3], [10, 20, 30])
107−///
108−/// [1, 10, 2, 20, 3, 30]
109−/// ```
110−@warn_unused_result
111−public func interdig<
112− S0 : SequenceType, S1 : SequenceType where
113− S0.Generator.Element == S1.Generator.Element
114− >(s0: S0, _ s1: S1) -> [S0.Generator.Element] {
115−
116− var ret: [S0.Generator.Element] = []
117−
118− var (g0, g1) = (s0.generate(), s1.generate())
119−
120− while let e0 = g0.next(), e1 = g1.next() {
121− ret.append(e0)
122− ret.append(e1)
123− }
124−
125− return ret
126−}
127−
128−/// Returns an array of two sequences interdigitated, with the respective length of each
129−/// interdigitation specified
130−/// - Parameter s0Len: The length of the first sequence's interdigitations
131−/// - Parameter s1Len: The length of the second sequence's interdigitations
132−/// ```swift
133−/// interdig([1, 2, 3, 4, 5], [10, 20, 30, 40, 50, 60], s0Len: 2, s1Len: 3)
134−///
135−/// [1, 2, 10, 20, 30, 3, 4, 40, 50, 60, 5]
136−/// ```
137−@warn_unused_result
138−public func interdig<
139− S0 : SequenceType, S1 : SequenceType where
140− S0.Generator.Element == S1.Generator.Element
141− >(s0: S0, _ s1: S1, s0Len: Int, s1Len: Int) -> [S0.Generator.Element] {
142−
143− var ret: [S0.Generator.Element] = []
144−
145− var (g0, g1) = (s0.generate(), s1.generate())
146−
147− for ;; {
148− for _ in 0..<s0Len {
149− if let next = g0.next() {
150− ret.append(next)
151− } else {
152− return ret
153− }
154− }
155− for _ in 0..<s1Len {
156− if let next = g1.next() {
157− ret.append(next)
158− } else {
159− return ret
160− }
161− }
162− }
163−}
164−
165−// MARK: - Lazy
166−
167−// MARK: Interpose with single element
168−/// :nodoc:
169−public struct InterposeElGen<G : GeneratorType> : GeneratorType {
170−
171− private let n: Int
172− private var count: Int
173− private var g: G
174− private let element: G.Element
175− /// :nodoc:
176− public mutating func next() -> G.Element? {
177− return --count < 0 ? {count = n; return element}() : g.next()
178− }
179−}
180−/// :nodoc:
181−public struct InterposeElSeq<S : SequenceType> : LazySequenceType {
182−
183− private let element: InterposeElGen<S.Generator>.Element
184− private let n: Int
185− private let seq: S
186− /// :nodoc:
187− public func generate() -> InterposeElGen<S.Generator> {
188− return InterposeElGen(n: n, count: n, g: seq.generate(), element: element)
189− }
190−}
191−
192−public extension LazySequenceType {
193−
194− /// Returns a lazy sequence that alternates between successive elements of self and an
195− /// element
196− /// ```swift
197− /// [1, 2, 3].lazy.interpose(10)
198− ///
199− /// 1, 10, 2, 10, 3, 10
200− /// ```
201− @warn_unused_result
202− func interpose(element: Generator.Element) -> InterposeElSeq<Self> {
203− return InterposeElSeq(element: element, n: 1, seq: self)
204− }
205−
206− /// Returns a lazy sequence that alternates between n successive elements of self and an
207− /// element
208− /// ```swift
209− /// [1, 2, 3, 4, 5].lazy.interpose(10, n: 2)
210− ///
211− /// 1, 2, 10, 3, 4, 10, 5
212− /// ```
213− @warn_unused_result
214− func interpose(element: Generator.Element, n: Int) -> InterposeElSeq<Self> {
215− return InterposeElSeq(element: element, n: n, seq: self)
216− }
217−}
218−
219−// MARK: Interpose with collection
220−/// :nodoc:
221−public struct InterposeColGen<
222− G : GeneratorType,
223− C: CollectionType where
224− G.Element == C.Generator.Element
225− > : GeneratorType {
226−
227− private let col: C
228− private var g: G
229− private let n: Int
230− private var count: Int
231− private var colG: C.Generator
232− /// :nodoc:
233− public mutating func next() -> G.Element? {
234− return --count <= 0 ? {
235− colG.next() ?? {
236− count = n
237− colG = col.generate()
238− return g.next()
239− }()}() : g.next()
240− }
241−}
242−/// :nodoc:
243−public struct InterposeColSeq<
244− S : SequenceType,
245− C: CollectionType where
246− S.Generator.Element == C.Generator.Element
247− > : LazySequenceType {
248−
249− private let col: C
250− private let n: Int
251− private let seq: S
252− /// :nodoc:
253− public func generate() -> InterposeColGen<S.Generator, C> {
254− return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate())
255− }
256−}
257−
258−public extension LazySequenceType {
259−
260− /// Returns a lazy sequence that alternates between successive elements of self and
261− /// elements of a colletion
262− /// ```swift
263− /// [1, 2, 3].lazy.interpose([10, 20])
264− ///
265− /// 1, 10, 20, 2, 10, 20, 3, 10, 20
266− /// ```
267− @warn_unused_result
268− func interpose<
269− C: CollectionType where
270− C.Generator.Element == Generator.Element
271− >(elements: C) -> InterposeColSeq<Self, C> {
272− return InterposeColSeq(col: elements, n: 1, seq: self)
273− }
274−
275− /// Returns a lazy sequence that alternates between n successive elements of self and
276− /// elements of a colletion
277− /// ```swift
278− /// [1, 2, 3, 4, 5].lazy.interpose([10, 20], n: 2)
279− ///
280− /// 1, 2, 10, 20, 3, 4, 10, 20, 5
281− /// ```
282− @warn_unused_result
283− func interpose<
284− C: CollectionType where
285− C.Generator.Element == Generator.Element
286− >(elements: C, n: Int) -> InterposeColSeq<Self, C> {
287− return InterposeColSeq(col: elements, n: n, seq: self)
288− }
289−}
290−
291−// MARK: Interdigitate
292−/// :nodoc:
293−public struct InterDigGen<
294− G0 : GeneratorType,
295− G1 : GeneratorType where
296− G0.Element == G1.Element
297− > : GeneratorType {
298−
299− private var g0: G0
300− private var g1: G1
301−
302− private let aN: Int
303− private let bN: Int
304−
305− private var count: Int
306− /// :nodoc:
307− public mutating func next() -> G0.Element? {
308− for (--count;;count = aN) {
309− if count >= bN { return count < 0 ? g1.next() : g0.next() }
310− }
311− }
312−}
313−/// :nodoc:
314−public struct InterDigSeq<
315− S0 : LazySequenceType,
316− S1 : LazySequenceType where
317− S0.Generator.Element == S1.Generator.Element
318− > : LazySequenceType {
319−
320− private let s0: S0
321− private let s1: S1
322−
323− private let aN: Int
324− private let bN: Int
325− /// :nodoc:
326− public func generate() -> InterDigGen<S0.Generator, S1.Generator> {
327− return InterDigGen(
328− g0: s0.generate(),
329− g1: s1.generate(),
330− aN: aN - 1,
331− bN: -bN,
332− count: aN
333− )
334− }
335−}
336−
337−/// Returns a lazy sequence of two sequences interdigitated
338−/// ```swift
339−/// interdig([1, 2, 3].lazy, [10, 20, 30].lazy)
340−///
341−/// 1, 10, 2, 20, 3, 30
342−/// ```
343−@warn_unused_result
344−public func interdig<
345− S0 : LazySequenceType, S1 : LazySequenceType where
346− S0.Generator.Element == S1.Generator.Element
347− >(s0: S0, _ s1: S1) -> InterDigSeq<S0, S1> {
348− return InterDigSeq(s0: s0, s1: s1, aN: 1, bN: 1)
349−}
350−
351−/// Returns a lazy sequence of two sequences interdigitated, with the respective length of
352−/// each interdigitation specified
353−/// - Parameter s0Len: The length of the first sequence's interdigitations
354−/// - Parameter s1Len: The length of the second sequence's interdigitations
355−/// ```swift
356−/// interdig([1, 2, 3, 4, 5].lazy, [10, 20, 30, 40, 50, 60].lazy, s0Len: 2, s1Len: 3)
357−///
358−/// 1, 2, 10, 20, 30, 3, 4, 40, 50, 60, 5
359−/// ```
360−@warn_unused_result
361−public func interdig<
362− S0 : SequenceType, S1 : SequenceType where
363− S0.Generator.Element == S1.Generator.Element
364− >(s0: S0, _ s1: S1, s0Len: Int, s1Len: Int = 1) -> InterDigSeq<S0, S1> {
365− return InterDigSeq(s0: s0, s1: s1, aN: s0Len, bN: s1Len)
366−}
PixelImage/SwiftSugar/SwiftSequences/Iterate.swiftdeleted−34
@@ -1,34 +0,0 @@
1−public struct IterateGenerator<Element>: GeneratorType {
2− private var x: Element
3− private let f: Element -> Element
4− public mutating func next() -> Element? {
5− defer { x = f(x) }
6− return x
7− }
8−}
9−
10−public struct IterateSequence<Element>: SequenceType {
11− private let x: Element
12− private let f: Element -> Element
13− public func generate() -> IterateGenerator<Element> {
14− return IterateGenerator(x: x, f: f)
15− }
16−}
17−
18−public struct IterateEndGenerator<Element>: GeneratorType {
19− private var x: Element?
20− private var f: Element -> Element?
21− public mutating func next() -> Element? {
22− guard let y = x else { return nil }
23− defer { x = f(y) }
24− return y
25− }
26−}
27−
28−public struct IterateEndSequence<Element>: SequenceType {
29− private let x: Element
30− private let f: Element -> Element?
31− public func generate() -> IterateEndGenerator<Element> {
32− return IterateEndGenerator(x: x, f: f)
33− }
34−}
PixelImage/SwiftSugar/SwiftSequences/NestedSequences.swiftdeleted−229
@@ -1,229 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: Cartesian Product
4−
5−private extension GeneratorType where Element : CollectionType {
6− mutating private func product() -> [[Element.Generator.Element]] {
7− guard let x = next() else { return [[]] }
8− let xs = product()
9− return x.flatMap { h in xs.map { [h] + $0 } }
10− }
11−}
12−
13−public extension SequenceType where Generator.Element : SequenceType, Generator.Element : CollectionType {
14−
15− /// Returns a cartesian product of self
16− /// ```swift
17− /// [[1, 2], [3, 4]].product()
18− /// [[1, 3], [1, 4], [2, 3], [2, 4]]
19− /// ```
20− @warn_unused_result
21− public func product() -> [[Generator.Element.Generator.Element]] {
22− var g = generate()
23− return g.product()
24− }
25−}
26−
27−public extension SequenceType where Generator.Element : SequenceType {
28−
29− /// Returns a cartesian product of self
30− /// ```swift
31− /// [[1, 2], [3, 4]].product()
32− /// [[1, 3], [1, 4], [2, 3], [2, 4]]
33− /// ```
34− @warn_unused_result
35− public func product() -> [[Generator.Element.Generator.Element]] {
36− return map(Array.init).product()
37− }
38−}
39−
40−/// Cartesian product
41−/// ```swift
42−/// product([1, 2], [3, 4])
43−/// [[1, 3], [1, 4], [2, 3], [2, 4]]
44−/// ```
45−@warn_unused_result
46−public func product<C : CollectionType>(cols: C...) -> [[C.Generator.Element]] {
47− return cols.product()
48−}
49−
50−/// Cartesian product
51−/// ```swift
52−/// product([1, 2], [3, 4])
53−/// [[1, 3], [1, 4], [2, 3], [2, 4]]
54−/// ```
55−
56−public func product<S : SequenceType>(cols: S...) -> [[S.Generator.Element]] {
57− return cols.product()
58−}
59−
60−// MARK: Transposition
61−
62−private extension SequenceType {
63− private func mapM<U>(@noescape transform: Generator.Element -> U?) -> [U]? {
64− var result: [U] = []
65− result.reserveCapacity(underestimateCount())
66− for e in self {
67− if let r = transform(e) { result.append(r) } else { return nil }
68− }
69− return result
70− }
71−}
72−
73−public extension SequenceType where Generator.Element : SequenceType {
74−
75− /// Returns a transposed self
76− /// ```swift
77− /// [[1, 2, 3], [1, 2, 3], [1, 2, 3]].transpose()
78− ///
79− /// [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
80− /// ```
81− @warn_unused_result
82− func transpose() -> [[Generator.Element.Generator.Element]] {
83− return Array(TransposeSeq(seq: self))
84− }
85−}
86−
87−// MARK: - Lazy
88−
89−// MARK: Cartesian Product
90−/// :nodoc:
91−public struct ProdGen<C : CollectionType> : GeneratorType {
92−
93− private let cols: [C] // Must be collections, not sequences, in order to be multi-pass
94−
95− private var gens: [C.Generator]
96− private var curr: [C.Generator.Element]
97− /// :nodoc:
98− public mutating func next() -> [C.Generator.Element]? {
99−
100− for i in gens.indices.reverse() { // Loop through generators in reverse order, rolling over
101− if let n = gens[i].next() { // if generator isn't finished, just increment that column, return
102− curr[i] = n
103− return curr
104− } else { // generator is finished
105− gens[i] = cols[i].generate() // reset the generator
106− curr[i] = gens[i].next()! // set the current column to the first element of the generator
107− }
108− }
109− return nil
110− }
111−
112− private init(cols: [C]) {
113− var gens = cols.map{$0.generate()}
114− self.cols = cols
115− curr = gens.dropLast().indices.map{gens[$0].next()!} + [self.cols.last!.first!]
116− /**
117− set curr to the first value of each of the generators, except the last: don't
118− increment this generator, so that the first value returned contains it.
119− */
120− self.gens = gens
121− }
122−}
123−/// :nodoc:
124−public struct ProdSeq<C : CollectionType> : LazySequenceType {
125− private let cols: [C]
126− /// :nodoc:
127− public func generate() -> ProdGen<C> {
128− return ProdGen( cols: cols )
129− }
130− /// :nodoc:
131− public func underestimateCount() -> Int {
132− return cols.reduce(1) { (n,c) in n * c.underestimateCount() }
133− }
134−}
135−
136−/// Lazy Cartesian Product
137−/// ```swift
138−/// lazyProduct([1, 2], [3, 4])
139−///
140−/// [1, 3], [1, 4], [2, 3], [2, 4]
141−/// ```
142−@warn_unused_result
143−public func lazyProduct<C : CollectionType>
144− (cols: C...) -> ProdSeq<C> {
145− return ProdSeq(cols: cols)
146−}
147−
148−/// Lazy Cartesian Product
149−/// ```swift
150−/// lazyProduct([1, 2], [3, 4])
151−///
152−/// [1, 3], [1, 4], [2, 3], [2, 4]
153−/// ```
154−@warn_unused_result
155−public func lazyProduct<S : SequenceType>
156− (cols: S...) -> ProdSeq<[S.Generator.Element]> {
157− return ProdSeq(cols: cols.map(Array.init))
158−}
159−
160−public extension SequenceType where Generator.Element : SequenceType {
161−
162− /// Lazy Cartesian Product
163− /// ```swift
164− /// [[1, 2], [3, 4]].lazyProduct()
165− ///
166− /// [1, 3], [1, 4], [2, 3], [2, 4]
167− /// ```
168− @warn_unused_result
169− func lazyProduct() -> ProdSeq<[Generator.Element.Generator.Element]> {
170− return ProdSeq(cols: map(Array.init))
171− }
172−}
173−
174−public extension SequenceType where Generator.Element : CollectionType {
175−
176− /// Lazy Cartesian Product
177− /// ```swift
178− /// [[1, 2], [3, 4]].lazyProduct()
179− ///
180− /// [1, 3], [1, 4], [2, 3], [2, 4]
181− /// ```
182− @warn_unused_result
183− func lazyProduct() -> ProdSeq<Generator.Element> {
184− return ProdSeq(cols: Array(self))
185− }
186−}
187−
188−// MARK: Transposition
189−/// :nodoc:
190−public struct TransposeGen<T, G : GeneratorType where G.Element == T> : GeneratorType {
191− private var gens: [G]
192− /// :nodoc:
193− mutating public func next() -> [T]? {
194− return gens.indices.mapM { i in gens[i].next() }
195− }
196−}
197−/// :nodoc:
198−public struct TransposeSeq<
199− S : SequenceType where
200− S.Generator.Element : SequenceType
201− > : LazySequenceType {
202− private let seq: S
203− /// :nodoc:
204− public func generate()
205− -> TransposeGen<S.Generator.Element.Generator.Element, S.Generator.Element.Generator>{
206− return TransposeGen(gens: seq.map { g in g.generate() })
207− }
208−}
209−
210−public extension TransposeSeq where S: CollectionType {
211− @warn_unused_result
212− public func underestimateCount() -> Int {
213− return seq.first?.underestimateCount() ?? 0
214− }
215−}
216−
217−public extension LazySequenceType where Generator.Element: SequenceType {
218−
219− /// Returns a lazily transposed self
220− /// ```swift
221− /// lazy([[1, 2, 3], [1, 2, 3], [1, 2, 3]]).transpose()
222− ///
223− /// [1, 1, 1], [2, 2, 2], [3, 3, 3]
224− /// ```
225− @warn_unused_result
226− func transpose() -> TransposeSeq<Self> {
227− return TransposeSeq(seq: self)
228− }
229−}
PixelImage/SwiftSugar/SwiftSequences/Permutations.swiftdeleted−187
@@ -1,187 +0,0 @@
1−// MARK: - Common
2−
3−public extension MutableCollectionType {
4−
5− /// [Algorithm](https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order)
6−
7− public mutating func nextLexPerm
8− (isOrderedBefore: (Generator.Element, Generator.Element) -> Bool) -> Self? {
9− for k in indices.reverse().dropFirst()
10− where isOrderedBefore(self[k], self[k.successor()]) {
11− for l in indices.reverse() where isOrderedBefore(self[k], self[l]) {
12− swap(&self[k], &self[l])
13− let r = (k.successor()..<endIndex)
14− for (x, y) in zip(r, r.reverse()) {
15− if x == y || x == y.successor() { return self }
16− swap(&self[x], &self[y])
17− }
18− }
19− }
20− return nil
21− }
22−}
23−
24−public extension MutableCollectionType where Generator.Element : Comparable {
25−
26− /// [Algorithm](https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order)
27−
28− public mutating func nextLexPerm() -> Self? {
29− return nextLexPerm(<)
30− }
31−}
32−/// :nodoc:
33−public struct LexPermGen<C : MutableCollectionType> : GeneratorType {
34− private var col: C?
35− private let order: (C.Generator.Element, C.Generator.Element) -> Bool
36− /// :nodoc:
37− mutating public func next() -> C? {
38− defer { col = col?.nextLexPerm(order) }
39− return col
40− }
41−}
42−/// :nodoc:
43−public struct LexPermSeq<C : MutableCollectionType> : LazySequenceType {
44− private let col: C
45− private let order: (C.Generator.Element, C.Generator.Element) -> Bool
46− /// :nodoc:
47− public func generate() -> LexPermGen<C> {
48− return LexPermGen(col: col, order: order)
49− }
50−}
51−
52−// MARK: - Eager
53−
54−public extension SequenceType {
55−
56− /// Returns an array of the permutations of self, ordered lexicographically, according
57− /// to the closure `isOrderedBefore`.
58− /// - Note: The permutations returned follow self, so if self is not the first
59− /// lexicographically ordered permutation, not all permutations will be returned.
60− /// ```swift
61− /// [1, 2, 3].lexPermutations(<)
62− ///
63− /// [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
64− /// ```
65− /// ```swift
66− /// [1, 2, 3].lexPermutations(>)
67− ///
68− /// [[1, 2, 3]]
69− /// ```
70− @warn_unused_result
71− public func lexPermutations
72− (isOrderedBefore: (Generator.Element, Generator.Element) -> Bool) -> [[Generator.Element]] {
73− return Array(LexPermSeq(col: Array(self), order: isOrderedBefore))
74− }
75−}
76−
77−public extension MutableCollectionType where Generator.Element : Comparable {
78−
79− /// Returns an array of the permutations of self, ordered lexicographically.
80− /// - Note: The permutations returned follow self, so if self is not the first
81− /// lexicographically ordered permutation, not all permutations will be returned.
82− /// ```swift
83− /// [1, 2, 3].lexPermutations()
84− ///
85− /// [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
86− /// ```
87− /// ```swift
88− /// [3, 2, 1].lexPermutations()
89− ///
90− /// [[3, 2, 1]]
91− /// ```
92− @warn_unused_result
93− public func lexPermutations() -> [[Generator.Element]] {
94− return Array(LexPermSeq(col: Array(self), order: <))
95− }
96−}
97−
98−public extension SequenceType {
99−
100− /// Returns an array of the permutations of self.
101− /// ```swift
102− /// [1, 2, 3].permutations()
103− ///
104− /// [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
105− /// ```
106− @warn_unused_result
107− public func permutations() -> [[Generator.Element]] {
108− var col = Array(self)
109− return Array(LexPermSeq(col: Array(col.indices), order: <).map { inds in inds.map{col[$0]} })
110− }
111− /// Returns an array of the permutations of length `n` of self.
112− /// ```swift
113− /// [1, 2, 3].permutations()
114− ///
115− /// [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
116− /// ```
117− public func permutations(n: Int) -> [[Generator.Element]] {
118− return Array(lazyCombos(n).flatMap { a in a.permutations() })
119− }
120−}
121−
122−// MARK: - Lazy
123−
124−public extension SequenceType {
125−
126− /// Returns a lazy sequence of the permutations of self, ordered lexicographically,
127− /// according to the closure `isOrderedBefore`.
128− /// - Note: The permutations returned follow self, so if self is not the first
129− /// lexicographically ordered permutation, not all permutations will be returned.
130− /// ```swift
131− /// lazy([1, 2, 3]).lazyLexPermutations(<)
132− ///
133− /// [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]
134− /// ```
135− /// ```swift
136− /// lazy([1, 2, 3]).lazyLexPermutations(>)
137− ///
138− /// [1, 2, 3]
139− /// ```
140− @warn_unused_result
141− public func lazyLexPermutations(isOrderedBefore: (Generator.Element, Generator.Element) -> Bool)
142− -> LexPermSeq<[Generator.Element]> {
143− return LexPermSeq(col: Array(self), order: isOrderedBefore)
144− }
145−}
146−
147−public extension SequenceType where Generator.Element : Comparable {
148−
149− /// Returns a lazy sequence of the permutations of self, ordered lexicographically.
150− /// - Note: The permutations returned follow self, so if self is not the first
151− /// lexicographically ordered permutation, not all permutations will be returned.
152− /// ```swift
153− /// lazy([1, 2, 3]).lazyLexPermutations()
154− ///
155− /// [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]
156− /// ```
157− /// ```swift
158− /// lazy([3, 2, 1]).lazyLexPermutations()
159− ///
160− /// [3, 2, 1]
161− /// ```
162− @warn_unused_result
163− public func lazyLexPermutations() -> LexPermSeq<[Generator.Element]> {
164− return LexPermSeq(col: Array(self), order: <)
165− }
166−}
167−
168−public extension SequenceType {
169−
170− /// Returns a lazy sequence of the permutations of self.
171− /// - Note: The permutations are lexicographically ordered, based on the indices of self
172− /// ```swift
173− /// lazy([1, 2, 3]).lazyPermutations()
174− ///
175− /// [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]
176− /// ```
177− /// ```swift
178− /// lazy([3, 2, 1]).lazyPermutations()
179− ///
180− /// [3, 2, 1], [3, 1, 2], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]
181− /// ```
182− @warn_unused_result
183− public func lazyPermutations() -> LazyMapSequence<LexPermSeq<[Int]>, [Self.Generator.Element]> {
184− let col = Array(self)
185− return col.indices.lazyLexPermutations().map { $0.map { col[$0] } }
186− }
187−}
PixelImage/SwiftSugar/SwiftSequences/ScanReduce.swiftdeleted−152
@@ -1,152 +0,0 @@
1−// MARK: - Eager
2−
3−public extension SequenceType {
4−
5− // MARK: Reduce1
6−
7− /// Return the result of repeatedly calling combine with an accumulated value
8− /// initialized to the first element of self and each element of self, in turn, i.e.
9− /// return combine(combine(...combine(combine(self[0], self[1]),
10− /// self[2]),...self[count-2]), self[count-1]).
11− /// ```swift
12− /// [1, 2, 3].reduce(+) // 6
13− /// ```
14− @warn_unused_result
15− func reduce
16− (@noescape combine: (accumulator: Generator.Element, element: Generator.Element) throws -> Generator.Element)
17− rethrows -> Generator.Element? {
18− var g = generate()
19− guard let a = g.next() else { return nil }
20− var accu = a
21− while let next = g.next() {
22− accu = try combine(accumulator: accu, element: next)
23− }
24− return accu
25− }
26−
27− // MARK: Scan
28−
29− /// Return an array where every value is equal to combine called on the previous
30− /// element, and the current element. The first element is taken to be initial.
31− /// ```swift
32− /// [1, 2, 3].scan(0, combine: +)
33− ///
34− /// [1, 3, 6]
35− /// ```
36− @warn_unused_result
37− func scan<T>(initial: T, @noescape combine: (accumulator: T, element: Generator.Element) throws -> T) rethrows -> [T] {
38− var accu = initial
39− return try map { e in
40− accu = try combine(accumulator: accu, element: e)
41− return accu
42− }
43− }
44−
45− // MARK: Scan1
46−
47− /// Return an array where every value is equal to combine called on the previous
48− /// element, and the current element.
49− /// ```swift
50− /// [1, 2, 3].scan(+)
51− ///
52− /// [3, 6]
53− /// ```
54− @warn_unused_result
55− func scan(@noescape combine: (accumulator: Generator.Element, element: Generator.Element) throws -> Generator.Element) rethrows -> [Generator.Element] {
56− var g = generate()
57− guard let i = g.next() else { return [] }
58− return try GeneratorSequence(g).scan(i, combine: combine)
59− }
60−}
61−
62−// MARK: - Lazy
63−
64−// MARK: Scan
65−
66−/// :nodoc:
67−public struct ScanGen<G : GeneratorType, T> : GeneratorType {
68−
69− private let combine: (T, G.Element) -> T
70− private var initial: T
71− private var g: G
72− /// :nodoc:
73− public mutating func next() -> T? {
74− guard let e = g.next() else { return nil }
75− initial = combine(initial, e)
76− return initial
77− }
78−}
79−
80−/// :nodoc:
81−public struct LazyScanSeq<S : SequenceType, T> : LazySequenceType {
82−
83− private let seq : S
84− private let combine: (T, S.Generator.Element) -> T
85− private let initial: T
86− /// :nodoc:
87− public func generate() -> ScanGen<S.Generator, T> {
88− return ScanGen(combine: combine, initial: initial, g: seq.generate())
89− }
90−}
91−
92−public extension LazySequenceType {
93−
94− /// Return a lazy sequence where every value is equal to combine called on the previous
95− /// element, and the current element. The first element is taken to be initial.
96− /// ```swift
97− /// lazy([1, 2, 3]).scan(0, combine: +)
98− ///
99− /// 1, 3, 6
100− /// ```
101− @warn_unused_result
102− func scan<T>(initial: T, combine: (accumulator: T, element: Generator.Element) -> T) -> LazyScanSeq<Self, T> {
103− return LazyScanSeq(seq: self, combine: combine, initial: initial)
104− }
105−}
106−
107−// MARK: Scan1
108−/// :nodoc:
109−public struct Scan1Gen<G : GeneratorType> : GeneratorType {
110−
111− private let combine: (G.Element, G.Element) -> G.Element
112− private var accu: G.Element?
113− private var g: G
114−
115− public mutating func next() -> G.Element? {
116− guard let a = accu, e = g.next() else { return nil }
117− accu = combine(a, e)
118− return accu!
119− }
120−
121− private init(combine: (G.Element, G.Element) -> G.Element, generator: G) {
122− g = generator
123− self.combine = combine
124− accu = g.next()
125− }
126−}
127−/// :nodoc:
128−public struct LazyScan1Seq<S : SequenceType> : LazySequenceType {
129−
130− private let seq: S
131− private let combine: (S.Generator.Element, S.Generator.Element) -> S.Generator.Element
132− /// :nodoc:
133− public func generate() -> Scan1Gen<S.Generator> {
134− return Scan1Gen(combine: combine, generator: seq.generate())
135− }
136−}
137−
138−public extension LazySequenceType {
139−
140− /// Return a lazy sequence where every value is equal to combine called on the previous
141− /// element, and the current element.
142− /// ```swift
143− /// lazy([1, 2, 3]).scan(+)
144− ///
145− /// 3, 6
146− /// ```
147− @warn_unused_result
148− func scan(combine: (accumulator: Generator.Element, element: Generator.Element) -> Generator.Element)
149− -> LazyScan1Seq<Self> {
150− return LazyScan1Seq(seq: self, combine: combine)
151− }
152−}
PixelImage/SwiftSugar/SwiftSequences/Slicing.swiftdeleted−138
@@ -1,138 +0,0 @@
1−// IntervalTypes
2−
3−public protocol OpenIntervalType {
4− typealias Value
5− func contains(v: Value) -> Bool
6−}
7−public protocol OpenEndedIntervalType: OpenIntervalType {
8− typealias Value: Comparable
9− var val: Value { get }
10−}
11−public protocol OpenStartedIntervalTypeTo: OpenIntervalType {
12− typealias Value: Comparable
13− var val: Value { get }
14−}
15−public protocol OpenStartedIntervalTypeThrough: OpenIntervalType {
16− typealias Value: Comparable
17− var val: Value { get }
18−}
19−
20−// Interval Structs
21−
22−public struct OpenEndedInterval<C: Comparable>: OpenEndedIntervalType {
23− public let val: C
24−}
25−public struct OpenStartedIntervalTo<C: Comparable>: OpenStartedIntervalTypeTo {
26− public let val: C
27−}
28−public struct OpenStartedIntervalThrough<C: Comparable>: OpenStartedIntervalTypeThrough {
29− public let val: C
30−}
31−
32−// Range structs
33−
34−public struct OpenEndedRange<I: ForwardIndexType where I: Comparable>: OpenEndedIntervalType {
35− public var val: I
36−}
37−public struct OpenStartedRangeTo<I: BidirectionalIndexType where I: Comparable>: OpenStartedIntervalTypeTo {
38− public var val: I
39−}
40−public struct OpenStartedRangeThrough<I: BidirectionalIndexType where I: Comparable>: OpenStartedIntervalTypeThrough {
41− public var val: I
42−}
43−
44−// Generators
45−
46−public struct EndlessIncrement<I: ForwardIndexType>: GeneratorType {
47− private var i: I
48− public mutating func next() -> I? {
49− defer { i = i.successor() }
50− return i
51− }
52−}
53−
54−// SequenceType
55−
56−extension OpenEndedRange: SequenceType {
57− public func generate() -> EndlessIncrement<I> {
58− return EndlessIncrement(i: val)
59− }
60−}
61−
62−// Operators
63−
64−postfix operator ... {}
65−prefix operator ... {}
66−prefix operator ..< {}
67−
68−public postfix func ...<C: Comparable>(c: C) -> OpenEndedInterval<C> {
69− return OpenEndedInterval(val: c)
70−}
71−public postfix func ...<I: ForwardIndexType>(c: I) -> OpenEndedRange<I> {
72− return OpenEndedRange(val: c)
73−}
74−public prefix func ..<<C: Comparable>(c: C) -> OpenStartedIntervalTo<C> {
75− return OpenStartedIntervalTo(val: c)
76−}
77−public prefix func ..<<C: BidirectionalIndexType>(c: C) -> OpenStartedRangeTo<C> {
78− return OpenStartedRangeTo(val: c)
79−}
80−public prefix func ... <C: Comparable>(c: C) -> OpenStartedIntervalThrough<C> {
81− return OpenStartedIntervalThrough(val: c)
82−}
83−public prefix func ... <C: BidirectionalIndexType>(c: C) -> OpenStartedRangeThrough<C> {
84− return OpenStartedRangeThrough(val: c)
85−}
86−
87−// Contains
88−
89−extension OpenEndedIntervalType {
90− public func contains(v: Value) -> Bool { return val <= v }
91−}
92−extension OpenStartedIntervalTypeTo {
93− public func contains(v: Value) -> Bool { return val > v }
94−}
95−extension OpenStartedIntervalTypeThrough {
96− public func contains(v: Value) -> Bool { return val >= v }
97−}
98−
99−// Pattern Matching
100−
101−public func ~=<I: OpenIntervalType>(lhs: I, rhs: I.Value) -> Bool {
102− return lhs.contains(rhs)
103−}
104−
105−// Indexing
106−
107−public extension CollectionType where Index: Comparable {
108− subscript(r: OpenEndedRange<Index>) -> SubSequence {
109− return suffixFrom(r.val)
110− }
111−}
112−
113−public extension CollectionType where Index: Comparable, Index: BidirectionalIndexType {
114− subscript(r: OpenStartedRangeTo<Index>) -> SubSequence {
115− return prefixUpTo(r.val)
116− }
117− subscript(r: OpenStartedRangeThrough<Index>) -> SubSequence {
118− return prefixThrough(r.val)
119− }
120−}
121−
122−public extension MutableCollectionType where Index: Comparable {
123− subscript(r: OpenEndedRange<Index>) -> SubSequence {
124− get { return suffixFrom(r.val) }
125− set { self[r.val..<endIndex] = newValue }
126− }
127−}
128−
129−public extension MutableCollectionType where Index: Comparable, Index: BidirectionalIndexType {
130− subscript(r: OpenStartedRangeTo<Index>) -> SubSequence {
131− get { return prefixUpTo(r.val) }
132− set { self[startIndex..<r.val] = newValue }
133− }
134− subscript(r: OpenStartedRangeThrough<Index>) -> SubSequence {
135− get { return prefixThrough(r.val) }
136− set { self[startIndex...r.val] = newValue }
137− }
138−}
PixelImage/SwiftSugar/SwiftSequences/TakeDrop.swiftdeleted−208
@@ -1,208 +0,0 @@
1−// MARK: - Eager
2−
3−// MARK: prefixWhile
4−
5−public extension SequenceType {
6−
7− /// Returns an array of self up until the first element that returns false for condition
8− /// ```swift
9− /// [1, 2, 3, 4, 5, 2].prefixWhile { $0 < 4 }
10− ///
11− /// [1, 2, 3]
12− /// ```
13− @warn_unused_result
14− func prefixWhile(@noescape condition: Generator.Element throws -> Bool) rethrows -> [Generator.Element] {
15− var ret : [Generator.Element] = []
16− var g = generate()
17− while let next = g.next() where try condition(next) { ret.append(next) }
18− return ret
19− }
20−}
21−
22−// MARK: DropWhile
23−
24−public extension SequenceType {
25−
26− /// Returns an array of self with the first elements that return true for condition
27− /// dropped
28− /// ```swift
29− /// [1, 2, 3, 4, 5, 2].dropWhile { $0 < 4 }
30− ///
31− /// [4, 5, 2]
32− /// ```
33− @warn_unused_result
34− func dropWhile(@noescape condition: Generator.Element throws -> Bool) rethrows -> [Generator.Element] {
35− var g = generate()
36− while let next = g.next() {
37− if try !condition(next) {
38− return [next] + GeneratorSequence(g)
39− }
40− }
41− return []
42− }
43−}
44−
45−public extension SequenceType {
46− /**
47− Returns a tuple of the prefix and suffix of `self`, the first element
48− being the prefix up to `n`.
49− */
50− public func breakAt(n: Int) -> ([Generator.Element],[Generator.Element]) {
51− let r = max(0, underestimateCount() - n)
52− var f,b : [Generator.Element]
53− (f,b) = ([],[])
54− f.reserveCapacity(n)
55− b.reserveCapacity(r)
56− var g = generate()
57− for _ in 0..<n {
58− if let e = g.next() { f.append(e) } else { return (f,b) }
59− }
60− while let e = g.next() { b.append(e) }
61− return (f,b)
62− }
63−}
64−
65−public extension CollectionType {
66− /**
67− Returns a tuple of the prefix and suffix of `self`, the first element
68− being the prefix up to `n`.
69− */
70− public func breakAt(n: Index) -> (SubSequence, SubSequence) {
71− return (prefixUpTo(n),suffixFrom(n))
72− }
73−}
74−
75−public extension CollectionType where Index == Int {
76− /**
77− Returns a tuple of the prefix and suffix of `self`, the first element
78− being the prefix up to `n`.
79− */
80− public func breakAt(n: Int) -> (SubSequence, SubSequence) {
81− return (prefixUpTo(n),suffixFrom(n))
82− }
83−}
84−public extension SequenceType {
85− /**
86− Returns a tuple of the prefix and suffix of `self`, the first element
87− being the prefix up to the first elements of `self` which returns
88− `true` for `isBreak`.
89− */
90− public func breakAt(@noescape isBreak: Generator.Element throws -> Bool)
91− rethrows -> ([Generator.Element],[Generator.Element]) {
92− var f,b : [Generator.Element]
93− (f,b) = ([],[])
94− var g = generate()
95− while let e = g.next() {
96− if try isBreak(e) {
97− b.append(e)
98− while let be = g.next() { b.append(be) }
99− return (f,b)
100− } else {
101− f.append(e)
102− }
103− }
104− return (f,b)
105− }
106−}
107−public extension CollectionType {
108− /**
109− Returns a tuple of the prefix and suffix of `self`, the first element
110− being the prefix up to the first elements of `self` which returns
111− `true` for `isBreak`.
112− */
113− public func breakAt(@noescape isBreak: Generator.Element throws -> Bool) rethrows -> (SubSequence, SubSequence) {
114− return try indexOf(isBreak).map(breakAt) ?? (suffixFrom(startIndex),prefixUpTo(startIndex))
115− }
116−}
117−// MARK: - Lazy
118−
119−// MARK: TakeWhile
120−/// :nodoc:
121−public struct WhileGen<G : GeneratorType> : GeneratorType {
122−
123− private var g: G
124− private let condition : G.Element -> Bool
125− /// :nodoc:
126− mutating public func next() -> G.Element? {
127− if let next = g.next() where condition(next) {
128− return next
129− }
130− return nil
131− }
132−}
133−/// :nodoc:
134−public struct WhileSeq<S : SequenceType> : LazySequenceType {
135−
136− private let seq: S
137− private let condition: S.Generator.Element -> Bool
138− /// :nodoc:
139− public func generate() -> WhileGen<S.Generator> {
140− return WhileGen(g: seq.generate(), condition: condition)
141− }
142−}
143−
144−public extension LazySequenceType {
145−
146− /// Returns a lazy sequence of self up until the first element that returns false for
147− /// condition
148− /// ```swift
149− /// [1, 2, 3, 4, 5, 2].lazy.takeWhile { $0 < 4 }
150− ///
151− /// 1, 2, 3
152− /// ```
153− @warn_unused_result
154− func prefixWhile(condition: Generator.Element -> Bool) -> WhileSeq<Self> {
155− return WhileSeq(seq: self, condition: condition)
156− }
157−}
158−
159−// MARK: DropWhile
160−/// :nodoc:
161−public struct DropWhileGen<G : GeneratorType> : GeneratorType {
162−
163− private let predicate: G.Element -> Bool
164− private var nG: G?
165− private var oG: G
166−
167− private init(g: G, predicate: G.Element -> Bool) {
168− nG = nil
169− oG = g
170− self.predicate = predicate
171− }
172− /// :nodoc:
173− public mutating func next() -> G.Element? {
174− guard nG == nil else { return nG!.next() }
175− while let next = oG.next() {
176− if !predicate(next) {
177− nG = oG
178− return next
179− }
180− }
181− return nil
182− }
183−}
184−/// :nodoc:
185−public struct DropWhileSeq<S : SequenceType> : LazySequenceType {
186−
187− private let predicate: S.Generator.Element -> Bool
188− private let seq: S
189− /// :nodoc:
190− public func generate() -> DropWhileGen<S.Generator> {
191− return DropWhileGen(g: seq.generate(), predicate: predicate)
192− }
193−}
194−
195−public extension LazySequenceType {
196−
197− /// Returns a lazy sequence of self with the first elements that return true for
198− /// condition dropped
199− /// ```swift
200− /// [1, 2, 3, 4, 5, 2].lazy.dropWhile { $0 < 4 }
201− ///
202− /// 4, 5, 2
203− /// ```
204− @warn_unused_result
205− func dropWhile(predicate: Generator.Element -> Bool) -> DropWhileSeq<Self> {
206− return DropWhileSeq(predicate: predicate, seq: self)
207− }
208−}
PixelImage/SwiftSugar/SwiftSequences/Zip.swiftdeleted−90
@@ -1,90 +0,0 @@
1−/// :nodoc:
2−public struct NilPaddedZipGenerator<G0: GeneratorType, G1: GeneratorType> : GeneratorType {
3−
4− private var (g0, g1): (G0?, G1?)
5−
6− public mutating func next() -> (G0.Element?, G1.Element?)? {
7− let (e0,e1) = (g0?.next(),g1?.next())
8− switch (e0,e1) {
9− case (nil,nil): return nil
10− case ( _,nil): g1 = nil
11− case (nil, _): g0 = nil
12− default: break
13− }
14− return (e0,e1)
15− }
16−}
17−/// :nodoc:
18−public struct NilPaddedZip<S0: SequenceType, S1: SequenceType> : LazySequenceType {
19−
20− private let (s0, s1): (S0, S1)
21− /// :nodoc:
22− public func generate() -> NilPaddedZipGenerator<S0.Generator, S1.Generator> {
23− return NilPaddedZipGenerator(g0: s0.generate(), g1: s1.generate())
24− }
25−}
26−
27−/// A sequence of pairs built out of two underlying sequences, where the elements of the
28−/// ith pair are optional ith elements of each underlying sequence. If one sequence is
29−/// shorter than the other, pairs will continue to be returned after it is exhausted, but
30−/// with its elements replaced by nil.
31−/// ```swift
32−/// zipWithPadding([1, 2, 3], [1, 2])
33−///
34−/// (1?, 1?), (2?, 2?), (3?, nil)
35−/// ```
36−@warn_unused_result
37−public func zipWithPadding<S0: SequenceType, S1: SequenceType>(s0: S0, _ s1: S1)
38− -> NilPaddedZip<S0, S1> {
39− return NilPaddedZip(s0: s0, s1: s1)
40−}
41−/// :nodoc:
42−public struct PaddedZipGenerator<G0: GeneratorType, G1: GeneratorType> : GeneratorType {
43−
44− typealias E0 = G0.Element
45− typealias E1 = G1.Element
46−
47− private var g: NilPaddedZipGenerator<G0, G1>
48− private let (p0, p1): (E0, E1)
49−
50− public mutating func next() -> (E0, E1)? {
51− guard let (e0,e1) = g.next() else { return nil }
52− return (e0 ?? p0, e1 ?? p1)
53− }
54−}
55−/// :nodoc:
56−public struct PaddedZip<S0: SequenceType, S1: SequenceType> : LazySequenceType {
57−
58− private let (s0, s1): (S0, S1)
59− private let (p0, p1): (S0.Generator.Element, S1.Generator.Element)
60− /// :nodoc:
61− public func generate() -> PaddedZipGenerator<S0.Generator, S1.Generator> {
62− return PaddedZipGenerator(
63− g: NilPaddedZipGenerator(
64− g0: s0.generate(),
65− g1: s1.generate()
66− ),
67− p0: p0,
68− p1: p1
69− )
70− }
71−}
72−
73−/// A sequence of pairs built out of two underlying sequences, where the elements of the
74−/// ith pair are the ith elements of each underlying sequence. If one sequence is
75−/// shorter than the other, pairs will continue to be returned after it is exhausted, but
76−/// with its elements replaced by its respective pad.
77−/// - Parameter pad0: the element to pad `s0` with after it is exhausted
78−/// - Parameter pad1: the element to pad `s1` with after it is exhausted
79−/// ```swift
80−/// zipWithPadding([1, 2, 3], [1, 2], pad0: 100, pad1: 900)
81−///
82−/// (1, 1), (2, 2), (3, 900)
83−/// ```
84−@warn_unused_result
85−public func zipWithPadding<
86− S0: SequenceType, S1: SequenceType
87− >(s0: S0, _ s1: S1, pad0: S0.Generator.Element, pad1: S1.Generator.Element)
88− -> PaddedZip<S0, S1> {
89− return PaddedZip(s0: s0, s1: s1, p0: pad0, p1: pad1)
90−}
PixelImage/SwiftSugar/TestCommons.swiftdeleted−96
@@ -1,96 +0,0 @@
1−// TODO: Preconditions
2−// TODO: Test memoization
3−// TODO: Reorganize Swift Sugar folders
4−// TODO: Sugar documentation
5−// TODO: Add Swift Sugar to git
6−// TODO: Add LINT to EngineKit
7−// TODO: Add @warnunusedresult where appropriate
8−
9−import Darwin
10−
11−class Random<T: Numeric> {
12−
13− let max: Double = Double(INT32_MAX)
14− let exponent: Double = 7
15−
16− init(example: T) {
17− setupRandomSeed()
18− }
19−
20− private func expRandom() -> Double {
21− let rawRandom = Double(rand()) / max
22− let exponentiated = (3 * rawRandom) ^ exponent
23− return exponentiated
24− }
25−
26− private func uniRandom() -> Double {
27− return Double(rand()) / max
28− }
29−
30− private func setupRandomSeed() {
31− var now = time(nil)
32− var date = tm()
33− localtime_r(&now, &date)
34− let day = date.tm_yday
35− let year = date.tm_year
36− srand(UInt32(365 * year + day))
37− }
38−
39− func nonnegativeRandomNumber() -> T {
40− let random = expRandom()
41− return T.fromDouble(random)
42− }
43−
44− func positiveRandomNumber() -> T {
45− let random = expRandom()
46− let result = T.fromDouble(random)
47−
48− guard result != 0 else {
49− return positiveRandomNumber()
50− }
51−
52− return result
53− }
54−
55− func randomNumber() -> T {
56− let random = expRandom()
57− let signed = random * ±(Double(rand()) - max)
58− return T.fromDouble(signed)
59− }
60−
61− func uniformRandomNumber(from tStart: T, to tEnd: T) -> T {
62− let start = tStart.toDouble
63− let end = tEnd.toDouble
64−
65− let rawRandom = uniRandom()
66− let interval = end - start
67− let result = start + (rawRandom * interval)
68− return T.fromDouble(result)
69− }
70−
71− func uniformRandomNumber(start tStart: T, interval tInterval: T)
72− -> T {
73− let start = tStart.toDouble
74− let interval = tInterval.toDouble
75−
76− let rawRandom = uniRandom()
77− let result = start + (rawRandom * interval)
78− return T.fromDouble(result)
79− }
80−
81− func uniformRandomNumber(center tCenter: T,
82− maxDeviation tInterval: T) -> T {
83− let center = tCenter.toDouble
84− let interval = tInterval.toDouble
85− let start = T.fromDouble(center - interval / 2)
86−
87− return uniformRandomNumber(start: start, interval: tInterval)
88− }
89−
90− func randomSign() -> T {
91− let rawRandom = rand() % 2
92− let result = Double((2 * rawRandom) - 1)
93− return T.fromDouble(result)
94− }
95−
96−}
PixelImage/UIColor.swift+6
@@ -7,3 +7,9 @@ extension UIColor {
7 return (r, g, b, a)
7 return (r, g, b, a)
8 }
8 }
9}
9}
10+
11+extension UIColor {
12+ convenience init(red255 red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
13+ self.init(red: red / 255, green: green / 255, blue: blue / 255, alpha: alpha / 255)
14+ }
15+}
PixelImage/UIKit.swift+80−1
@@ -1,3 +1,5 @@
1+// TODO: Unite UIView and CALayer extensions under a common protocol
2+
1import UIKit
3import UIKit
2
4
3func - (left: CGPoint, right: CGPoint) -> CGVector {
5func - (left: CGPoint, right: CGPoint) -> CGVector {
@@ -40,7 +42,7 @@ extension CGFloat: DoubleValuable {
40 }
42 }
41 }
43 }
42
44
43− static func fromDouble(double: Double) -> CGFloat {
45+ static func fromDouble(_ double: Double) -> CGFloat {
44 return CGFloat(double)
46 return CGFloat(double)
45 }
47 }
46
48
@@ -138,3 +140,80 @@ extension UIView {
138 }
140 }
139 }
141 }
140}
142}
143+
144+extension CALayer {
145+ var origin: CGPoint {
146+ get {
147+ return frame.origin
148+ }
149+ set {
150+ frame.origin = newValue
151+ }
152+ }
153+
154+ var size: CGSize {
155+ get {
156+ return frame.size
157+ }
158+ set {
159+ frame.size = newValue
160+ }
161+ }
162+
163+ var width: CGFloat {
164+ get {
165+ return frame.width
166+ }
167+ set {
168+ frame.size = CGSize(width: newValue, height: height)
169+ }
170+ }
171+
172+ var height: CGFloat {
173+ get {
174+ return frame.height
175+ }
176+ set {
177+ frame.size = CGSize(width: width, height: newValue)
178+ }
179+ }
180+
181+ var middle: CGPoint {
182+ get {
183+ return CGPoint(x: origin.x + width / 2, y: origin.y + height / 2)
184+ }
185+ set {
186+ origin = CGPoint(x: newValue.x - width / 2, y: newValue.y - height / 2)
187+ }
188+ }
189+
190+ var midX: CGFloat {
191+ get {
192+ return middle.x
193+ }
194+ set {
195+ middle = CGPoint(x: newValue, y: midY)
196+ }
197+ }
198+
199+ var midY: CGFloat {
200+ get {
201+ return middle.y
202+ }
203+ set {
204+ middle = CGPoint(x: midX, y: newValue)
205+ }
206+ }
207+}
208+
209+let screenRect = UIScreen.main.bounds
210+let screenWidth = screenRect.size.width
211+let screenHeight = screenRect.size.height
212+
213+func * <T: Numeric>(vector: CGVector, scalar: T) -> CGVector {
214+ return CGVector(dx: vector.dx * CGFloat(scalar.toDouble), dy: vector.dy * CGFloat(scalar.toDouble))
215+}
216+
217+func + (point: CGPoint, vector: CGVector) -> CGPoint {
218+ return CGPoint(x: point.x + vector.dx, y: point.y + vector.dy)
219+}
PixelImage/ViewController.swift+220−118
@@ -2,123 +2,225 @@ import UIKit
2
2
3class ViewController: UIViewController, MetaballDataSource {
3class ViewController: UIViewController, MetaballDataSource {
4
4
5− var metaballView: UIImageView!
5+ var metaballView: UIImageView!
6− var renderer: MetalMetaballRenderer!
6+ var renderer: MetalMetaballRenderer!
7+
8+ let width = 350
9+ let height = 600
10+
11+ var metaballGraph: Graph<Metaball>!
12+ var previousLocation: CGPoint!
13+
14+ var selectedMetaball: Metaball?
15+
16+ let edgeAnimationDuration: Float = 1
17+
18+ override func viewDidLoad() {
19+ super.viewDidLoad()
20+
21+ view.backgroundColor = UIColor.white
22+
23+ let recognizer = UIPanGestureRecognizer(
24+ target: self,
25+ action: #selector(ViewController.handlePan(_:)))
26+ view.addGestureRecognizer(recognizer)
27+
28+ var positions = [CGPoint]()
29+ positions.append(CGPoint(
30+ x: Double(screenWidth) / 2,
31+ y: Double(screenHeight) / 2))
32+ for i in 1...5 {
33+ let sine = sin(Double(i) * 2 * .pi / 5)
34+ let cosine = cos(Double(i) * 2 * .pi / 5)
35+ let radius: Double = 150
36+ let x = Double(screenWidth) / 2 + sine * radius
37+ let y = Double(screenHeight) / 2 + cosine * radius
38+ positions.append(CGPoint(x: x, y: y))
39+ }
40+
41+ let colors =
42+ [UIColor(red255: 110, green: 220, blue: 220, alpha: 1.0),
43+ UIColor(red255: 250, green: 235, blue: 50, alpha: 1.0),
44+ UIColor(red255: 110, green: 220, blue: 220, alpha: 1.0),
45+ UIColor(red255: 90, green: 170, blue: 170, alpha: 1.0),
46+ UIColor(red255: 90, green: 170, blue: 170, alpha: 1.0),
47+ UIColor(red255: 110, green: 220, blue: 220, alpha: 1.0)]
48+ let metaballs = zip(positions, colors).map {
49+ Metaball(position: $0.0, color: $0.1)
50+ }
51+
52+ metaballGraph = Graph(vertices: metaballs)
53+
54+ let metaballViewFrame = screenRect
55+ renderer = MetalMetaballRenderer(dataSource: self,
56+ frame: metaballViewFrame)
57+ metaballView = renderer.targetView
58+ view.addSubview(metaballView)
59+
60+ for metaball in metaballs {
61+ metaballView.addSubview(metaball)
62+ }
63+
64+ delay(1.0) {
65+ self.addEdge(0, 1)
66+ self.addEdge(0, 2)
67+ self.addEdge(0, 3)
68+ self.addEdge(0, 4)
69+ self.addEdge(0, 5)
70+ }
71+
72+ delay(2.3) {
73+ self.removeEdge(0, 1)
74+ self.removeEdge(0, 2)
75+ self.removeEdge(0, 3)
76+ self.removeEdge(0, 4)
77+ self.removeEdge(0, 5)
78+ }
79+
80+ delay(4) {
81+ for i in 1...5 {
82+ UIView.animate(withDuration: 1.0, delay: 0,
83+ options: UIView.AnimationOptions(),
84+ animations: { () -> Void in
85+ let sine = sin(Double(i) * 2 * .pi / 5)
86+ let cosine = cos(Double(i) * 2 * .pi / 5)
87+ let radius: Double = 85
88+ let x = Double(screenWidth) / 2 + sine * radius
89+ let y = Double(screenHeight) / 2 + cosine * radius
90+ let metaball = metaballs[i]
91+ self.animateMetaball(metaball, toPoint: CGPoint(x: x, y: y))
92+ }, completion: nil)
93+ }
94+ }
95+
96+ delay(6) { () -> () in
97+ for i in 1...5 {
98+ UIView.animate(withDuration: 1.0, delay: 0,
99+ usingSpringWithDamping: 0.5,
100+ initialSpringVelocity: 0,
101+ options: UIView.AnimationOptions(),
102+ animations: { () -> Void in
103+ let sine = sin(Double(i) * 2 * .pi / 5)
104+ let cosine = cos(Double(i) * 2 * .pi / 5)
105+ let radius: Double = 150
106+ let x = Double(screenWidth) / 2 + sine * radius
107+ let y = Double(screenHeight) / 2 + cosine * radius
108+ let metaball = metaballs[i]
109+ self.animateMetaball(metaball, toPoint: CGPoint(x: x, y: y))
110+ }, completion: nil)
111+ }
112+ }
113+
114+ renderer.state = .running
115+ }
116+
117+ func addEdge(_ i: Int, _ j: Int) {
118+ animateEdge(i, j, fadeIn: true)
119+ }
120+
121+ func removeEdge(_ i: Int, _ j: Int) {
122+ animateEdge(i, j, fadeIn: false)
123+ }
124+
125+ func animateMetaball(_ metaball: Metaball, toPoint destination: CGPoint) {
126+ let parameters = VertexAnimationParameters(startDate: Date(),
127+ duration: 1.0,
128+ origin: metaball.center,
129+ destination: destination,
130+ metaball: metaball)
131+ Timer.scheduledTimer(
132+ timeInterval: 1.0 / 60.0,
133+ target: self,
134+ selector: #selector(ViewController.animateMetaball(withTimer:)),
135+ userInfo: parameters,
136+ repeats: true)
137+ }
138+
139+ @objc func animateMetaball(withTimer timer: Timer) {
140+ guard let userInfo = timer.userInfo as? VertexAnimationParameters else {
141+ preconditionFailure()
142+ }
143+ let (animationStart, duration, origin, destination, metaball) =
144+ (userInfo).unpack()
145+
146+ let now = Date()
147+ var timeElapsed = Float(now.timeIntervalSince(animationStart))
148+
149+ if timeElapsed > duration {
150+ timer.invalidate()
151+ timeElapsed = duration
152+ }
153+
154+ let linearValue = timeElapsed / duration
155+ let interpolatedValue = interpolateSmooth(linearValue)
156+
157+ let position = origin + ((destination - origin) * interpolatedValue)
158+ metaball.center = position
159+
160+ renderer.state = .running
161+ }
162+
163+ func animateEdge(_ i: Int, _ j: Int, fadeIn: Bool) {
164+ let parameters = EdgeAnimationParameters(startDate: Date(),
165+ duration: edgeAnimationDuration,
166+ fadeIn: fadeIn,
167+ i: i,
168+ j: j)
169+ Timer.scheduledTimer(
170+ timeInterval: 1.0 / 60.0,
171+ target: self,
172+ selector: #selector(ViewController.animateEdge(withTimer:)),
173+ userInfo: parameters,
174+ repeats: true)
175+ }
176+
177+ @objc func animateEdge(withTimer timer: Timer) {
178+ guard let userInfo = timer.userInfo as? EdgeAnimationParameters else {
179+ preconditionFailure()
180+ }
181+ let (animationStart, duration, fadeIn, i, j) = (userInfo).unpack()
182+
183+ let now = Date()
184+ var timeElapsed = Float(now.timeIntervalSince(animationStart))
185+
186+ if timeElapsed > duration {
187+ timer.invalidate()
188+ timeElapsed = duration
189+ }
190+
191+ let linearValue = timeElapsed / duration
192+ let interpolatedValue = fadeIn ?
193+ interpolateSquareEaseOut(linearValue) :
194+ (1 - interpolateSquareEaseIn(linearValue))
195+
196+ metaballGraph.adjacencyMatrix.set(i, j, value: interpolatedValue)
197+ metaballGraph.adjacencyMatrix.set(j, i, value: interpolatedValue)
198+
199+ renderer.state = .running
200+ }
201+
202+ @objc func handlePan(_ recognizer: UIPanGestureRecognizer) {
203+ let location = recognizer.location(in: metaballView)
204+
205+ if selectedMetaball == nil {
206+ for metaball in metaballs where
207+ abs(metaball.midX - location.x) < 50 &&
208+ abs(metaball.midY - location.y) < 50
209+ {
210+ selectedMetaball = metaball
211+ break
212+ }
213+ }
214+
215+ guard selectedMetaball != nil else { return }
216+
217+ selectedMetaball?.middle = location
218+
219+ renderer.state = .running
220+
221+ if recognizer.state == .ended {
222+ selectedMetaball = nil
223+ }
224+ }
7
225
8− let width = 350
9− let height = 600
10−
11− var metaballGraph: Graph<Metaball>!
12− var previousLocation: CGPoint!
13−
14− var selectedMetaball: Metaball?
15−
16− let edgeAnimationDuration: Float = 1
17−
18− override func viewDidLoad() {
19− super.viewDidLoad()
20−
21− let recognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
22− view.addGestureRecognizer(recognizer)
23−
24− let metaballs = [CGPoint(x: 70, y: 70), CGPoint(x: 270, y: 70), CGPoint(x: 270, y: 470), CGPoint(x: 70, y: 470)].map {
25− Metaball(position: $0)
26− }
27− metaballGraph = Graph(vertices: metaballs)
28− metaballGraph.addEdge(0, 1)
29− metaballGraph.addEdge(0, 3)
30− metaballGraph.addEdge(1, 2)
31− metaballGraph.addEdge(1, 3)
32− metaballGraph.addEdge(2, 3)
33−
34− let border = 20
35− let metaballViewFrame = CGRect(x: border / 2, y: border / 2, width: width, height: height)
36− renderer = MetalMetaballRenderer(dataSource: self, frame: metaballViewFrame)
37− metaballView = renderer.targetView
38−
39− let bigView = UIView(frame: CGRect(x: 10, y: 70, width: width + border, height: height + border))
40− bigView.backgroundColor = UIColor.redColor()
41− bigView.addSubview(metaballView)
42− view.addSubview(bigView)
43−
44− for metaball in metaballs {
45− metaballView.addSubview(metaball)
46− }
47−
48− addEdge(0, 2)
49−
50− renderer.state = .Running
51− }
52−
53− func addEdge(i: Int, _ j: Int) {
54− animateEdge(i, j, fadeIn: true)
55− }
56−
57− func removeEdge(i: Int, _ j: Int) {
58− animateEdge(i, j, fadeIn: false)
59− }
60−
61− func animateEdge(i: Int, _ j: Int, fadeIn: Bool) {
62− let parameters = EdgeAnimationParameters(startDate: NSDate(), duration: edgeAnimationDuration, fadeIn: fadeIn, i: i, j: j)
63− NSTimer.scheduledTimerWithTimeInterval(1.0 / 60.0, target: self, selector: "animateEdgeWithTimer:", userInfo: parameters, repeats: true)
64− }
65−
66− func animateEdge(withTimer timer: NSTimer) {
67− guard let userInfo = timer.userInfo as? EdgeAnimationParameters else { preconditionFailure() }
68− let (animationStart, duration, fadeIn, i, j) = (userInfo).unpack()
69−
70− let now = NSDate()
71− var timeElapsed = Float(now.timeIntervalSinceDate(animationStart))
72−
73− if timeElapsed > duration {
74− timer.invalidate()
75− timeElapsed = duration
76− }
77−
78− let linearValue = timeElapsed / duration
79− let interpolatedValue = fadeIn ? interpolateSquareEaseOut(linearValue) : (1 - interpolateSquareEaseIn(linearValue))
80−
81− metaballGraph.adjacencyMatrix.set(i, j, value: interpolatedValue)
82− metaballGraph.adjacencyMatrix.set(j, i, value: interpolatedValue)
83−
84− renderer.state = .Running
85− }
86−
87− func handlePan(recognizer: UIPanGestureRecognizer) {
88− let location = recognizer.locationInView(metaballView)
89−
90− if selectedMetaball == nil {
91− for metaball in metaballs where
92− abs(metaball.midX - location.x) < 50 && abs(metaball.midY - location.y) < 50 {
93− selectedMetaball = metaball
94− break
95− }
96− }
97−
98− guard selectedMetaball != nil else { return }
99−
100− selectedMetaball?.middle = location
101−
102− renderer.state = .Running
103−
104− if recognizer.state == .Ended {
105− selectedMetaball = nil
106− }
107− }
108−
109−}
110−
111−class Metaball: UIView {
112−
113− init(position: CGPoint) {
114− super.init(frame: CGRect.zero)
115−
116− size = CGSize(50)
117− middle = position
118− backgroundColor = UIColor(randomFlatColorOfShadeStyle: .Light)
119− }
120−
121− required init?(coder aDecoder: NSCoder) {
122− super.init(coder: aDecoder)
123− }
124}
226}
PixelImage/shaders.metal+21−18
@@ -23,7 +23,6 @@ kernel void
23 float3 colorSum = float3(0, 0, 0);
23 float3 colorSum = float3(0, 0, 0);
24 float colorAccumulation = 0;
24 float colorAccumulation = 0;
25 float3 colorSumLink = float3(0, 0, 0);
25 float3 colorSumLink = float3(0, 0, 0);
26− float greatestLinkWeight = 0.0;
27
26
28 char x, y;
27 char x, y;
29
28
@@ -34,9 +33,10 @@ kernel void
34 for (x = 1; x <= numberOfMetaballs; x += 1) {
33 for (x = 1; x <= numberOfMetaballs; x += 1) {
35 metaballData metaball = metaballBuffer[x];
34 metaballData metaball = metaballBuffer[x];
36 float2 metaballPosition = float2(metaball.x, metaball.y);
35 float2 metaballPosition = float2(metaball.x, metaball.y);
37− float2 vector
38− = float2(metaballPosition.x - gid.x, metaballPosition.y - gid.y);
36+ float2 vector = float2(metaballPosition.x - gid.x,
39− float squaredDistance = dot(vector, vector);
37+ metaballPosition.y - gid.y);
38+ float dotProduct = dot(vector, vector);
39+ float squaredDistance = dotProduct > 0 ? dotProduct : 1;
40 float realDistance = sqrt(squaredDistance);
40 float realDistance = sqrt(squaredDistance);
41 metaballDistances[x - 1] = squaredDistance;
41 metaballDistances[x - 1] = squaredDistance;
42 metaballDirections[x - 1] = vector / realDistance;
42 metaballDirections[x - 1] = vector / realDistance;
@@ -45,11 +45,11 @@ kernel void
45
45
46 float bendClose = 0.0;
46 float bendClose = 0.0;
47 float bendCloseCount = 0.0;
47 float bendCloseCount = 0.0;
48− float red = 0.0;
48+ float ball = 0.0;
49
49
50 for (x = 0; x < numberOfMetaballs; x += 1) {
50 for (x = 0; x < numberOfMetaballs; x += 1) {
51 float distance1 = metaballDistances[x];
51 float distance1 = metaballDistances[x];
52− float value1 = 2048 / (distance1 + 1);
52+ float value1 = 1500 / distance1;
53 float2 direction1 = metaballDirections[x];
53 float2 direction1 = metaballDirections[x];
54
54
55 float colorContribution = 1 / distance1;
55 float colorContribution = 1 / distance1;
@@ -58,7 +58,7 @@ kernel void
58
58
59 for (y = x + 1; y < numberOfMetaballs; y += 1) {
59 for (y = x + 1; y < numberOfMetaballs; y += 1) {
60 float distance2 = metaballDistances[y];
60 float distance2 = metaballDistances[y];
61− float value2 = 2048 / (distance2 + 1);
61+ float value2 = 1500 / distance2;
62 float2 direction2 = metaballDirections[y];
62 float2 direction2 = metaballDirections[y];
63
63
64 float v = value1 + value2;
64 float v = value1 + value2;
@@ -72,28 +72,27 @@ kernel void
72
72
73 float result = weightedValue + weightedLink;
73 float result = weightedValue + weightedLink;
74
74
75− if (result > 0.4 && result < 0.6) {
75+ ball += step(0.4, weightedValue);
76− bendClose += result;
77− bendCloseCount += 1.0;
78− }
79
76
80− red += step(0.4, weightedValue);
77+ float metaballValue = step(0.5, weightedValue + weightedLink);
81
78
82− if (weightedLink > greatestLinkWeight) {
79+ if (metaballValue > 0.0) {
83− greatestLinkWeight = weightedLink;
84 colorSumLink = float3(0.0, 0.0, 0.0);
80 colorSumLink = float3(0.0, 0.0, 0.0);
85 colorSumLink += metaballColors[x] / distance1;
81 colorSumLink += metaballColors[x] / distance1;
86 colorSumLink += metaballColors[y] / distance2;
82 colorSumLink += metaballColors[y] / distance2;
87 colorSumLink /= (1 / distance1) + (1 / distance2);
83 colorSumLink /= (1 / distance1) + (1 / distance2);
88 }
84 }
89
85
90− float metaballValue = step(0.5, weightedValue + weightedLink);
86+ if (result > 0.4) {
87+ bendClose += result;
88+ bendCloseCount += 1.0;
89+ }
91
90
92 sum += metaballValue;
91 sum += metaballValue;
93 }
92 }
94 }
93 }
95
94
96− bendClose = bendClose / bendCloseCount;
95+ // bendClose = bendClose / bendCloseCount;
97
96
98 if (bendClose != 0.0) {
97 if (bendClose != 0.0) {
99 bendClose = (bendClose - 0.4) * (1 / (0.6 - 0.4));
98 bendClose = (bendClose - 0.4) * (1 / (0.6 - 0.4));
@@ -101,17 +100,21 @@ kernel void
101 bendClose = 0.0;
100 bendClose = 0.0;
102 }
101 }
103
102
103+
104 float result = step(0.4, sum);
104 float result = step(0.4, sum);
105− result += bendClose * 10;
106 result = clamp(result, 0.0, 1.0);
105 result = clamp(result, 0.0, 1.0);
107
106
108 colorSum = colorSum / colorAccumulation;
107 colorSum = colorSum / colorAccumulation;
109
108
110− if (result > 0.0 && red < 1.0) {
109+ if (result > 0.0 && ball < 1.0) {
111 colorSum = colorSumLink;
110 colorSum = colorSumLink;
112 }
111 }
113
112
114 colorSum *= result;
113 colorSum *= result;
115
114
115+ if (colorSum.r == 0 && colorSum.g == 0 && colorSum.b == 0) {
116+ colorSum = float3(1, 1, 1);
117+ }
118+
116 outTexture.write(float4(colorSum.bgr, 1), gid);
119 outTexture.write(float4(colorSum.bgr, 1), gid);
117}
120}
Podfile+1−1
@@ -2,5 +2,5 @@ platform :ios, '9.2'
2use_frameworks!
2use_frameworks!
3
3
4target 'PixelImage' do
4target 'PixelImage' do
5− pod 'ChameleonFramework/Swift'
5+ pod 'ChameleonFramework/Swift', :git => 'https://github.com/ViccAlexander/Chameleon.git'
6end
6end
Podfile.lock+13−2
@@ -4,9 +4,20 @@ PODS:
4 - ChameleonFramework/Default
4 - ChameleonFramework/Default
5
5
6DEPENDENCIES:
6DEPENDENCIES:
7− - ChameleonFramework/Swift
7+ - ChameleonFramework/Swift (from `https://github.com/ViccAlexander/Chameleon.git`)
8+
9+EXTERNAL SOURCES:
10+ ChameleonFramework:
11+ :git: https://github.com/ViccAlexander/Chameleon.git
12+
13+CHECKOUT OPTIONS:
14+ ChameleonFramework:
15+ :commit: 6dd284bde21ea2e7f9fd89bc36f40df16e16369d
16+ :git: https://github.com/ViccAlexander/Chameleon.git
8
17
9SPEC CHECKSUMS:
18SPEC CHECKSUMS:
10 ChameleonFramework: d21a3cc247abfe5e37609a283a8238b03575cf64
19 ChameleonFramework: d21a3cc247abfe5e37609a283a8238b03575cf64
11
20
21+PODFILE CHECKSUM: 01ad8f20bdbed983c319dde08426f855f26bc5a0
22+
12−COCOAPODS: 0.39.0
23+COCOAPODS: 1.5.2
README.md+19−2
@@ -1,2 +1,19 @@
1−# metal-metaballs
1+![Example Animation](https://raw.githubusercontent.com/vinivendra/metal-metaballs/master/Examples/Animation.gif)
2−A 'playground' project for rendering metaball-like graphics in metal.
2+
3+# Metal Metaballs
4+
5+Metal Metaballs is a framework for rendering graphs in an aesthetically pleasing way. It uses an adapted version of [metaball](https://en.wikipedia.org/wiki/Metaballs) math to create fluid graphics, allow vertices to merge with each other and allow edges to flow and animate smoothly.
6+
7+Vertices and edges may be added and removed at will and can interact with gestures. Rendering a fullscreen view continuously uses only about 19% of the CPU at 60 fps, though normally the view will only be updated when needed. All rendering is done in a background thread, so the main thread remains almost completely free. These measurements were done using an iPhone 6S Plus (which has more pixels to calculate but more power to do so), so YMMV.
8+
9+This framework is being developed to make me learn several different design patters, APIs and features used in iOS and in graphics applications. So far, it uses:
10+
11+- [**Metaball**](https://en.wikipedia.org/wiki/Metaballs) math, in an adapted version, to render the graphics.
12+- [**Metal**](https://developer.apple.com/metal/) compute shaders to draw the metaballs dynamically.
13+- [**Grand Central Dispatch**](https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/) for doing CPU and GPU calculations simultaneously.
14+- [**Double buffering**](https://en.wikipedia.org/wiki/Multiple_buffering), to speed up rendering times.
15+- Different [**interpolations**](http://flexmonkey.blogspot.ca/2016/01/playing-with-interpolation-functions-in.html) for animations.
16+
17+## Installation
18+
19+Just download the app and run it on your metal-enabled device of choice :)