{"id":16699852,"url":"https://github.com/malcommac/swiftunistroke","last_synced_at":"2025-09-18T22:56:33.227Z","repository":{"id":56312715,"uuid":"43973151","full_name":"malcommac/SwiftUnistroke","owner":"malcommac","description":"✍️ $1 Unistroke Gesture Recognizer in Swift","archived":false,"fork":false,"pushed_at":"2020-11-15T09:35:57.000Z","size":1473,"stargazers_count":54,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T09:22:42.651Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malcommac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-09T18:31:36.000Z","updated_at":"2024-09-23T05:29:22.000Z","dependencies_parsed_at":"2022-08-15T16:31:05.770Z","dependency_job_id":null,"html_url":"https://github.com/malcommac/SwiftUnistroke","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcommac%2FSwiftUnistroke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcommac%2FSwiftUnistroke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcommac%2FSwiftUnistroke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcommac%2FSwiftUnistroke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malcommac","download_url":"https://codeload.github.com/malcommac/SwiftUnistroke/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244156645,"owners_count":20407542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T18:08:22.697Z","updated_at":"2025-09-18T22:56:28.162Z","avatar_url":"https://github.com/malcommac.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\" \u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/malcommac/SwiftUnistroke/master/logo.png\" width=210px height=204px alt=\"SwiftUnistroke\" title=\"SwiftUnistroke\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" \u003e$1 Unistroke Gesture Recognizer in Swift\u003cp/\u003e\n\u003cp align=\"center\" \u003e★★ \u003cb\u003eStar our github repository to help us!\u003c/b\u003e ★★\u003c/p\u003e\n\n[![CI Status](http://img.shields.io/travis/Daniele Margutti/SwiftUnistroke.svg?style=flat)](https://travis-ci.org/Daniele Margutti/SwiftUnistroke)\n[![Version](https://img.shields.io/cocoapods/v/SwiftUnistroke.svg?style=flat)](http://cocoapods.org/pods/SwiftUnistroke)\n[![License](https://img.shields.io/cocoapods/l/SwiftUnistroke.svg?style=flat)](http://cocoapods.org/pods/SwiftUnistroke)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftUnistroke.svg?style=flat)](http://cocoapods.org/pods/SwiftUnistroke)\n\n# SwiftUnistroke\n\n## You also may like\n-------\n\nDo you like `SwiftRichString`? I'm also working on several other opensource libraries.\n\nTake a look here:\n\n* **[SwiftDate](https://github.com/malcommac/SwiftDate)** - Full features Dates \u0026 TimeZone management for iOS,macOS,tvOS and watchOS\n* **[Hydra](https://github.com/malcommac/Hydra)** - Promise, Async/Await on sterioids!\n* **[SwiftLocation](https://github.com/malcommac/SwiftLocation)** - CoreLocation and Beacon Monitoring on steroid!\n* **[SwiftScanner](https://github.com/malcommac/SwiftScanner)** - String scanner in pure Swift with full unicode support\n* **[SwiftSimplify](https://github.com/malcommac/SwiftSimplify)** - Tiny high-performance Swift Polyline Simplification Library\n* **[SwiftMsgPack](https://github.com/malcommac/SwiftMsgPack)** - MsgPack Encoder/Decoder in Swit\n\n\n## Demo\nA full video of the gesture recognizer is available here:\n* [$1 Unistroke Demo](http://www.youtube.com/watch?v=P7wQVkmTkPY)\n\n[![SwiftUnistroke Video](https://raw.githubusercontent.com/malcommac/SwiftUnistroke/master/swiftunistroke.png)](http://www.youtube.com/watch?v=P7wQVkmTkPY)\n\n## Description\nSwiftUnistroke is a pure Swift 2 implementation of the $1 Unistroke Algorithm developed by Jacob Wobbrock, Andy Wilson and Yang Li.\n\nThe $1 Unistroke Recognizer is a 2-D single-stroke recognizer designed for rapid prototyping of gesture-based user interfaces.\n\nIn machine learning terms, $1 is an instance-based nearest-neighbor classifier with a Euclidean scoring function, i.e., a geometric template matcher.\n\nDespite its simplicity, $1 requires very few templates to perform well and is only about 100 lines of code, making it easy to deploy. An optional enhancement called Protractor improves $1's speed.\n\nA more detailed description of the algorithm is available both on [official project paper](http://faculty.washington.edu/wobbrock/pubs/uist-07.01.pdf) and on my [blog's article here](http://danielemargutti.com/1-recognizer-in-swift-2/).\n\nThis library also contain an example project which demostrate how the algorithm works with a set of loaded templates; extends this library is pretty easy and does not involve any machine learning stuff.\nOther languages implementation can be [found here](https://depts.washington.edu/aimgroup/proj/dollar/).\n\n##Highlights\n- [x] Fast gestures recognition\n- [x] Simple code, less than 200 lines\n- [x] Easy extensible pattern templates collection\n- [x] High performance even with old hardware\n- [x] Machine learning is not necessary\n- [x] An optional enhancement called protractor ([more](http://dl.acm.org/citation.cfm?id=1753654)) improves speed.\n\n### Author\nDaniele Margutti\n- *web*: [www.danielemargutti.com](http://www.danielemargutti.com)\n- *linkedin*: [https://linkedin.com/in/danielemargutti](https://linkedin.com/in/danielemargutti)\n- *twitter*: [@danielemargutti](http://www.twitter.com/danielemargutti)  \n- *mail*: [hello@danielemargutti.com](hello@danielemargutti.com)\n\n## Communication\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n##Version History\n##1.0 (Oct 9, 2015)\n- First release\n\n## Requirements\n- Mac OS X 10.10+ or iOS 8+\n- Swift 2+\n\n## How to use it\nSwiftUnistroke is really simple to use: first of all you need to provide a set of templates; each template is composed by a series of points which describe the path.\nYou can create a new ```SwiftUnistrokeTemplate``` object from an array of ```CGPoints``` or ```StrokePoint```.\n\nIn this example we load a template from a JSON dictionary which contains ```name```,```points``` keys:\n\n```swift\nlet templateDict = try NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary\nlet name = templateDict[\"name\"]! as! String\nlet rawPoints: [AnyObject] = templateDict[\"points\"]! as! [AnyObject]\n\nvar points: [StrokePoint] = []\nfor rawPoint in rawPoints {\n\tlet x = (rawPoint as! [AnyObject]).first! as! Double\n\tlet y = (rawPoint as! [AnyObject]).last! as! Double\n\tpoints(StrokePoint(x: x, y: y))\n}\t\t\nlet templateObj = SwiftUnistrokeTemplate(name: name, points: points)\t\t\n```\nNow suppose you have an array of ```SwiftUnistrokeTemplate``` and an array of captured points (```inputPoints```, your path to recognize).\nIn order to perform a search you need to allocate a new ```SwiftUnistroke``` and call ```recognizeIn()``` method:\n\n```swift\nlet recognizer = SwiftUnistroke(points: inputPoints!)\ndo {\n\tlet (template,distance) = try recognizer.recognizeIn(self.templates, useProtractor:  false)\n\tif template != nil {\n\t\tprint(\"[FOUND] Template found is \\(template!.name) with distance: \\(distance!)\")\n\t} else {\n\t\tprint(\"[FAILED] Template not found\")\n\t}\n} catch (let error as NSError) {\n\tprint(\"[FAILED] Error: \\(error.localizedDescription)\")\n}\n```\n\nThat's all, this method return the best match in your templates bucket.\n\n## Installation\n\nSwiftUnistroke is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"SwiftUnistroke\"\n```    \n\n### License\n\nSwiftUnistroke is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalcommac%2Fswiftunistroke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalcommac%2Fswiftunistroke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalcommac%2Fswiftunistroke/lists"}