{"id":16836799,"url":"https://github.com/redblobgames/dual-mesh","last_synced_at":"2025-04-02T22:08:42.919Z","repository":{"id":24726032,"uuid":"102298826","full_name":"redblobgames/dual-mesh","owner":"redblobgames","description":"V2 of dual polygon-triangle mesh code used in redblobgames's projects from 2017 to 2022. V3 (not here) used from 2023 onwards.","archived":false,"fork":false,"pushed_at":"2024-10-03T02:12:34.000Z","size":163,"stargazers_count":62,"open_issues_count":3,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T07:38:42.727Z","etag":null,"topics":["procedural-map-generator","triangle-mesh"],"latest_commit_sha":null,"homepage":"https://redblobgames.github.io/dual-mesh/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redblobgames.png","metadata":{"files":{"readme":"README.org","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-03T22:45:15.000Z","updated_at":"2025-03-24T01:47:27.000Z","dependencies_parsed_at":"2024-10-28T12:46:12.042Z","dependency_job_id":null,"html_url":"https://github.com/redblobgames/dual-mesh","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/redblobgames%2Fdual-mesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redblobgames%2Fdual-mesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redblobgames%2Fdual-mesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redblobgames%2Fdual-mesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redblobgames","download_url":"https://codeload.github.com/redblobgames/dual-mesh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246899658,"owners_count":20851898,"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":["procedural-map-generator","triangle-mesh"],"created_at":"2024-10-13T12:14:53.851Z","updated_at":"2025-04-02T22:08:42.901Z","avatar_url":"https://github.com/redblobgames.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[[http://unmaintained.tech/][http://unmaintained.tech/badge.svg]]\n\n*This is my 2017 library* but in 2023 I abandoned this and switched to a [[https://www.redblobgames.com/x/2312-dual-mesh/][newer library]].\n\nDual mesh library for my polygon map generator projects (mapgen2, mapgen4). Feel free to use this, but it's not a stable library and I do make breaking changes. The create.js interface is the most likely to change in the future.\n\nThis is a wrapper around [[https://mapbox.github.io/delaunator/][Delaunator]]. I wrote the [[https://mapbox.github.io/delaunator/][Delaunator Guide]] based on the code from this project. The code in the guide is easier to read and more general but less efficient than the code in this library.\n\n[[https://redblobgames.github.io/dual-mesh/][Documentation is here]], but it's a bit rough. See [[http://www.redblobgames.com/x/1721-voronoi-alternative/][my blog post about centroid polygons]] and [[http://www.redblobgames.com/x/1722-b-rep-triangle-meshes/][my blog post about the dual mesh data structure]] for the history. Those blog posts used the names “seeds, edges, triangles” but now I call them “regions, sides, triangles”, and I use “ghost” elements to eliminate the boundaries.\n\nThe naming convention is: =x_name_y= takes type x (r, s, t) as input and produces type y (r, s, t) as output. For example, =s_begin_r= is a function that takes a side (s) as input and returns a region (r), and could be called ~r = mesh.s_begin_r(s)~. In 2023 [[https://www.redblobgames.com/x/2312-dual-mesh/][I changed conventions]] to use =y_from_x=, putting the output first. \n\nFor efficiency, the accessors never allocate new arrays, but take a parameter where the result should be written:\n\n#+begin_src js\nlet out_r = [];\nmesh.t_circulate_r(out_r, t);\n// output written into out_r\n#+end_src\n\nFor convenience, they also return the array, so this works:\n\n#+begin_src js\nlet out_r = mesh.t_circulate_r([], t);\n#+end_src\n\nTo create a mesh, use the =MeshBuilder=:\n\n#+begin_src js\nlet mesh = new MeshBuilder()\n    .addPoints(array_of_points)\n    .create();\n#+end_src\n\n#+begin_src js\nlet Poisson = require('poisson-disk-sampling');\nlet mesh = new MeshBuilder({boundarySpacing: 75})\n    .addPoisson(Poisson, 75)\n    .create();\n#+end_src\n\n** Built with\n\n- [[https://github.com/mapbox/delaunator][delaunator]] to build the Delaunay triangulation\n- [[https://github.com/kchapelier/poisson-disk-sampling][poisson-disk-sampling]] to choose evenly spaced points\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredblobgames%2Fdual-mesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredblobgames%2Fdual-mesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredblobgames%2Fdual-mesh/lists"}