{"id":28146127,"url":"https://github.com/hypertidy/laridae","last_synced_at":"2025-06-27T15:07:49.622Z","repository":{"id":31661094,"uuid":"35226473","full_name":"hypertidy/laridae","owner":"hypertidy","description":"Triangulation with CGAL (WIP)","archived":false,"fork":false,"pushed_at":"2022-11-01T00:22:39.000Z","size":6141,"stargazers_count":10,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-09T17:43:06.231Z","etag":null,"topics":["c-plus-plus","cgal","constrained-delaunay-triangulation","r","vertices"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypertidy.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-07T15:00:19.000Z","updated_at":"2022-11-04T12:48:13.000Z","dependencies_parsed_at":"2023-01-14T19:30:21.113Z","dependency_job_id":null,"html_url":"https://github.com/hypertidy/laridae","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hypertidy/laridae","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Flaridae","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Flaridae/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Flaridae/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Flaridae/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypertidy","download_url":"https://codeload.github.com/hypertidy/laridae/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertidy%2Flaridae/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262279177,"owners_count":23286550,"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":["c-plus-plus","cgal","constrained-delaunay-triangulation","r","vertices"],"created_at":"2025-05-14T23:12:09.767Z","updated_at":"2025-06-27T15:07:49.592Z","avatar_url":"https://github.com/hypertidy.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/hypertidy/laridae/workflows/R-CMD-check/badge.svg)](https://github.com/hypertidy/laridae/actions)\n\u003c!-- badges: end --\u003e\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\", \n  fig.width=12, fig.height=8\n)\n```\n\nWork in progress to get constrained and conforming Delaunay triangulation for shapes in R with CGAL. We have\n\n* point-only triangulation in `tri_xy()` - it's fast\n* segment-input constraints in `insert_mesh()` - only returns the vertices, which might include new points\n* constrained and conformal triangulations in-progress ...\n\nWe need: \n\n* export of new vertex pool and its edge- or triangle-based indices\n* proper inputs of nested polygon shapes\n* robust dealing with segment and polygon soups, so that numeric insertions are robust (and c.)\n\nWe can now hit this more easily thanks to [cgal4h](https://CRAN.R-project.org/package=cgal4h) thanks \nto Ahmadou Dicko. \n\n`laridae` came out of a need for constrained triangulation for a topology-in-R project. That effort has moved on somewhat, proving the case by using `RTriangle` and then bedding down the normalization model in the `hypertidy/silicate` package. \n\nR now has [cgal4h](https://cran.r-project.org/package=cgal4h) providing the library infrastructure for CGAL and [euclid](https:://github.com/thomasp85/euclid) providing numerically robust geometric primitives (it's unclear if laridae or whatever it becomes will use euclid). \n\nRTriangle is really fast, but it's not as fast as CGAL. CGAL can also be used to update a triangulation, which means (I think) that we could build an unconstrained triangulation from all the coordinates, and then add in any segments, even unclosed linear paths. At any rate, being able to update a mesh has a lot of applications, especially for neighbouring shapes, and for on-demand (extent or zoom dependent level of detail) tasks. \n\n\nThe interest (which seems miniscule ...) in constrained triangulations is discussed here along with the overall landscape in R. \n\nhttps://github.com/r-spatial/discuss/issues/6\n\n## Installation\n\n```R\nremotes::install_github(\"hypertidy/laridae\")\n## not universe ready yet\n#install.packages(\"laridae\", repos = \"https://hypertidy.r-universe.dev\")\n```\n\n## Triangulation\n\n\nTriangulate with CGAL via [laridae](https://github.com/hypertidy/laridae).  The function `tri_xy` performs an exact Delaunay triangulation on all vertices, returning a triplet-index for each triangle (zero-based in CGAL). \n\n\nThe variants `tri_xy1()` and `tri_xy2()` work slightly differently illustrating CGAL usage in C++ (thanks to Mark Padgham). 'xy1' order is not trivial ... but we ignore that for now. \n\n```{r triangle}\nlibrary(laridae)\nx \u003c- c(0, 0, 1)\ny \u003c- c(0, 1, 1)\nplot(x, y, pch = \"+\")\n(idx0 \u003c- tri_xy(x, y))\n(idx1 \u003c- tri_xy1(x, y))\n(idx2 \u003c- tri_xy2(x, y))\n\npolygon(cbind(x, y)[idx0, ])\n\nx    \u003c- c(2.3,3.0,7.0,1.0,3.0,8.0)\ny    \u003c- c(2.3,3.0,2.0,5.0,8.0,9.0)\nidx \u003c- tri_xy(x, y)\nplot(x, y, pch = \"+\", cex = 1.5)\npolygon(cbind(x, y)[rbind(matrix(idx, 3L), NA), ], lty = 3)\n\n```\n\nSome timings, to show we aren't wildly off-base and that CGAL wins for raw unconstrained Delaunay triangulation.  \n\n```{r}\nset.seed(90)\nx \u003c- rnorm(1e3, sd = 4)\ny \u003c- rnorm(1e3, sd = 2)\nlibrary(laridae)\n\n# plot a matrix xy as points\n# and add the triangulation indexed\n# by structural triplet row-identifiers\npoly_index \u003c- function(xy, index, ...) {\n  plot(xy, ...)\n  ## assume index is 0,1,2,0,1,2,0,1,...\n  ii \u003c- c(rbind(matrix(index, nrow = 3), NA_integer_))\n  ## have forgetten why polypath fails, so just use polygon\n  polygon(xy[ii, 1], xy[ii, 2])\n}\n\n\nps \u003c- RTriangle::pslg(P = cbind(x, y))\n\nmicrobenchmark::microbenchmark(\n  ind_t \u003c- tri_xy(x, y), \n  ind_t1 \u003c- tri_xy1(x, y), \n  ind_t2 \u003c- tri_xy2(x, y), \n  RT \u003c- RTriangle::triangulate(ps)\n)\nlength(ind_t)\nlength(ind_t1)\nlength(ind_t2)\nlength(RT$T)\n\n\np \u003c- par(mfrow = c(2, 2), mar = rep(0, 4))\npoly_index(cbind(x, y), ind_t, pch = \".\")\n## can't work as order is not aligned, but still fun\npoly_index(cbind(x, y), ind_t1, pch = \".\")  \npoly_index(cbind(x, y), ind_t2, pch = \".\")\nplot(RT)\npar(p)\n\n\n\n```\n\n## Constrained triangulation\n\nCurrently laridae only has vertex-output and \"reporting\" of the result. I can't yet see how to \n\n* get the vertex pool (it may have expanded given mesh properties, overlapping segments, etc.)\n* get the triangle index\n\nThe only other implementation in R is in RTriangle, so we use that for comparison. \n\n\n```{r mesh-input, echo=TRUE}\nsfx \u003c- silicate::inlandwaters\nsc \u003c- silicate::SC(sfx)\nX \u003c- sc$vertex$x_\nY \u003c- sc$vertex$y_\ni0 \u003c- match(sc$edge$.vx0, sc$vertex$vertex_)\ni1 \u003c- match(sc$edge$.vx1, sc$vertex$vertex_)\n\nsystem.time(insert_constraint(X, Y, i0 , i1))\nsystem.time(segment_constraint(sc))\n\n## insert_mesh actually returns the vertices (which might include new ones)\nsystem.time(xy_out \u003c- insert_mesh(X, Y, i0 , i1))\nplot(xy_out, pch = \".\")\n## compare RTriangle, it's fast if we don't include pslg() time\nps \u003c- RTriangle::pslg(cbind(X, Y), S = cbind(i0, i1))\nsystem.time({\n  tr \u003c- RTriangle::triangulate(ps, D = TRUE)\n})\n\n\nplot(tr$P, pch= \".\")\nsegments(tr$P[tr$E[,1],1], tr$P[tr$E[,1],2], \n         tr$P[tr$E[,2],1], tr$P[tr$E[,2],2])\n\nstr(tr)\n```\n\n\n\n## History\n\nWas originally called `cgalgris`. \n\n\n\n## Code of Conduct\n  \nPlease note that the laridae project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/1/0/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertidy%2Flaridae","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypertidy%2Flaridae","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertidy%2Flaridae/lists"}