git.iko.soy/metal-metaballs
on master help sign in
Merge pull request #1 from vinivendra/dev

Added initial files.

commit7c82db8d66974b36a3a334442e2eff4db5640c93 authorVinicius Vendramini <vinivendra@gmail.com> dateWed 10 Feb 2016, 11:47 (11 years ago) parentce89442ae06ca5
47 files changed+3968
.gitignore+1 PixelImage.xcodeproj/project.pbxproj+471 PixelImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata+7 PixelImage.xcodeproj/project.xcworkspace/xcuserdata/vini.xcuserdatad/UserInterfaceState.xcuserstate PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist+23 PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcschemes/PixelImage.xcscheme+91 PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcschemes/xcschememanagement.plist+22 PixelImage/AppDelegate.swift+46 PixelImage/Assets.xcassets/AppIcon.appiconset/Contents.json+68 PixelImage/Base.lproj/LaunchScreen.storyboard+27 PixelImage/Base.lproj/Main.storyboard+26 PixelImage/ImageMetaballRenderer.swift+101 PixelImage/Info.plist+47 PixelImage/MetaballRenderer.swift+18 PixelImage/Metal.swift+13 PixelImage/MetalMetaballRenderer.swift+126 PixelImage/SwiftSugar/ApproximationOperator.swift+12 PixelImage/SwiftSugar/Collections.swift+6 PixelImage/SwiftSugar/ComparatorChains.swift+57 PixelImage/SwiftSugar/Dictionary.swift+12 PixelImage/SwiftSugar/Foundation/NSNumber.swift+11 PixelImage/SwiftSugar/Numeric.swift+62 PixelImage/SwiftSugar/PowerOperator.swift+15 PixelImage/SwiftSugar/Sequence.swift+16 PixelImage/SwiftSugar/Sequences/Memoize.swift+162 PixelImage/SwiftSugar/SignOperator.swift+13 PixelImage/SwiftSugar/String.swift+9 PixelImage/SwiftSugar/SwiftSequences/Categorise.swift+211 PixelImage/SwiftSugar/SwiftSequences/ChunkWindowSplit.swift+146 PixelImage/SwiftSugar/SwiftSequences/Combinations.swift+114 PixelImage/SwiftSugar/SwiftSequences/Cycle.swift+86 PixelImage/SwiftSugar/SwiftSequences/Enumerate.swift+33 PixelImage/SwiftSugar/SwiftSequences/Finding.swift+80 PixelImage/SwiftSugar/SwiftSequences/FlatMap.swift+23 PixelImage/SwiftSugar/SwiftSequences/Hopping.swift+78 PixelImage/SwiftSugar/SwiftSequences/Interpose.swift+366 PixelImage/SwiftSugar/SwiftSequences/Iterate.swift+34 PixelImage/SwiftSugar/SwiftSequences/NestedSequences.swift+229 PixelImage/SwiftSugar/SwiftSequences/Permutations.swift+187 PixelImage/SwiftSugar/SwiftSequences/ScanReduce.swift+152 PixelImage/SwiftSugar/SwiftSequences/Slicing.swift+138 PixelImage/SwiftSugar/SwiftSequences/TakeDrop.swift+208 PixelImage/SwiftSugar/SwiftSequences/Zip.swift+90 PixelImage/SwiftSugar/TestCommons.swift+95 PixelImage/UIKit.swift+104 PixelImage/ViewController.swift+81 PixelImage/shaders.metal+51
.gitignorenew file+1
@@ -0,0 +1 @@
1+.DS*
PixelImage.xcodeproj/project.pbxprojnew file+471
@@ -0,0 +1,471 @@
1+// !$*UTF8*$!
2+{
3+ archiveVersion = 1;
4+ classes = {
5+ };
6+ objectVersion = 46;
7+ objects = {
8+
9+/* Begin PBXBuildFile section */
10+ 242686881C63B72A00D62456 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242686871C63B72A00D62456 /* AppDelegate.swift */; };
11+ 2426868A1C63B72A00D62456 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242686891C63B72A00D62456 /* ViewController.swift */; };
12+ 2426868D1C63B72A00D62456 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2426868B1C63B72A00D62456 /* Main.storyboard */; };
13+ 2426868F1C63B72A00D62456 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2426868E1C63B72A00D62456 /* Assets.xcassets */; };
14+ 242686921C63B72A00D62456 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 242686901C63B72A00D62456 /* LaunchScreen.storyboard */; };
15+ 24E1E7D71C67C8B200ECF1C4 /* UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7D61C67C8B200ECF1C4 /* UIKit.swift */; };
16+ 24E1E7D91C67C9C900ECF1C4 /* MetaballRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7D81C67C9C900ECF1C4 /* MetaballRenderer.swift */; };
17+ 24E1E7DB1C67CA3600ECF1C4 /* ImageMetaballRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7DA1C67CA3600ECF1C4 /* ImageMetaballRenderer.swift */; };
18+ 24E1E7E21C67D37F00ECF1C4 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24E1E7E11C67D37F00ECF1C4 /* Metal.framework */; };
19+ 24E1E7E41C67D39300ECF1C4 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24E1E7E31C67D39300ECF1C4 /* MetalKit.framework */; };
20+ 24E1E7EB1C67D70300ECF1C4 /* MetalMetaballRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EA1C67D70300ECF1C4 /* MetalMetaballRenderer.swift */; };
21+ 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */; };
22+ 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */; };
23+ 24FFA86B1C6BA038005ACD60 /* ApproximationOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */; };
24+ 24FFA86C1C6BA038005ACD60 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84D1C6BA038005ACD60 /* Collections.swift */; };
25+ 24FFA86D1C6BA038005ACD60 /* ComparatorChains.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */; };
26+ 24FFA86E1C6BA038005ACD60 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */; };
27+ 24FFA86F1C6BA038005ACD60 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8511C6BA038005ACD60 /* NSNumber.swift */; };
28+ 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8521C6BA038005ACD60 /* Numeric.swift */; };
29+ 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */; };
30+ 24FFA8721C6BA038005ACD60 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8541C6BA038005ACD60 /* Sequence.swift */; };
31+ 24FFA8731C6BA038005ACD60 /* Memoize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8561C6BA038005ACD60 /* Memoize.swift */; };
32+ 24FFA8741C6BA038005ACD60 /* SignOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8571C6BA038005ACD60 /* SignOperator.swift */; };
33+ 24FFA8751C6BA038005ACD60 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8581C6BA038005ACD60 /* String.swift */; };
34+ 24FFA8761C6BA038005ACD60 /* Categorise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85A1C6BA038005ACD60 /* Categorise.swift */; };
35+ 24FFA8771C6BA038005ACD60 /* ChunkWindowSplit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */; };
36+ 24FFA8781C6BA038005ACD60 /* Combinations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85C1C6BA038005ACD60 /* Combinations.swift */; };
37+ 24FFA8791C6BA038005ACD60 /* Cycle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85D1C6BA038005ACD60 /* Cycle.swift */; };
38+ 24FFA87A1C6BA038005ACD60 /* Enumerate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */; };
39+ 24FFA87B1C6BA038005ACD60 /* Finding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA85F1C6BA038005ACD60 /* Finding.swift */; };
40+ 24FFA87C1C6BA038005ACD60 /* FlatMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8601C6BA038005ACD60 /* FlatMap.swift */; };
41+ 24FFA87D1C6BA038005ACD60 /* Hopping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8611C6BA038005ACD60 /* Hopping.swift */; };
42+ 24FFA87E1C6BA038005ACD60 /* Interpose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8621C6BA038005ACD60 /* Interpose.swift */; };
43+ 24FFA87F1C6BA038005ACD60 /* Iterate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8631C6BA038005ACD60 /* Iterate.swift */; };
44+ 24FFA8801C6BA038005ACD60 /* NestedSequences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */; };
45+ 24FFA8811C6BA038005ACD60 /* Permutations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8651C6BA038005ACD60 /* Permutations.swift */; };
46+ 24FFA8821C6BA038005ACD60 /* ScanReduce.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */; };
47+ 24FFA8831C6BA038005ACD60 /* Slicing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8671C6BA038005ACD60 /* Slicing.swift */; };
48+ 24FFA8841C6BA038005ACD60 /* TakeDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */; };
49+ 24FFA8851C6BA038005ACD60 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA8691C6BA038005ACD60 /* Zip.swift */; };
50+ 24FFA8861C6BA038005ACD60 /* TestCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */; };
51+/* End PBXBuildFile section */
52+
53+/* Begin PBXFileReference section */
54+ 242686841C63B72A00D62456 /* PixelImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PixelImage.app; sourceTree = BUILT_PRODUCTS_DIR; };
55+ 242686871C63B72A00D62456 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
56+ 242686891C63B72A00D62456 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
57+ 2426868C1C63B72A00D62456 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
58+ 2426868E1C63B72A00D62456 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
59+ 242686911C63B72A00D62456 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
60+ 242686931C63B72A00D62456 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
61+ 24E1E7D61C67C8B200ECF1C4 /* UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKit.swift; sourceTree = "<group>"; };
62+ 24E1E7D81C67C9C900ECF1C4 /* MetaballRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaballRenderer.swift; sourceTree = "<group>"; };
63+ 24E1E7DA1C67CA3600ECF1C4 /* ImageMetaballRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageMetaballRenderer.swift; sourceTree = "<group>"; };
64+ 24E1E7E11C67D37F00ECF1C4 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
65+ 24E1E7E31C67D39300ECF1C4 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; };
66+ 24E1E7EA1C67D70300ECF1C4 /* MetalMetaballRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalMetaballRenderer.swift; sourceTree = "<group>"; };
67+ 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Metal.swift; sourceTree = "<group>"; };
68+ 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = shaders.metal; sourceTree = "<group>"; };
69+ 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApproximationOperator.swift; sourceTree = "<group>"; };
70+ 24FFA84D1C6BA038005ACD60 /* Collections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Collections.swift; sourceTree = "<group>"; };
71+ 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparatorChains.swift; sourceTree = "<group>"; };
72+ 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
73+ 24FFA8511C6BA038005ACD60 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = "<group>"; };
74+ 24FFA8521C6BA038005ACD60 /* Numeric.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Numeric.swift; sourceTree = "<group>"; };
75+ 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PowerOperator.swift; sourceTree = "<group>"; };
76+ 24FFA8541C6BA038005ACD60 /* Sequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = "<group>"; };
77+ 24FFA8561C6BA038005ACD60 /* Memoize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Memoize.swift; sourceTree = "<group>"; };
78+ 24FFA8571C6BA038005ACD60 /* SignOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignOperator.swift; sourceTree = "<group>"; };
79+ 24FFA8581C6BA038005ACD60 /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
80+ 24FFA85A1C6BA038005ACD60 /* Categorise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Categorise.swift; sourceTree = "<group>"; };
81+ 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChunkWindowSplit.swift; sourceTree = "<group>"; };
82+ 24FFA85C1C6BA038005ACD60 /* Combinations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinations.swift; sourceTree = "<group>"; };
83+ 24FFA85D1C6BA038005ACD60 /* Cycle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cycle.swift; sourceTree = "<group>"; };
84+ 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enumerate.swift; sourceTree = "<group>"; };
85+ 24FFA85F1C6BA038005ACD60 /* Finding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Finding.swift; sourceTree = "<group>"; };
86+ 24FFA8601C6BA038005ACD60 /* FlatMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlatMap.swift; sourceTree = "<group>"; };
87+ 24FFA8611C6BA038005ACD60 /* Hopping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hopping.swift; sourceTree = "<group>"; };
88+ 24FFA8621C6BA038005ACD60 /* Interpose.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Interpose.swift; sourceTree = "<group>"; };
89+ 24FFA8631C6BA038005ACD60 /* Iterate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Iterate.swift; sourceTree = "<group>"; };
90+ 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedSequences.swift; sourceTree = "<group>"; };
91+ 24FFA8651C6BA038005ACD60 /* Permutations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Permutations.swift; sourceTree = "<group>"; };
92+ 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanReduce.swift; sourceTree = "<group>"; };
93+ 24FFA8671C6BA038005ACD60 /* Slicing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Slicing.swift; sourceTree = "<group>"; };
94+ 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TakeDrop.swift; sourceTree = "<group>"; };
95+ 24FFA8691C6BA038005ACD60 /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
96+ 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCommons.swift; sourceTree = "<group>"; };
97+/* End PBXFileReference section */
98+
99+/* Begin PBXFrameworksBuildPhase section */
100+ 242686811C63B72A00D62456 /* Frameworks */ = {
101+ isa = PBXFrameworksBuildPhase;
102+ buildActionMask = 2147483647;
103+ files = (
104+ 24E1E7E41C67D39300ECF1C4 /* MetalKit.framework in Frameworks */,
105+ 24E1E7E21C67D37F00ECF1C4 /* Metal.framework in Frameworks */,
106+ );
107+ runOnlyForDeploymentPostprocessing = 0;
108+ };
109+/* End PBXFrameworksBuildPhase section */
110+
111+/* Begin PBXGroup section */
112+ 2426867B1C63B72A00D62456 = {
113+ isa = PBXGroup;
114+ children = (
115+ 24E1E7E31C67D39300ECF1C4 /* MetalKit.framework */,
116+ 24E1E7E11C67D37F00ECF1C4 /* Metal.framework */,
117+ 242686861C63B72A00D62456 /* PixelImage */,
118+ 242686851C63B72A00D62456 /* Products */,
119+ );
120+ sourceTree = "<group>";
121+ };
122+ 242686851C63B72A00D62456 /* Products */ = {
123+ isa = PBXGroup;
124+ children = (
125+ 242686841C63B72A00D62456 /* PixelImage.app */,
126+ );
127+ name = Products;
128+ sourceTree = "<group>";
129+ };
130+ 242686861C63B72A00D62456 /* PixelImage */ = {
131+ isa = PBXGroup;
132+ children = (
133+ 24FFA84B1C6BA038005ACD60 /* SwiftSugar */,
134+ 242686871C63B72A00D62456 /* AppDelegate.swift */,
135+ 242686891C63B72A00D62456 /* ViewController.swift */,
136+ 24E1E7D61C67C8B200ECF1C4 /* UIKit.swift */,
137+ 24E1E7D81C67C9C900ECF1C4 /* MetaballRenderer.swift */,
138+ 24E1E7DA1C67CA3600ECF1C4 /* ImageMetaballRenderer.swift */,
139+ 24E1E7EA1C67D70300ECF1C4 /* MetalMetaballRenderer.swift */,
140+ 24E1E7EE1C67D74300ECF1C4 /* Metal.swift */,
141+ 24E1E7EF1C67D74300ECF1C4 /* shaders.metal */,
142+ 2426868B1C63B72A00D62456 /* Main.storyboard */,
143+ 2426868E1C63B72A00D62456 /* Assets.xcassets */,
144+ 242686901C63B72A00D62456 /* LaunchScreen.storyboard */,
145+ 242686931C63B72A00D62456 /* Info.plist */,
146+ );
147+ path = PixelImage;
148+ sourceTree = "<group>";
149+ };
150+ 24FFA84B1C6BA038005ACD60 /* SwiftSugar */ = {
151+ isa = PBXGroup;
152+ children = (
153+ 24FFA84C1C6BA038005ACD60 /* ApproximationOperator.swift */,
154+ 24FFA84D1C6BA038005ACD60 /* Collections.swift */,
155+ 24FFA84E1C6BA038005ACD60 /* ComparatorChains.swift */,
156+ 24FFA84F1C6BA038005ACD60 /* Dictionary.swift */,
157+ 24FFA8501C6BA038005ACD60 /* Foundation */,
158+ 24FFA8521C6BA038005ACD60 /* Numeric.swift */,
159+ 24FFA8531C6BA038005ACD60 /* PowerOperator.swift */,
160+ 24FFA8541C6BA038005ACD60 /* Sequence.swift */,
161+ 24FFA8551C6BA038005ACD60 /* Sequences */,
162+ 24FFA8571C6BA038005ACD60 /* SignOperator.swift */,
163+ 24FFA8581C6BA038005ACD60 /* String.swift */,
164+ 24FFA8591C6BA038005ACD60 /* SwiftSequences */,
165+ 24FFA86A1C6BA038005ACD60 /* TestCommons.swift */,
166+ );
167+ path = SwiftSugar;
168+ sourceTree = "<group>";
169+ };
170+ 24FFA8501C6BA038005ACD60 /* Foundation */ = {
171+ isa = PBXGroup;
172+ children = (
173+ 24FFA8511C6BA038005ACD60 /* NSNumber.swift */,
174+ );
175+ path = Foundation;
176+ sourceTree = "<group>";
177+ };
178+ 24FFA8551C6BA038005ACD60 /* Sequences */ = {
179+ isa = PBXGroup;
180+ children = (
181+ 24FFA8561C6BA038005ACD60 /* Memoize.swift */,
182+ );
183+ path = Sequences;
184+ sourceTree = "<group>";
185+ };
186+ 24FFA8591C6BA038005ACD60 /* SwiftSequences */ = {
187+ isa = PBXGroup;
188+ children = (
189+ 24FFA85A1C6BA038005ACD60 /* Categorise.swift */,
190+ 24FFA85B1C6BA038005ACD60 /* ChunkWindowSplit.swift */,
191+ 24FFA85C1C6BA038005ACD60 /* Combinations.swift */,
192+ 24FFA85D1C6BA038005ACD60 /* Cycle.swift */,
193+ 24FFA85E1C6BA038005ACD60 /* Enumerate.swift */,
194+ 24FFA85F1C6BA038005ACD60 /* Finding.swift */,
195+ 24FFA8601C6BA038005ACD60 /* FlatMap.swift */,
196+ 24FFA8611C6BA038005ACD60 /* Hopping.swift */,
197+ 24FFA8621C6BA038005ACD60 /* Interpose.swift */,
198+ 24FFA8631C6BA038005ACD60 /* Iterate.swift */,
199+ 24FFA8641C6BA038005ACD60 /* NestedSequences.swift */,
200+ 24FFA8651C6BA038005ACD60 /* Permutations.swift */,
201+ 24FFA8661C6BA038005ACD60 /* ScanReduce.swift */,
202+ 24FFA8671C6BA038005ACD60 /* Slicing.swift */,
203+ 24FFA8681C6BA038005ACD60 /* TakeDrop.swift */,
204+ 24FFA8691C6BA038005ACD60 /* Zip.swift */,
205+ );
206+ path = SwiftSequences;
207+ sourceTree = "<group>";
208+ };
209+/* End PBXGroup section */
210+
211+/* Begin PBXNativeTarget section */
212+ 242686831C63B72A00D62456 /* PixelImage */ = {
213+ isa = PBXNativeTarget;
214+ buildConfigurationList = 242686961C63B72A00D62456 /* Build configuration list for PBXNativeTarget "PixelImage" */;
215+ buildPhases = (
216+ 242686801C63B72A00D62456 /* Sources */,
217+ 242686811C63B72A00D62456 /* Frameworks */,
218+ 242686821C63B72A00D62456 /* Resources */,
219+ );
220+ buildRules = (
221+ );
222+ dependencies = (
223+ );
224+ name = PixelImage;
225+ productName = PixelImage;
226+ productReference = 242686841C63B72A00D62456 /* PixelImage.app */;
227+ productType = "com.apple.product-type.application";
228+ };
229+/* End PBXNativeTarget section */
230+
231+/* Begin PBXProject section */
232+ 2426867C1C63B72A00D62456 /* Project object */ = {
233+ isa = PBXProject;
234+ attributes = {
235+ LastSwiftUpdateCheck = 0720;
236+ LastUpgradeCheck = 0720;
237+ ORGANIZATIONNAME = "Vinicius Vendramini";
238+ TargetAttributes = {
239+ 242686831C63B72A00D62456 = {
240+ CreatedOnToolsVersion = 7.2;
241+ DevelopmentTeam = HHT774898M;
242+ };
243+ };
244+ };
245+ buildConfigurationList = 2426867F1C63B72A00D62456 /* Build configuration list for PBXProject "PixelImage" */;
246+ compatibilityVersion = "Xcode 3.2";
247+ developmentRegion = English;
248+ hasScannedForEncodings = 0;
249+ knownRegions = (
250+ en,
251+ Base,
252+ );
253+ mainGroup = 2426867B1C63B72A00D62456;
254+ productRefGroup = 242686851C63B72A00D62456 /* Products */;
255+ projectDirPath = "";
256+ projectRoot = "";
257+ targets = (
258+ 242686831C63B72A00D62456 /* PixelImage */,
259+ );
260+ };
261+/* End PBXProject section */
262+
263+/* Begin PBXResourcesBuildPhase section */
264+ 242686821C63B72A00D62456 /* Resources */ = {
265+ isa = PBXResourcesBuildPhase;
266+ buildActionMask = 2147483647;
267+ files = (
268+ 242686921C63B72A00D62456 /* LaunchScreen.storyboard in Resources */,
269+ 2426868F1C63B72A00D62456 /* Assets.xcassets in Resources */,
270+ 2426868D1C63B72A00D62456 /* Main.storyboard in Resources */,
271+ );
272+ runOnlyForDeploymentPostprocessing = 0;
273+ };
274+/* End PBXResourcesBuildPhase section */
275+
276+/* Begin PBXSourcesBuildPhase section */
277+ 242686801C63B72A00D62456 /* Sources */ = {
278+ isa = PBXSourcesBuildPhase;
279+ buildActionMask = 2147483647;
280+ files = (
281+ 24FFA87B1C6BA038005ACD60 /* Finding.swift in Sources */,
282+ 24FFA8751C6BA038005ACD60 /* String.swift in Sources */,
283+ 24FFA8781C6BA038005ACD60 /* Combinations.swift in Sources */,
284+ 24FFA87E1C6BA038005ACD60 /* Interpose.swift in Sources */,
285+ 2426868A1C63B72A00D62456 /* ViewController.swift in Sources */,
286+ 24FFA8841C6BA038005ACD60 /* TakeDrop.swift in Sources */,
287+ 24FFA8771C6BA038005ACD60 /* ChunkWindowSplit.swift in Sources */,
288+ 24FFA86F1C6BA038005ACD60 /* NSNumber.swift in Sources */,
289+ 24FFA8861C6BA038005ACD60 /* TestCommons.swift in Sources */,
290+ 24FFA8741C6BA038005ACD60 /* SignOperator.swift in Sources */,
291+ 24FFA8821C6BA038005ACD60 /* ScanReduce.swift in Sources */,
292+ 24FFA8831C6BA038005ACD60 /* Slicing.swift in Sources */,
293+ 24FFA8721C6BA038005ACD60 /* Sequence.swift in Sources */,
294+ 24FFA87F1C6BA038005ACD60 /* Iterate.swift in Sources */,
295+ 24FFA8761C6BA038005ACD60 /* Categorise.swift in Sources */,
296+ 24FFA86D1C6BA038005ACD60 /* ComparatorChains.swift in Sources */,
297+ 24FFA8711C6BA038005ACD60 /* PowerOperator.swift in Sources */,
298+ 24E1E7D91C67C9C900ECF1C4 /* MetaballRenderer.swift in Sources */,
299+ 24E1E7D71C67C8B200ECF1C4 /* UIKit.swift in Sources */,
300+ 24FFA8851C6BA038005ACD60 /* Zip.swift in Sources */,
301+ 24FFA8791C6BA038005ACD60 /* Cycle.swift in Sources */,
302+ 24E1E7F11C67D74300ECF1C4 /* shaders.metal in Sources */,
303+ 24FFA86E1C6BA038005ACD60 /* Dictionary.swift in Sources */,
304+ 24FFA87D1C6BA038005ACD60 /* Hopping.swift in Sources */,
305+ 24E1E7EB1C67D70300ECF1C4 /* MetalMetaballRenderer.swift in Sources */,
306+ 24FFA87A1C6BA038005ACD60 /* Enumerate.swift in Sources */,
307+ 24E1E7DB1C67CA3600ECF1C4 /* ImageMetaballRenderer.swift in Sources */,
308+ 242686881C63B72A00D62456 /* AppDelegate.swift in Sources */,
309+ 24E1E7F01C67D74300ECF1C4 /* Metal.swift in Sources */,
310+ 24FFA87C1C6BA038005ACD60 /* FlatMap.swift in Sources */,
311+ 24FFA8701C6BA038005ACD60 /* Numeric.swift in Sources */,
312+ 24FFA8811C6BA038005ACD60 /* Permutations.swift in Sources */,
313+ 24FFA86B1C6BA038005ACD60 /* ApproximationOperator.swift in Sources */,
314+ 24FFA8801C6BA038005ACD60 /* NestedSequences.swift in Sources */,
315+ 24FFA8731C6BA038005ACD60 /* Memoize.swift in Sources */,
316+ 24FFA86C1C6BA038005ACD60 /* Collections.swift in Sources */,
317+ );
318+ runOnlyForDeploymentPostprocessing = 0;
319+ };
320+/* End PBXSourcesBuildPhase section */
321+
322+/* Begin PBXVariantGroup section */
323+ 2426868B1C63B72A00D62456 /* Main.storyboard */ = {
324+ isa = PBXVariantGroup;
325+ children = (
326+ 2426868C1C63B72A00D62456 /* Base */,
327+ );
328+ name = Main.storyboard;
329+ sourceTree = "<group>";
330+ };
331+ 242686901C63B72A00D62456 /* LaunchScreen.storyboard */ = {
332+ isa = PBXVariantGroup;
333+ children = (
334+ 242686911C63B72A00D62456 /* Base */,
335+ );
336+ name = LaunchScreen.storyboard;
337+ sourceTree = "<group>";
338+ };
339+/* End PBXVariantGroup section */
340+
341+/* Begin XCBuildConfiguration section */
342+ 242686941C63B72A00D62456 /* Debug */ = {
343+ isa = XCBuildConfiguration;
344+ buildSettings = {
345+ ALWAYS_SEARCH_USER_PATHS = NO;
346+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
347+ CLANG_CXX_LIBRARY = "libc++";
348+ CLANG_ENABLE_MODULES = YES;
349+ CLANG_ENABLE_OBJC_ARC = YES;
350+ CLANG_WARN_BOOL_CONVERSION = YES;
351+ CLANG_WARN_CONSTANT_CONVERSION = YES;
352+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
353+ CLANG_WARN_EMPTY_BODY = YES;
354+ CLANG_WARN_ENUM_CONVERSION = YES;
355+ CLANG_WARN_INT_CONVERSION = YES;
356+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
357+ CLANG_WARN_UNREACHABLE_CODE = YES;
358+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
359+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
360+ COPY_PHASE_STRIP = NO;
361+ DEBUG_INFORMATION_FORMAT = dwarf;
362+ ENABLE_STRICT_OBJC_MSGSEND = YES;
363+ ENABLE_TESTABILITY = YES;
364+ GCC_C_LANGUAGE_STANDARD = gnu99;
365+ GCC_DYNAMIC_NO_PIC = NO;
366+ GCC_NO_COMMON_BLOCKS = YES;
367+ GCC_OPTIMIZATION_LEVEL = 0;
368+ GCC_PREPROCESSOR_DEFINITIONS = (
369+ "DEBUG=1",
370+ "$(inherited)",
371+ );
372+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
373+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
374+ GCC_WARN_UNDECLARED_SELECTOR = YES;
375+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
376+ GCC_WARN_UNUSED_FUNCTION = YES;
377+ GCC_WARN_UNUSED_VARIABLE = YES;
378+ IPHONEOS_DEPLOYMENT_TARGET = 9.2;
379+ MTL_ENABLE_DEBUG_INFO = YES;
380+ ONLY_ACTIVE_ARCH = YES;
381+ SDKROOT = iphoneos;
382+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
383+ TARGETED_DEVICE_FAMILY = "1,2";
384+ };
385+ name = Debug;
386+ };
387+ 242686951C63B72A00D62456 /* Release */ = {
388+ isa = XCBuildConfiguration;
389+ buildSettings = {
390+ ALWAYS_SEARCH_USER_PATHS = NO;
391+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
392+ CLANG_CXX_LIBRARY = "libc++";
393+ CLANG_ENABLE_MODULES = YES;
394+ CLANG_ENABLE_OBJC_ARC = YES;
395+ CLANG_WARN_BOOL_CONVERSION = YES;
396+ CLANG_WARN_CONSTANT_CONVERSION = YES;
397+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
398+ CLANG_WARN_EMPTY_BODY = YES;
399+ CLANG_WARN_ENUM_CONVERSION = YES;
400+ CLANG_WARN_INT_CONVERSION = YES;
401+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
402+ CLANG_WARN_UNREACHABLE_CODE = YES;
403+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
404+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
405+ COPY_PHASE_STRIP = NO;
406+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
407+ ENABLE_NS_ASSERTIONS = NO;
408+ ENABLE_STRICT_OBJC_MSGSEND = YES;
409+ GCC_C_LANGUAGE_STANDARD = gnu99;
410+ GCC_NO_COMMON_BLOCKS = YES;
411+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
412+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
413+ GCC_WARN_UNDECLARED_SELECTOR = YES;
414+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
415+ GCC_WARN_UNUSED_FUNCTION = YES;
416+ GCC_WARN_UNUSED_VARIABLE = YES;
417+ IPHONEOS_DEPLOYMENT_TARGET = 9.2;
418+ MTL_ENABLE_DEBUG_INFO = NO;
419+ SDKROOT = iphoneos;
420+ TARGETED_DEVICE_FAMILY = "1,2";
421+ VALIDATE_PRODUCT = YES;
422+ };
423+ name = Release;
424+ };
425+ 242686971C63B72A00D62456 /* Debug */ = {
426+ isa = XCBuildConfiguration;
427+ buildSettings = {
428+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
429+ INFOPLIST_FILE = PixelImage/Info.plist;
430+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
431+ PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
432+ PRODUCT_NAME = "$(TARGET_NAME)";
433+ };
434+ name = Debug;
435+ };
436+ 242686981C63B72A00D62456 /* Release */ = {
437+ isa = XCBuildConfiguration;
438+ buildSettings = {
439+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
440+ INFOPLIST_FILE = PixelImage/Info.plist;
441+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
442+ PRODUCT_BUNDLE_IDENTIFIER = vinivendra.PixelImage;
443+ PRODUCT_NAME = "$(TARGET_NAME)";
444+ };
445+ name = Release;
446+ };
447+/* End XCBuildConfiguration section */
448+
449+/* Begin XCConfigurationList section */
450+ 2426867F1C63B72A00D62456 /* Build configuration list for PBXProject "PixelImage" */ = {
451+ isa = XCConfigurationList;
452+ buildConfigurations = (
453+ 242686941C63B72A00D62456 /* Debug */,
454+ 242686951C63B72A00D62456 /* Release */,
455+ );
456+ defaultConfigurationIsVisible = 0;
457+ defaultConfigurationName = Release;
458+ };
459+ 242686961C63B72A00D62456 /* Build configuration list for PBXNativeTarget "PixelImage" */ = {
460+ isa = XCConfigurationList;
461+ buildConfigurations = (
462+ 242686971C63B72A00D62456 /* Debug */,
463+ 242686981C63B72A00D62456 /* Release */,
464+ );
465+ defaultConfigurationIsVisible = 0;
466+ defaultConfigurationName = Release;
467+ };
468+/* End XCConfigurationList section */
469+ };
470+ rootObject = 2426867C1C63B72A00D62456 /* Project object */;
471+}
PixelImage.xcodeproj/project.xcworkspace/contents.xcworkspacedatanew file+7
@@ -0,0 +1,7 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<Workspace
3+ version = "1.0">
4+ <FileRef
5+ location = "self:PixelImage.xcodeproj">
6+ </FileRef>
7+</Workspace>
PixelImage.xcodeproj/project.xcworkspace/xcuserdata/vini.xcuserdatad/UserInterfaceState.xcuserstatenew file

