CorentinTh/quadtree-js được TopGit xếp vào nhóm dự án frontend, với 82 sao trên GitHub, viết chủ yếu bằng TypeScript. A simple quadtree implementation for javascript and typescript (nodejs or browser).
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
// Create the bounding area of the quadtree (x, y, width, height)
const boundingArea = new Box(0, 0, 1000, 1000);
// Instantiate the new quadtree
const quadtree = new QuadTree(boundingArea);
You can also specify the following optional parameters:
// Create the bounding area of the quadtree (x, y, width, height)
const boundingArea = new Box(0, 0, 1000, 1000);
const config = {
capacity: 10, // Specify the maximum amount of point per node (default: 4)
removeEmptyNodes: true, // Specify if the quadtree has to remove subnodes if they are empty (default: false).
maximumDepth: 5, // Specify the maximum depth of the quadtree. -1 for no limit (default: -1).
// Specify a custom method to compare point for removal (default: (point1, point2) => point1.x === point2.x && point1.y === point2.y).
arePointsEqual: (point1, point2) => point1.data.foo === point2.data.foo
};
// An array of point to insert directly (same as quadtree.insert(points) )
const points = [new Point(10, 10), new Point(52, 64)];
const quadtree = new QuadTree(boundingArea, config, points);
Insert
You can insert a Point element, an array of Point element, your own element as long as it has an x and a y property or an array of custom element.
const point = new Point(10, 25);
const pointArray = [
new Point(45, 22),
new Point(30, 60),
new Point(14, 12)
];
const customPoint = {
x: 94,
y: 23,
customField:{}
};
quadtree.insert(point);
quadtree.insert(pointArray);
quadtree.insert(customPoint);
You can add your data in a Point element:
const myData = {
foo: 'bar'
};
const point = new Point(50, 50, myData);
console.log(point.data.foo); // 'bar'
Remove
As the insert method, you can remove a Point element, an array of Point element, your own element as long as it has an x and a y property or an array of custom element.
By default, points having the same x and y values will be removed. To override this behavior, add a method under arePointsEqual in the config of the quadtree that takes two points in parameters and return a boolean if the points are equal.
Example: const quadtree = new QuadTree(boundingArea, {arePointsEqual: (point1, point2) => point1.data.foo === point2.data.foo});
const point = new Point(10, 25);
const pointArray = [
new Point(45, 22),
new Point(30, 60),
new Point(14, 12)
];
const customPoint = {
x: 94,
y: 23
};
quadtree.remove(point);
quadtree.remove(pointArray);
quadtree.remove(customPoint);
Note: it doesn't have to be the same object, the test is done with the coordinates.
Query
Use the query method to get all the point within a range.
// This will return all the points in the given Box (x, y, width, height)
const points = quadtree.query(new Box(10, 10, 100, 100));
// This will return all the points in the given Circle (x, y, radius)
const points = quadtree.query(new Circle(10, 10, 100));
You can use a Box or a Circle as a range or even your own range element as long as it has the following methods:
contains: return true if a point is within this range, false otherwise.
intersects: return true if a Box intersects with this range, false otherwise.
See the Box definition for a good example.
Get all the point
If want to retrieve all the point, you can use this method:
const points = quadtree.getAllPoints();
Note: you may want to store your points in a side array since, it have to look trough all the child nodes.
Get Tree
You can get the amount of points by nodes with the getTree() method.
Có — CorentinTh/quadtree-js phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/CorentinTh/quadtree-js.
CorentinTh/quadtree-js là gì?
CorentinTh/quadtree-js (CorentinTh/quadtree-js) là dự án TypeScript trên GitHub. Theo mô tả gốc: A simple quadtree implementation for javascript and typescript (nodejs or browser).
CorentinTh/quadtree-js so với các dự án Frontend khác thế nào?
CorentinTh/quadtree-js được TopGit xếp vào nhóm Frontend, với 82 sao GitHub và viết bằng TypeScript. Xem trang chủ đề Frontend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Cùng nhóm Frontend còn repo nào?
CorentinTh/quadtree-js thuộc nhóm Frontend trên TopGit, cùng 9 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về CorentinTh/quadtree-js ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/CorentinTh/quadtree-js là nguồn chính thức.
Vì sao CorentinTh/quadtree-js được xếp vào nhóm Frontend?
TopGit xếp CorentinTh/quadtree-js vào nhóm Frontend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "intersects", "javascript", "js"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về quadtree-js?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về quadtree-js.