{"id":1161,"url":"https://github.com/didierbrun/DBPathRecognizer","last_synced_at":"2025-07-30T20:32:34.491Z","repository":{"id":28806910,"uuid":"32330000","full_name":"didierbrun/DBPathRecognizer","owner":"didierbrun","description":"Gesture recognizer tool [Swift / iOS]","archived":false,"fork":false,"pushed_at":"2022-07-12T09:05:14.000Z","size":565,"stargazers_count":1176,"open_issues_count":1,"forks_count":92,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-12-01T12:06:54.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/didierbrun.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-03-16T14:21:07.000Z","updated_at":"2024-10-22T13:29:00.000Z","dependencies_parsed_at":"2022-09-05T01:20:21.091Z","dependency_job_id":null,"html_url":"https://github.com/didierbrun/DBPathRecognizer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didierbrun%2FDBPathRecognizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didierbrun%2FDBPathRecognizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didierbrun%2FDBPathRecognizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didierbrun%2FDBPathRecognizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/didierbrun","download_url":"https://codeload.github.com/didierbrun/DBPathRecognizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187539,"owners_count":17882322,"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-01-05T20:15:40.245Z","updated_at":"2024-12-04T20:31:02.061Z","avatar_url":"https://github.com/didierbrun.png","language":"Swift","funding_links":[],"categories":["Gesture","Libs","UI"],"sub_categories":["Getting Started","Gesture","Other free courses","Linter"],"readme":"DBPathRecognizer\n================\n\n## Demo\n\n![ScreenShot](https://raw.github.com/didierbrun/DBPathRecognizer/master/Assets/screencast.gif)\n\n## Installation\n\nSimply add the file DBPathRecognizer.swift to your project\n\n## Basic usage\n\nStart by creating a new DBPathRecognizer instance\n\n```swift\n// Create the path 8-directions path recognizer with a delta move sensibility of 16 pt\nlet recognizer = DBPathRecognizer(sliceCount: 8, deltaMove: 16.0)\n```\n\nNote that you can specify a max cost to recognize the gestures. It means that if a gesture has a score greater than costMax, it will be ignored. \n\n```swift\nlet recognizer = DBPathRecognizer(sliceCount: 8, deltaMove: 16.0, costMax: 40)\n```\n\nAdd some path model to the recognizer.\nEach path is defined by a direction-sequence and an associated data object (AnyObject).\n\n```swift\nrecognizer.addModel(PathModel(directions: [7, 1], datas:\"A\"))\nrecognizer.addModel(PathModel(directions: [2,6,0,1,2,3,4,0,1,2,3,4], datas:\"B\"))\nrecognizer.addModel(PathModel(directions: [4,3,2,1,0], datas:\"C\"))\nrecognizer.addModel(PathModel(directions: [4,3,2,1,0,4,3,2,1,0], datas:\"E\"))\n```\n\nFor example, here the model for the letter E :\n\n![ScreenShot](https://raw.github.com/didierbrun/DBPathRecognizer/master/Assets/directions.png)\n\nRecord a touch move sequence into the dedicated Path structure :\n\n```swift\n// Create the path\nvar path:Path = Path()\n\n// Add a point (from touch location)\npath.addPoint(PathPoint(x:100, y:100)) \n\n// You can also use the convenient method addPointFromRaw(var rawDatas:[Int])\npath.addPointFromRaw(rawPoints)\n```\n\nFinally, tell the recognizer to find the best model :\n\n```swift\nvar gesture:PathModel? = self.recognizer!.recognizePath(path)\n        \nif gesture != nil {\n    // The best gesture is recognized\n} else {\n    // No gesture recognized (score is too low)\n}\n```\n\n## Custom filter\n\nWhile adding a model, you can specify a custom filter. The filter callback method, if specified, will give you a last chance to modify / analyze the datas to determine a new score.\n\nFor example, the letter D \u0026 P have a similar draw-direction-path, however you can discriminate each one by detecting the position of the last point (up -\u003e it's a P, down -\u003e it's a D). The PathInfos struct transmitted to the filter function will help you to determine the new score.\n\nYour custom filter function should conform to this signature : ((score:Int, infos:PathInfos) -\u003e newScore:Int) :\n\n```swift\nrecognizer.addModel(PathModel(directions: [2,6,7,0,1,2,3,4], datas:\"P\", filter:{\n            (cost:Int, infos:PathInfos) -\u003e Int in\n                // Determine new cost\n                return cost\n        }));\n```\n\n## Free path\n\nIn this sample project I've used the Graffiti alphabet for the didactic aspect. However, PathRecognizer is a generic algorithm, you can add any free path to control an interface / game :\n\n![ScreenShot](https://raw.github.com/didierbrun/DBPathRecognizer/master/Assets/other_moves.png)\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidierbrun%2FDBPathRecognizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdidierbrun%2FDBPathRecognizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidierbrun%2FDBPathRecognizer/lists"}