{"id":13413763,"url":"https://github.com/tchayen/triangolatte","last_synced_at":"2025-04-13T11:03:18.133Z","repository":{"id":48246781,"uuid":"141491194","full_name":"tchayen/triangolatte","owner":"tchayen","description":"2D triangulation library. Allows translating lines and polygons (both based on points) to the language of GPUs.","archived":false,"fork":false,"pushed_at":"2021-08-04T11:33:07.000Z","size":4190,"stargazers_count":36,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-05T15:14:26.817Z","etag":null,"topics":["computational-geometry","golang","triangulation"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tchayen.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":"2018-07-18T21:17:09.000Z","updated_at":"2023-11-18T05:44:58.000Z","dependencies_parsed_at":"2022-08-24T20:41:28.007Z","dependency_job_id":null,"html_url":"https://github.com/tchayen/triangolatte","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/tchayen%2Ftriangolatte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchayen%2Ftriangolatte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchayen%2Ftriangolatte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchayen%2Ftriangolatte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tchayen","download_url":"https://codeload.github.com/tchayen/triangolatte/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237335325,"owners_count":19293344,"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":["computational-geometry","golang","triangulation"],"created_at":"2024-07-30T20:01:48.517Z","updated_at":"2025-02-05T16:39:32.288Z","avatar_url":"https://github.com/tchayen.png","language":"Go","funding_links":[],"categories":["Science and Data Analysis","科学与数据分析","数据分析与数据科学","Relational Databases"],"sub_categories":["HTTP Clients","HTTP客户端","查询语","交流"],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"assets/logo.png\"\u003e\u003cbr /\u003e\n  triangolatte\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/tchayen/triangolatte\"\u003e\u003cimg src=\"https://travis-ci.org/tchayen/triangolatte.svg?branch=master\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/tchayen/triangolatte\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/tchayen/triangolatte\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/tchayen/triangolatte?branch=master\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/tchayen/triangolatte/badge.svg?branch=master\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://godoc.org/github.com/tchayen/triangolatte\"\u003e\u003cimg src=\"https://godoc.org/github.com/tchayen/triangolatte?status.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://gitter.im/triangolatte/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\"\u003e\u003cimg src=\"https://badges.gitter.im/triangolatte/Lobby.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n2D triangulation library. Allows translating lines and polygons (both based on\npoints) to the language of GPUs.\n\nFeatures normal and miter joint line triangulation. Handles polygons using ear\nclipping algorithm with hole elimination included.\n\n![screenshot](assets/examples_screenshot.png)\n\n\u003e **For reference:** _triangulates 99.76% of 75 thousand buildings in Cracow under 3.43s on\naverage programmer notebook (single threaded)._\n\n## Table of contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Features](#features)\n  - [API](#api)\n  - [Types](#types)\n- [Tests](#tests)\n- [Benchmarks](#benchmarks)\n  - [Flame Graphs](#flame-graphs)\n- [Future plans](#future-plans)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nNothing surprising\n```bash\ngo get github.com/tchayen/triangolatte\n```\n\n## Usage\n\n#### Basic example\n```go\nvertices := []Point{{10, 20}, {30, 40}, {50, 60}}\nt, err = triangolatte.Polygon(vertices)\n```\n\n## Examples\n\nIn `/examples` you can find:\n- **buildings** – full-blown WebGL previewer of buildings triangulated in _city_ example\n- **city** – triangulation of whole city downloaded from Open Street Map\n- **gpx** – GPX format parsing and triangulation of its data\n- **wireframe** – desktop OpenGL wireframe previewer for triangulated shapes\n\nYou will find instructions for running the code there.\n\n## Features\n\n### API\n\n#### `Polygon(points []Point, holes [][]Point) ([]float64, error)`\n\nTakes array of points and produces array of triangle coordinates.\n\nBased on the following [paper](https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf) and inspired by [EarCut](https://github.com/mapbox/earcut).\n\n#### `JoinHoles(points [][]Point) ([]Point, error)`\n\nRemoves holes, joining them with the rest of the polygon. Provides preprocessing\nfor `Polygon`. First element of the points array is the outer polygon, the rest\nof them are considered as holes to be removed.\n\n#### `Line(joint Joint, points []Point, width int) ([]float64, error)`\n\nTakes array of points and triangulates them to resemble a line of given\nwidth. Returns array of two-coordinate CCW triangles one after another.\n\n### Types\n\nTo select method of joining line segments.\n```go\ntype Joint int\n\nconst (\n\t// No joint correction.\n\tNormal Joint = 0\n\t// Producing miter joints, i.e. extending the lines until they meet at some point.\n\tMiter Joint = 1\n)\n```\n\nFor calculations using points.\n```go\ntype Point struct {\n  X, Y float64\n}\n```\n\nA wrapper for Point used in cyclic list.\n```go\ntype Element struct {\n\tPrev, Next *Element\n\tPoint      Point\n}\n```\n\n### Helpers\n\nYou can have a look at `helpers.go` file. It stores triangolatte's helper\nfunctions used mostly by tests and examples. They are not exported because I\ndon't want to commit to supporting them in the future, but they might turn out\nuseful for you.\n\n## Tests\n\nCode is (more or less) covered in tests. You can run them like this:\n\n```bash\ngo test -v\n```\n\nYou can also run benchmarks for selected functions (refer to the `*_test.go` files for availability). For example:\n\n```bash\ngo test -run NONE -bench IsInsideTriangle\n```\n\n## Benchmarks\n\n\u003e **NOTE:** _This section contains work in progress. Numbers below are better reference point than nothing, but still far from perfect._\n\n`Polygon()` on shape with 10 vertices takes `754ns` on average.\n\nTriangulation of 75 thousand buildings runs for around `3.43s`.\n\n_Using average programmer's notebook. Expect speed up on faster CPUs or while splitting execution into separate threads._\n\n### Flame Graphs\n\nCPU time % usage snaphost using Flame Graphs:\n\n![assets/torch.svg](assets/torch.svg)\n\nWant to learn what is it or maybe you are willing to generate one yourself? Check [FlameGraphs](flame_graphs.md) document in this repository.\n\n## Future plans\n\n### Optimizations\n\n\u003e **NOTE**: _this library is developed mostly with map data triangulation in\nmind and it will be its main performance target._\n\n- explore possibilities for optimizations in `JoinHoles(...)`\n- maybe allow reusing point array for massive allocation reduction\n\n### Content\n\n- provide more examples (e.g. desktop OpenGL usage, mobile app, live rendering pipeline, other unusual use cases...)\n- add benchmarks with comparison to libraries in\nother languages\n\n### WebAssembly\n\nOne of the core plans for this library's development is creating, as soon as it\nbecomes possible, some kind of [WebAssembly](https://webassembly.org/) module\nfor use in JS.\n\n## Contributing\n\nYou are welcome to create an issue or pull request if you've got an idea what to\ndo. It is usually a good idea to visit [Gitter](https://gitter.im/triangolatte/Lobby)\nand discuss your thoughts.\n\nDon't have one, but still want to contribute? Get in touch with us and we can\nbrainstorm some ideas.\n\n## License\n\nMIT License – refer to the [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchayen%2Ftriangolatte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftchayen%2Ftriangolatte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchayen%2Ftriangolatte/lists"}