{"id":17091407,"url":"https://github.com/jhurliman/kdtreepp","last_synced_at":"2025-06-22T11:36:03.981Z","repository":{"id":66019682,"uuid":"333322689","full_name":"jhurliman/kdtreepp","owner":"jhurliman","description":"k-d tree for C++ and Eigen","archived":false,"fork":false,"pushed_at":"2021-02-12T00:48:23.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T16:14:20.454Z","etag":null,"topics":["cpp17-library","eigen","kdtree"],"latest_commit_sha":null,"homepage":"","language":"CMake","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/jhurliman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-01-27T06:14:06.000Z","updated_at":"2023-08-10T21:45:32.000Z","dependencies_parsed_at":"2023-04-11T10:26:38.693Z","dependency_job_id":null,"html_url":"https://github.com/jhurliman/kdtreepp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jhurliman/kdtreepp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fkdtreepp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fkdtreepp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fkdtreepp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fkdtreepp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhurliman","download_url":"https://codeload.github.com/jhurliman/kdtreepp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fkdtreepp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261288773,"owners_count":23136042,"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":["cpp17-library","eigen","kdtree"],"created_at":"2024-10-14T13:58:32.986Z","updated_at":"2025-06-22T11:35:58.961Z","avatar_url":"https://github.com/jhurliman.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kdtreepp\n\n### A C++ k-d tree implementation\n\n[![Build Status](https://travis-ci.com/jhurliman/kdtreepp.svg?branch=main)](https://travis-ci.com/jhurliman/kdtreepp)\n[![codecov](https://codecov.io/gh/jhurliman/kdtreepp/branch/main/graph/badge.svg)](https://codecov.io/gh/jhurliman/kdtreepp)\n\n## Usage\n\n### Search for the closest 3D point\n\n```cpp\n#include \u003cEigen/StdVector\u003e\n#include \u003ciostream\u003e\n#include \u003crandom\u003e\n#include \u003cvector\u003e\n\n#include \"kdtreepp.hpp\"\n\nusing Vector3 = Eigen::Vector3d;\nusing AlignedBox3 = Eigen::AlignedBox3d;\n\nint main() {\n  std::vector\u003cVector3, Eigen::aligned_allocator\u003cVector3\u003e\u003e points;\n  std::mt19937_64 randGen{size_t(42)};\n  std::uniform_real_distribution\u003cdouble\u003e dist{-1000.0, 1000.0};\n\n  // Make random points\n  points.resize(size_t(5000));\n  for (auto\u0026 point : points) {\n    point \u003c\u003c dist(randGen), dist(randGen), dist(randGen);\n  }\n\n  // Construct a k-d tree from 3d points\n  const auto node = kdtreepp::MakeEigenKdTreeNode\u003cdouble, 3\u003e(\n      points.begin(), points.end(), [](const Vector3\u0026 p) { return p; },\n      [](const Vector3\u0026 p) { return p; });\n\n  // Create a random query point\n  const Vector3 queryPoint{dist(randGen), dist(randGen), dist(randGen)};\n\n  // Find the closest point to the given query point\n  double minDistSq = std::numeric_limits\u003cdouble\u003e::max();\n  Vector3 closestPoint;\n  node.visit(\n      [\u0026minDistSq, queryPoint](const AlignedBox3\u0026 bounds) {\n        return bounds.squaredExteriorDistance(queryPoint) \u003c minDistSq;\n      },\n      [\u0026minDistSq, \u0026closestPoint, queryPoint](const Vector3\u0026 point) {\n        const double rSq = (point - queryPoint).squaredNorm();\n        if (rSq \u003c minDistSq) {\n          minDistSq = rSq;\n          closestPoint = point;\n        }\n      });\n\n  std::cout \u003c\u003c \"Closest point to \" \u003c\u003c queryPoint \u003c\u003c \" is \" \u003c\u003c closestPoint \u003c\u003c \"\\n\";\n}\n```\n\n## Test\n\n```shell\n# build test binaries\nmake\n\n# run tests\nmake test\n\n# run bench tests\nmake bench\n```\n\nThe default test binaries will be built in release mode. You can make Debug test binaries as well:\n\n```shell\nmake clean\nmake debug\nmake test\n```\n\nEnable additional sanitizers to catch hard-to-find bugs, for example:\n\n```shell\nexport LDFLAGS=\"-fsanitize=address,undefined\"\nexport CXXFLAGS=\"-fsanitize=address,undefined\"\n\nmake\n```\n\n# License\n\nkdtreepp is licensed under [MIT](https://opensource.org/licenses/MIT).\n\nMade with [hpp-skel](https://github.com/mapbox/hpp-skel).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurliman%2Fkdtreepp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhurliman%2Fkdtreepp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurliman%2Fkdtreepp/lists"}