Binary file not shown.

PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlistnew file+23
@@ -0,0 +1,23 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<Bucket
3+ type = "1"
4+ version = "2.0">
5+ <Breakpoints>
6+ <BreakpointProxy
7+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+ <BreakpointContent
9+ shouldBeEnabled = "Yes"
10+ ignoreCount = "0"
11+ continueAfterRunningActions = "No"
12+ filePath = "PixelImage/MetalMetaballRenderer.swift"
13+ timestampString = "476814708.217603"
14+ startingColumnNumber = "9223372036854775807"
15+ endingColumnNumber = "9223372036854775807"
16+ startingLineNumber = "62"
17+ endingLineNumber = "62"
18+ landmarkName = "updateTargetView(_:dataSource:)"
19+ landmarkType = "5">
20+ </BreakpointContent>
21+ </BreakpointProxy>
22+ </Breakpoints>
23+</Bucket>
PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcschemes/PixelImage.xcschemenew file+91
@@ -0,0 +1,91 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<Scheme
3+ LastUpgradeVersion = "0720"
4+ version = "1.3">
5+ <BuildAction
6+ parallelizeBuildables = "YES"
7+ buildImplicitDependencies = "YES">
8+ <BuildActionEntries>
9+ <BuildActionEntry
10+ buildForTesting = "YES"
11+ buildForRunning = "YES"
12+ buildForProfiling = "YES"
13+ buildForArchiving = "YES"
14+ buildForAnalyzing = "YES">
15+ <BuildableReference
16+ BuildableIdentifier = "primary"
17+ BlueprintIdentifier = "242686831C63B72A00D62456"
18+ BuildableName = "PixelImage.app"
19+ BlueprintName = "PixelImage"
20+ ReferencedContainer = "container:PixelImage.xcodeproj">
21+ </BuildableReference>
22+ </BuildActionEntry>
23+ </BuildActionEntries>
24+ </BuildAction>
25+ <TestAction
26+ buildConfiguration = "Debug"
27+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+ shouldUseLaunchSchemeArgsEnv = "YES">
30+ <Testables>
31+ </Testables>
32+ <MacroExpansion>
33+ <BuildableReference
34+ BuildableIdentifier = "primary"
35+ BlueprintIdentifier = "242686831C63B72A00D62456"
36+ BuildableName = "PixelImage.app"
37+ BlueprintName = "PixelImage"
38+ ReferencedContainer = "container:PixelImage.xcodeproj">
39+ </BuildableReference>
40+ </MacroExpansion>
41+ <AdditionalOptions>
42+ </AdditionalOptions>
43+ </TestAction>
44+ <LaunchAction
45+ buildConfiguration = "Debug"
46+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+ launchStyle = "0"
49+ useCustomWorkingDirectory = "NO"
50+ ignoresPersistentStateOnLaunch = "NO"
51+ debugDocumentVersioning = "YES"
52+ debugServiceExtension = "internal"
53+ allowLocationSimulation = "YES">
54+ <BuildableProductRunnable
55+ runnableDebuggingMode = "0">
56+ <BuildableReference
57+ BuildableIdentifier = "primary"
58+ BlueprintIdentifier = "242686831C63B72A00D62456"
59+ BuildableName = "PixelImage.app"
60+ BlueprintName = "PixelImage"
61+ ReferencedContainer = "container:PixelImage.xcodeproj">
62+ </BuildableReference>
63+ </BuildableProductRunnable>
64+ <AdditionalOptions>
65+ </AdditionalOptions>
66+ </LaunchAction>
67+ <ProfileAction
68+ buildConfiguration = "Release"
69+ shouldUseLaunchSchemeArgsEnv = "YES"
70+ savedToolIdentifier = ""
71+ useCustomWorkingDirectory = "NO"
72+ debugDocumentVersioning = "YES">
73+ <BuildableProductRunnable
74+ runnableDebuggingMode = "0">
75+ <BuildableReference
76+ BuildableIdentifier = "primary"
77+ BlueprintIdentifier = "242686831C63B72A00D62456"
78+ BuildableName = "PixelImage.app"
79+ BlueprintName = "PixelImage"
80+ ReferencedContainer = "container:PixelImage.xcodeproj">
81+ </BuildableReference>
82+ </BuildableProductRunnable>
83+ </ProfileAction>
84+ <AnalyzeAction
85+ buildConfiguration = "Debug">
86+ </AnalyzeAction>
87+ <ArchiveAction
88+ buildConfiguration = "Release"
89+ revealArchiveInOrganizer = "YES">
90+ </ArchiveAction>
91+</Scheme>
PixelImage.xcodeproj/xcuserdata/vini.xcuserdatad/xcschemes/xcschememanagement.plistnew file+22
@@ -0,0 +1,22 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+<plist version="1.0">
4+<dict>
5+ <key>SchemeUserState</key>
6+ <dict>
7+ <key>PixelImage.xcscheme</key>
8+ <dict>
9+ <key>orderHint</key>
10+ <integer>0</integer>
11+ </dict>
12+ </dict>
13+ <key>SuppressBuildableAutocreation</key>
14+ <dict>
15+ <key>242686831C63B72A00D62456</key>
16+ <dict>
17+ <key>primary</key>
18+ <true/>
19+ </dict>
20+ </dict>
21+</dict>
22+</plist>
PixelImage/AppDelegate.swiftnew file+46
@@ -0,0 +1,46 @@
1+//
2+// AppDelegate.swift
3+// PixelImage
4+//
5+// Created by Vinicius Vendramini on 2/4/16.
6+// Copyright © 2016 Vinicius Vendramini. All rights reserved.
7+//
8+
9+import UIKit
10+
11+@UIApplicationMain
12+class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+ var window: UIWindow?
15+
16+
17+ func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18+ // Override point for customization after application launch.
19+ return true
20+ }
21+
22+ func applicationWillResignActive(application: UIApplication) {
23+ // 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.
24+ // 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.
25+ }
26+
27+ func applicationDidEnterBackground(application: UIApplication) {
28+ // 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.
29+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30+ }
31+
32+ func applicationWillEnterForeground(application: UIApplication) {
33+ // 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.
34+ }
35+
36+ func applicationDidBecomeActive(application: UIApplication) {
37+ // 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.
38+ }
39+
40+ func applicationWillTerminate(application: UIApplication) {
41+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42+ }
43+
44+
45+}
46+
PixelImage/Assets.xcassets/AppIcon.appiconset/Contents.jsonnew file+68
@@ -0,0 +1,68 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "iphone",
5+ "size" : "29x29",
6+ "scale" : "2x"
7+ },
8+ {
9+ "idiom" : "iphone",
10+ "size" : "29x29",
11+ "scale" : "3x"
12+ },
13+ {
14+ "idiom" : "iphone",
15+ "size" : "40x40",
16+ "scale" : "2x"
17+ },
18+ {
19+ "idiom" : "iphone",
20+ "size" : "40x40",
21+ "scale" : "3x"
22+ },
23+ {
24+ "idiom" : "iphone",
25+ "size" : "60x60",
26+ "scale" : "2x"
27+ },
28+ {
29+ "idiom" : "iphone",
30+ "size" : "60x60",
31+ "scale" : "3x"
32+ },
33+ {
34+ "idiom" : "ipad",
35+ "size" : "29x29",
36+ "scale" : "1x"
37+ },
38+ {
39+ "idiom" : "ipad",
40+ "size" : "29x29",
41+ "scale" : "2x"
42+ },
43+ {
44+ "idiom" : "ipad",
45+ "size" : "40x40",
46+ "scale" : "1x"
47+ },
48+ {
49+ "idiom" : "ipad",
50+ "size" : "40x40",
51+ "scale" : "2x"
52+ },
53+ {
54+ "idiom" : "ipad",
55+ "size" : "76x76",
56+ "scale" : "1x"
57+ },
58+ {
59+ "idiom" : "ipad",
60+ "size" : "76x76",
61+ "scale" : "2x"
62+ }
63+ ],
64+ "info" : {
65+ "version" : 1,
66+ "author" : "xcode"
67+ }
68+}
PixelImage/Base.lproj/LaunchScreen.storyboardnew file+27
@@ -0,0 +1,27 @@
1+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
3+ <dependencies>
4+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
5+ </dependencies>
6+ <scenes>
7+ <!--View Controller-->
8+ <scene sceneID="EHf-IW-A2E">
9+ <objects>
10+ <viewController id="01J-lp-oVM" sceneMemberID="viewController">
11+ <layoutGuides>
12+ <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
13+ <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
14+ </layoutGuides>
15+ <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+ <animations/>
19+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+ </view>
21+ </viewController>
22+ <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+ </objects>
24+ <point key="canvasLocation" x="53" y="375"/>
25+ </scene>
26+ </scenes>
27+</document>
PixelImage/Base.lproj/Main.storyboardnew file+26
@@ -0,0 +1,26 @@
1+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
3+ <dependencies>
4+ <deployment identifier="iOS"/>
5+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
6+ </dependencies>
7+ <scenes>
8+ <!--View Controller-->
9+ <scene sceneID="tne-QT-ifu">
10+ <objects>
11+ <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="PixelImage" customModuleProvider="target" sceneMemberID="viewController">
12+ <layoutGuides>
13+ <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14+ <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
15+ </layoutGuides>
16+ <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+ </view>
21+ </viewController>
22+ <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23+ </objects>
24+ </scene>
25+ </scenes>
26+</document>
PixelImage/ImageMetaballRenderer.swiftnew file+101
@@ -0,0 +1,101 @@
1+
2+import UIKit
3+
4+class ImageMetaballRenderer: MetaballRenderer {
5+ typealias TargetView = UIImageView
6+
7+ static func updateTargetView(imageView: TargetView, dataSource: MetaballDataSource) {
8+ let width = Int(imageView.width)
9+ let height = Int(imageView.height)
10+ let metaballs = dataSource.metaballs
11+
12+ let bytesPerPixel = 4;
13+ let bytesPerRow = bytesPerPixel * width;
14+ let bitsPerComponent = 8;
15+
16+ var matrix = PixelMatrix(width: width, height: height)
17+ for i in 0..<width {
18+ for j in 0..<height {
19+ let pixelPosition = CGPoint(x: i, y: j)
20+
21+ var sum: CGFloat = 0
22+
23+ for combo in metaballs.combos() {
24+ let metaball1 = combo[0].middle
25+ let metaball2 = combo[1].middle
26+
27+ let metaball1Vector = metaball1 - pixelPosition
28+ let metaball2Vector = metaball2 - pixelPosition
29+
30+ let direction1 = metaball1Vector.normalized
31+ let direction2 = metaball2Vector.normalized
32+
33+ let cos = direction1 * direction2
34+
35+ let value1 = 255000 / (metaball1Vector * metaball1Vector + 1)
36+ let value2 = 255000 / (metaball2Vector * metaball2Vector + 1)
37+
38+ let v = gradient(value1 + value2)
39+ let link = ((1 - cos) * 0.5) ^ 50
40+
41+ let weightedLink = 128 * CGFloat(link)
42+ let weightedValue = 0.6 * CGFloat(v)
43+
44+ sum += weightedValue + weightedLink
45+ }
46+
47+ let result = threshold(sum)
48+
49+ matrix.set(x: i, y: j, r:0, g:result/2, b:result)
50+ }
51+ }
52+
53+ let buffer: UnsafeMutablePointer<Void> = UnsafeMutablePointer(matrix.pixels)
54+
55+ let colorSpace = CGColorSpaceCreateDeviceRGB()
56+ let context = CGBitmapContextCreate(buffer, width, height, bitsPerComponent, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedLast.rawValue | CGBitmapInfo.ByteOrder32Big.rawValue);
57+
58+ let cgImage = CGBitmapContextCreateImage(context)
59+ let image = UIImage(CGImage: cgImage!)
60+ imageView.image = image
61+ }
62+}
63+
64+struct PixelMatrix {
65+ var pixels: [UInt8]
66+
67+ let width: Int
68+ let height: Int
69+
70+ init(width: Int, height: Int) {
71+ self.width = width
72+ self.height = height
73+ pixels = [UInt8](count: (4 * width * height), repeatedValue: 255)
74+ }
75+
76+ mutating func set(x x: Int, y: Int, r: UInt8, g: UInt8, b: UInt8) {
77+ let index = 4 * (y * width + x)
78+ pixels[index ] = r
79+ pixels[index + 1] = g
80+ pixels[index + 2] = b
81+ }
82+
83+ mutating func set(x x: Int, y: Int, white: UInt8) {
84+ let index = 4 * (y * width + x)
85+ pixels[index ] = white
86+ pixels[index + 1] = white
87+ pixels[index + 2] = white
88+ }
89+}
90+
91+func threshold(value: CGFloat) -> UInt8 {
92+ return value < 128 ? 0 : 255
93+}
94+
95+func gradient(value: CGFloat) -> UInt8 {
96+ return UInt8(min(max(value, 0), CGFloat(255)))
97+}
98+
99+func thresholdf(value value: CGFloat, cap: CGFloat = 0.5) -> CGFloat {
100+ return value < cap ? 0 : 1.0
101+}
PixelImage/Info.plistnew file+47
@@ -0,0 +1,47 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+<plist version="1.0">
4+<dict>
5+ <key>CFBundleDevelopmentRegion</key>
6+ <string>en</string>
7+ <key>CFBundleExecutable</key>
8+ <string>$(EXECUTABLE_NAME)</string>
9+ <key>CFBundleIdentifier</key>
10+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+ <key>CFBundleInfoDictionaryVersion</key>
12+ <string>6.0</string>
13+ <key>CFBundleName</key>
14+ <string>$(PRODUCT_NAME)</string>
15+ <key>CFBundlePackageType</key>
16+ <string>APPL</string>
17+ <key>CFBundleShortVersionString</key>
18+ <string>1.0</string>
19+ <key>CFBundleSignature</key>
20+ <string>????</string>
21+ <key>CFBundleVersion</key>
22+ <string>1</string>
23+ <key>LSRequiresIPhoneOS</key>
24+ <true/>
25+ <key>UILaunchStoryboardName</key>
26+ <string>LaunchScreen</string>
27+ <key>UIMainStoryboardFile</key>
28+ <string>Main</string>
29+ <key>UIRequiredDeviceCapabilities</key>
30+ <array>
31+ <string>armv7</string>
32+ </array>
33+ <key>UISupportedInterfaceOrientations</key>
34+ <array>
35+ <string>UIInterfaceOrientationPortrait</string>
36+ <string>UIInterfaceOrientationLandscapeLeft</string>
37+ <string>UIInterfaceOrientationLandscapeRight</string>
38+ </array>
39+ <key>UISupportedInterfaceOrientations~ipad</key>
40+ <array>
41+ <string>UIInterfaceOrientationPortrait</string>
42+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
43+ <string>UIInterfaceOrientationLandscapeLeft</string>
44+ <string>UIInterfaceOrientationLandscapeRight</string>
45+ </array>
46+</dict>
47+</plist>
PixelImage/MetaballRenderer.swiftnew file+18
@@ -0,0 +1,18 @@
1+
2+import UIKit
3+
4+protocol MetaballDataSource {
5+ var metaballs: [Metaball] { get }
6+}
7+
8+protocol MetaballRenderer {
9+ typealias TargetView: UIView
10+
11+ static func updateTargetView(targetView: TargetView, dataSource: MetaballDataSource)
12+}
13+
14+extension MetaballRenderer {
15+ static func createTargetView(frame frame: CGRect) -> TargetView {
16+ return TargetView(frame: frame)
17+ }
18+}
PixelImage/Metal.swiftnew file+13
@@ -0,0 +1,13 @@
1+import Metal
2+
3+class MTLContext {
4+ let device: MTLDevice
5+ let library: MTLLibrary
6+ let commandQueue: MTLCommandQueue
7+
8+ init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
9+ self.device = device
10+ self.library = device.newDefaultLibrary()!
11+ self.commandQueue = device.newCommandQueue()
12+ }
13+}
PixelImage/MetalMetaballRenderer.swiftnew file+126
@@ -0,0 +1,126 @@
1+// TODO: Render metaballs on layer/view instead of image
2+// TODO: Remove references to view size from shader
3+// TODO: Make shader ignore metaballs that are outside a certain area of tolerance (eg ±100 from borders)
4+
5+// TODO: Make graphics have edges only according to graph (instead of being a complete graph)
6+
7+// TODO: Interpolate metaball colors
8+// TODO: Use metaballs as mask: apply strong blur inside, weak blur outside
9+// TODO: Add antialiasing
10+
11+import Metal
12+import UIKit
13+
14+class MetalMetaballRenderer: MetaballRenderer {
15+
16+ typealias TargetView = UIImageView
17+
18+ static let context = MTLContext()
19+
20+ static func updateTargetView(imageView: UIImageView, dataSource: MetaballDataSource) {
21+ let metaballs = dataSource.metaballs
22+
23+ let kernelFunction: MTLFunction?
24+ let pipeline: MTLComputePipelineState
25+ var internalTexture: MTLTexture! = nil
26+
27+ do {
28+ kernelFunction = context.library.newFunctionWithName("drawMetaballs")
29+ pipeline = try context.device.newComputePipelineStateWithFunction(kernelFunction!)
30+
31+ let width = Int(imageView.width)
32+ let height = Int(imageView.height)
33+
34+ let textureDescriptor =
35+ MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(.BGRA8Unorm, width: width, height: height, mipmapped: false)
36+
37+ internalTexture = context.device.newTextureWithDescriptor(textureDescriptor)
38+ let threadGroupCounts = MTLSizeMake(8, 8, 1)
39+ let threadGroups = MTLSizeMake(width / threadGroupCounts.width,
40+ height / threadGroupCounts.height, 1)
41+
42+ //
43+ let metaballInfoTexture = metaballTexture(metaballs)
44+
45+ //
46+ let commandBuffer = context.commandQueue.commandBuffer()
47+
48+ let commandEncoder = commandBuffer.computeCommandEncoder()
49+ commandEncoder.setComputePipelineState(pipeline)
50+ commandEncoder.setTexture(internalTexture, atIndex: 0)
51+ commandEncoder.setTexture(metaballInfoTexture, atIndex: 1)
52+ commandEncoder.dispatchThreadgroups(threadGroups,
53+ threadsPerThreadgroup: threadGroupCounts)
54+ commandEncoder.endEncoding()
55+
56+ commandBuffer.commit()
57+ commandBuffer.waitUntilCompleted()
58+
59+ } catch _ {
60+ print("Error!")
61+ }
62+
63+ imageView.image = image(texture: internalTexture)
64+ }
65+
66+ static func image(texture texture: MTLTexture) -> UIImage {
67+ let imageSize = CGSizeMake(CGFloat(texture.width),
68+ CGFloat(texture.height))
69+
70+ let width = Int(imageSize.width)
71+ let height = Int(imageSize.height)
72+
73+ let imageByteCount = width * height * 4
74+ let imageBytes = malloc(imageByteCount)
75+ let bytesPerRow = width * 4
76+ let region = MTLRegionMake2D(0, 0, width, height)
77+ texture.getBytes(imageBytes, bytesPerRow: bytesPerRow,
78+ fromRegion: region, mipmapLevel: 0)
79+
80+ let provider = CGDataProviderCreateWithData(nil, imageBytes,
81+ imageByteCount) {
82+ (_, data, _) -> Void in
83+ free(UnsafeMutablePointer<Void>(data))
84+ }
85+
86+ let bitsPerComponent = 8
87+ let bitsperPixel = 32
88+ let colorSpaceRef = CGColorSpaceCreateDeviceRGB()
89+ let bitmapInfo = CGBitmapInfo(rawValue:
90+ CGImageAlphaInfo.PremultipliedLast.rawValue |
91+ CGBitmapInfo.ByteOrder32Big.rawValue)
92+ let renderingIntent = CGColorRenderingIntent.RenderingIntentDefault
93+ let imageRef = CGImageCreate(width, height,
94+ bitsPerComponent, bitsperPixel, bytesPerRow,
95+ colorSpaceRef, bitmapInfo, provider,
96+ nil, false, renderingIntent)
97+ let image = UIImage(CGImage: imageRef!, scale: 0.0,
98+ orientation: UIImageOrientation.DownMirrored)
99+
100+ return image
101+ }
102+
103+ static func metaballTexture(metaballs: [Metaball]) -> MTLTexture {
104+ let floats: [Float] = metaballs.reduce([Float(metaballs.count)]) { (var array, metaball) -> [Float] in
105+ array.append(Float(metaball.midX))
106+ array.append(Float(metaball.midY))
107+ return array
108+ }
109+ let size = floats.count
110+
111+ let textureDescriptor =
112+ MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(
113+ .R32Float, width: size, height: 1, mipmapped: false)
114+
115+ let texture = context.device.newTextureWithDescriptor(textureDescriptor)
116+
117+ let region = MTLRegionMake2D(0, 0, size, 1)
118+
119+ texture.replaceRegion(region, mipmapLevel: 0, withBytes: floats,
120+ bytesPerRow: sizeof(Float) * size)
121+
122+ return texture
123+ }
124+
125+}
126+
PixelImage/SwiftSugar/ApproximationOperator.swiftnew file+12
@@ -0,0 +1,12 @@
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.swiftnew file+6
@@ -0,0 +1,6 @@
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.swiftnew file+57
@@ -0,0 +1,57 @@
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.swiftnew file+12
@@ -0,0 +1,12 @@
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.swiftnew file+11
@@ -0,0 +1,11 @@
1+import Foundation
2+
3+extension NSNumber: DoubleValuable {
4+ var toDouble: Double {
5+ get { return self.doubleValue }
6+ }
7+
8+ static func fromDouble(double: Double) -> Self {
9+ return self.init(double: double)
10+ }
11+}
PixelImage/SwiftSugar/Numeric.swiftnew file+62
@@ -0,0 +1,62 @@
1+protocol DoubleValuable {
2+ var toDouble: Double { get }
3+
4+ static func fromDouble(double: Double) -> Self
5+}
6+
7+postfix operator ++ { }
8+
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
17+ @warn_unused_result func - (lhs: Self, rhs: Self) -> Self
18+ @warn_unused_result func + (lhs: Self, rhs: Self) -> Self
19+ @warn_unused_result func * (lhs: Self, rhs: Self) -> Self
20+ postfix func ++ (inout _: Self) -> Self
21+}
22+
23+protocol FastNumeric: Numeric { }
24+
25+extension Double: FastNumeric {
26+ var toDouble: Double {
27+ get { return self }
28+ }
29+
30+ static func fromDouble(double: Double) -> Double {
31+ return double
32+ }
33+}
34+
35+extension Float: FastNumeric {
36+ var toDouble: Double {
37+ get { return Double(self) }
38+ }
39+
40+ static func fromDouble(double: Double) -> Float {
41+ return Float(double)
42+ }
43+}
44+
45+extension Int: FastNumeric {
46+ var toDouble: Double {
47+ get { return Double(self) }
48+ }
49+
50+ static func fromDouble(double: Double) -> Int {
51+ return Int(double)
52+ }
53+}
54+
55+//
56+extension Int {
57+ func times(@noescape block: () throws -> ()) rethrows {
58+ for _ in 1...self {
59+ try block()
60+ }
61+ }
62+}
PixelImage/SwiftSugar/PowerOperator.swiftnew file+15
@@ -0,0 +1,15 @@
1+import Darwin
2+
3+infix operator ^ { associativity right precedence 131 }
4+
5+func ^<T: DoubleValuable>(left: T, right: T) -> T {
6+ return T.fromDouble(pow(left.toDouble, right.toDouble))
7+}
8+
9+func ^ (left: Double, right: Double) -> Double {
10+ return pow(left, right)
11+}
12+
13+func ^ (left: Float, right: Float) -> Float {
14+ return powf(left, right)
15+}
PixelImage/SwiftSugar/Sequence.swiftnew file+16
@@ -0,0 +1,16 @@
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.swiftnew file+162
@@ -0,0 +1,162 @@
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+
11+struct HashMemoizedSequence <IndexType: Hashable, ReturnType>:
12+MemoizedSequence {
13+
14+ let memoizedFunction: (IndexType -> ReturnType)
15+ let increment: ((inout IndexType) -> Void)
16+ let firstIndex: IndexType
17+
18+ var index: IndexType
19+
20+ init(first: IndexType,
21+ incrementer: ((inout IndexType) -> Void),
22+ memoizedFunction: (IndexType -> ReturnType)) {
23+
24+ self.firstIndex = first
25+
26+ self.index = first
27+ self.increment = incrementer
28+ self.memoizedFunction = memoizedFunction
29+ }
30+
31+ init(first: IndexType,
32+ incrementer: ((inout IndexType) -> Void),
33+ closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
34+ let memoizedFunction = memoize(closure)
35+
36+ self.init(first: first, incrementer: incrementer,
37+ memoizedFunction: memoizedFunction)
38+ }
39+
40+ init(first: IndexType,
41+ incrementer: ((inout IndexType) -> Void),
42+ function: (IndexType -> ReturnType)) {
43+
44+ let memoizedFunction = memoize(function)
45+
46+ self.init(first: first, incrementer: incrementer,
47+ memoizedFunction: memoizedFunction)
48+ }
49+}
50+
51+extension HashMemoizedSequence: GeneratorType {
52+ mutating func next() -> ReturnType? {
53+ let result = memoizedFunction(index)
54+ increment(&index)
55+ return result
56+ }
57+}
58+
59+extension HashMemoizedSequence: LazySequenceType {
60+ func generate() -> HashMemoizedSequence {
61+ return self
62+ }
63+}
64+
65+extension HashMemoizedSequence where ReturnType: Comparable {
66+ @warn_unused_result
67+ func contains(element: ReturnType) -> Bool {
68+ var index = firstIndex
69+
70+ while true {
71+ let value = memoizedFunction(index)
72+
73+ if value == element {
74+ return true
75+ } else if value > element {
76+ return false
77+ }
78+
79+ increment(&index)
80+ }
81+ }
82+}
83+
84+extension HashMemoizedSequence where IndexType: Incrementable {
85+ init(first: IndexType,
86+ closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
87+ self.firstIndex = first
88+ self.index = first
89+ self.increment = { (inout index: IndexType) in
90+ index++
91+ }
92+ self.memoizedFunction = memoize(closure)
93+ }
94+
95+ init(first: IndexType,
96+ function: (IndexType -> ReturnType)) {
97+ self.firstIndex = first
98+ self.index = first
99+ self.increment = { (inout index: IndexType) in
100+ index++
101+ }
102+ self.memoizedFunction = memoize(function)
103+ }
104+}
105+
106+extension HashMemoizedSequence where IndexType: Incrementable,
107+ IndexType: IntegerLiteralConvertible {
108+ init(_ closure: ((IndexType -> ReturnType, IndexType) -> ReturnType)) {
109+ self.firstIndex = 1
110+ self.index = 1
111+ self.increment = { (inout index: IndexType) in
112+ index++
113+ }
114+ self.memoizedFunction = memoize(closure)
115+ }
116+
117+ init(_ function: (IndexType -> ReturnType)) {
118+ self.firstIndex = 1
119+ self.index = 1
120+ self.increment = { (inout index: IndexType) in
121+ index++
122+ }
123+ self.memoizedFunction = memoize(function)
124+ }
125+}
126+
127+func memoize <H: Hashable, R> (closure: ((H -> R, H) -> R) ) -> (H -> R) {
128+
129+ var table = [H : R]()
130+
131+ var auxiliaryFunction: (H -> R)!
132+ auxiliaryFunction = { index in
133+ if let result = table[index] {
134+ return result
135+ }
136+
137+ let result = closure(auxiliaryFunction, index)
138+ table[index] = result
139+
140+ return result
141+ }
142+
143+ return auxiliaryFunction
144+}
145+
146+func memoize <H: Hashable, R> (function: (H -> R) ) -> (H -> R) {
147+
148+ var table = [H : R]()
149+
150+ let result: (H -> R) = { index in
151+ if let result = table[index] {
152+ return result
153+ }
154+
155+ let result = function(index)
156+ table[index] = result
157+
158+ return result
159+ }
160+
161+ return result
162+}
PixelImage/SwiftSugar/SignOperator.swiftnew file+13
@@ -0,0 +1,13 @@
1+
2+prefix operator ± { }
3+
4+prefix func ± <T: Numeric> (number: T) -> T {
5+
6+ if number > 0 {
7+ return 1
8+ } else if number == 0 {
9+ return 0
10+ } else {
11+ return -1
12+ }
13+}
PixelImage/SwiftSugar/String.swiftnew file+9
@@ -0,0 +1,9 @@
1+extension String: DoubleValuable {
2+ var toDouble: Double {
3+ get { return Double(self) ?? Double(0) }
4+ }
5+
6+ static func fromDouble(double: Double) -> String {
7+ return "\(double)"
8+ }
9+}
PixelImage/SwiftSugar/SwiftSequences/Categorise.swiftnew file+211
@@ -0,0 +1,211 @@
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.swiftnew file+146
@@ -0,0 +1,146 @@
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.swiftnew file+114
@@ -0,0 +1,114 @@
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.swiftnew file+86
@@ -0,0 +1,86 @@
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.swiftnew file+33
@@ -0,0 +1,33 @@
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.swiftnew file+80
@@ -0,0 +1,80 @@
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.swiftnew file+23
@@ -0,0 +1,23 @@
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.swiftnew file+78
@@ -0,0 +1,78 @@
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.swiftnew file+366
@@ -0,0 +1,366 @@
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.swiftnew file+34
@@ -0,0 +1,34 @@
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.swiftnew file+229
@@ -0,0 +1,229 @@
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.swiftnew file+187
@@ -0,0 +1,187 @@
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.swiftnew file+152
@@ -0,0 +1,152 @@
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.swiftnew file+138
@@ -0,0 +1,138 @@
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.swiftnew file+208
@@ -0,0 +1,208 @@
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.swiftnew file+90
@@ -0,0 +1,90 @@
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.swiftnew file+95
@@ -0,0 +1,95 @@
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+}
PixelImage/UIKit.swiftnew file+104
@@ -0,0 +1,104 @@
1+import UIKit
2+
3+func - (left: CGPoint, right: CGPoint) -> CGVector {
4+ return CGVector(dx: left.x - right.x, dy: left.y - right.y)
5+}
6+
7+func * (left: CGVector, right: CGVector) -> CGFloat {
8+ return (left.dx * right.dx) + (left.dy * right.dy)
9+}
10+
11+func / (vector: CGVector, scalar: CGFloat) -> CGVector {
12+ return CGVector(dx: vector.dx / scalar, dy: vector.dy / scalar)
13+}
14+
15+extension CGVector {
16+ var norm: CGFloat {
17+ get {
18+ let dot = self * self
19+ return sqrt(dot)
20+ }
21+ }
22+
23+ var normalized: CGVector {
24+ get {
25+ return self / norm
26+ }
27+ }
28+
29+ mutating func normalize() {
30+ let norm = self.norm
31+ dx = dx / norm
32+ dy = dy / norm
33+ }
34+}
35+
36+extension CGFloat: DoubleValuable {
37+ var toDouble: Double { get {
38+ return Double(self)
39+ }
40+ }
41+
42+ static func fromDouble(double: Double) -> CGFloat {
43+ return CGFloat(double)
44+ }
45+}
46+
47+extension CGRect {
48+ var x: CGFloat {
49+ get { return origin.x }
50+ set { origin.x = newValue }
51+ }
52+
53+ var y: CGFloat {
54+ get { return origin.y }
55+ set { origin.y = newValue }
56+ }
57+}
58+
59+extension CGSize {
60+ init(_ squareSize: CGFloat) {
61+ self.init(width: squareSize, height: squareSize)
62+ }
63+}
64+
65+extension UIView {
66+ var origin: CGPoint {
67+ get { return frame.origin }
68+ set { frame.origin = newValue }
69+ }
70+
71+ var size: CGSize {
72+ get { return frame.size }
73+ set { frame.size = newValue }
74+ }
75+
76+ var width: CGFloat {
77+ get { return frame.width }
78+ set { frame.size = CGSize(width: newValue, height: height) }
79+ }
80+
81+ var height: CGFloat {
82+ get { return frame.height }
83+ set { frame.size = CGSize(width: width, height: newValue) }
84+ }
85+
86+ var middle: CGPoint {
87+ get {
88+ return CGPoint(x: origin.x + width/2, y: origin.y + height/2)
89+ }
90+ set {
91+ origin = CGPoint(x: newValue.x - width/2, y: newValue.y - height/2)
92+ }
93+ }
94+
95+ var midX: CGFloat {
96+ get { return middle.x }
97+ set { middle = CGPoint(x: newValue, y: midY) }
98+ }
99+
100+ var midY: CGFloat {
101+ get { return middle.y }
102+ set { middle = CGPoint(x: midX, y: newValue) }
103+ }
104+}
PixelImage/ViewController.swiftnew file+81
@@ -0,0 +1,81 @@
1+
2+import UIKit
3+
4+class ViewController: UIViewController, MetaballDataSource {
5+
6+ let dynamicRendering = true
7+ typealias Renderer = MetalMetaballRenderer // ImageMetaballRenderer // MetalMetaballRenderer
8+ typealias TargetView = Renderer.TargetView
9+
10+ var metaballView: TargetView!
11+
12+ let width = 350
13+ let height = 600
14+
15+ var metaballs = [CGPoint(x: 70, y: 70), CGPoint(x: 270, y: 470), CGPoint(x: 270, y: 70), CGPoint(x: 70, y: 470)].map {
16+ Metaball(position: $0)
17+ }
18+ var previousLocation: CGPoint!
19+
20+ override func viewDidLoad() {
21+ super.viewDidLoad()
22+
23+
24+ let recognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
25+ view.addGestureRecognizer(recognizer)
26+
27+
28+ let border = 20
29+ let metaballViewFrame = CGRect(x: border/2, y: border/2, width: width, height: height)
30+ metaballView = Renderer.createTargetView(frame: metaballViewFrame)
31+
32+ let bigView = UIView(frame: CGRect(x: 10, y: 70, width: width + border, height: height + border))
33+ bigView.backgroundColor = UIColor.redColor()
34+ bigView.addSubview(metaballView)
35+ view.addSubview(bigView)
36+
37+
38+ for metaball in metaballs {
39+ metaballView.addSubview(metaball)
40+ }
41+
42+
43+ Renderer.updateTargetView(metaballView, dataSource: self)
44+ }
45+
46+ func handlePan(recognizer: UIPanGestureRecognizer) {
47+ let location = recognizer.locationInView(metaballView)
48+
49+ var selectedMetaball: UIView?
50+
51+ for metaball in metaballs where
52+ abs(metaball.midX - location.x) < 50 && abs(metaball.midY - location.y) < 50 {
53+ selectedMetaball = metaball
54+ break
55+ }
56+
57+ selectedMetaball?.middle = location
58+
59+ if recognizer.state == .Changed && dynamicRendering {
60+ Renderer.updateTargetView(metaballView, dataSource: self)
61+ }
62+ if recognizer.state == .Ended {
63+ Renderer.updateTargetView(metaballView, dataSource: self)
64+ }
65+ }
66+}
67+
68+class Metaball: UIView {
69+
70+ init(position: CGPoint) {
71+ super.init(frame: CGRect.zero)
72+
73+ size = CGSize(50)
74+ middle = position
75+ backgroundColor = UIColor(red: 0.1306, green: 0.7522, blue: 0.0307, alpha: 0.3)
76+ }
77+
78+ required init?(coder aDecoder: NSCoder) {
79+ super.init(coder: aDecoder)
80+ }
81+}
PixelImage/shaders.metalnew file+51
@@ -0,0 +1,51 @@
1+
2+#include <metal_stdlib>
3+
4+using namespace metal;
5+
6+kernel void
7+ drawMetaballs(texture2d<float, access::write> outTexture[[texture(0)]],
8+ texture2d<float, access::read>
9+ metaballTexture[[texture(1)]],
10+ uint2 gid[[thread_position_in_grid]]) {
11+
12+ char numberOfMetaballs = metaballTexture.read(0)[0];
13+ char metaballArraySize = numberOfMetaballs * 2 + 1;
14+
15+ float sum = 0;
16+
17+ for (char i = 1; i < metaballArraySize; i += 2) {
18+ for (char j = i + 2; j < metaballArraySize; j += 2) {
19+ float2 metaball1 = float2(metaballTexture.read(i)[0],
20+ 600 - metaballTexture.read(i + 1)[0]);
21+
22+ float2 metaball2 = float2(metaballTexture.read(j)[0],
23+ 600 - metaballTexture.read(j + 1)[0]);
24+
25+ float2 metaball1Vector
26+ = float2(metaball1.x - gid.x, metaball1.y - gid.y);
27+ float2 metaball2Vector
28+ = float2(metaball2.x - gid.x, metaball2.y - gid.y);
29+
30+ float2 direction1 = normalize(metaball1Vector);
31+ float2 direction2 = normalize(metaball2Vector);
32+
33+ float cosine = dot(direction1, direction2);
34+
35+ float value1 = 2048 / (dot(metaball1Vector, metaball1Vector) + 1);
36+ float value2 = 2048 / (dot(metaball2Vector, metaball2Vector) + 1);
37+
38+ float v = value1 + value2;
39+ float link = pow(((1 - cosine) * 0.5), 100);
40+
41+ float weightedLink = 0.6 * link;
42+ float weightedValue = 0.5 * v;
43+
44+ sum += mix(0.0, 1.0, step(0.5, weightedValue + weightedLink));
45+ }
46+ }
47+
48+ float result = sum;
49+
50+ outTexture.write(float4(result, result / 2, 0, 1), gid);
51+}