Skip to content

Commit

Permalink
Update dependencies, update KDTree
Browse files Browse the repository at this point in the history
  • Loading branch information
havfo committed Nov 4, 2023
1 parent 2a6a108 commit aa97d00
Show file tree
Hide file tree
Showing 5 changed files with 1,008 additions and 1,256 deletions.
1 change: 1 addition & 0 deletions lib/KDTree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export declare class KDTree {
constructor(points: KDPoint[], k?: number);
buildTree(points: KDPoint[], depth?: number): KDNode | undefined;
private distance;
getAllPoints(): KDPoint[];
addNode(point: KDPoint, node?: KDNode | undefined, depth?: number): void;
removeNodeByFilter(filter: (point: KDPoint) => boolean): boolean;
private findNodeByFilter;
Expand Down
12 changes: 12 additions & 0 deletions lib/KDTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ class KDTree {
return Math.sqrt(a.position.reduce((acc, cur, i) => acc + (Math.pow((cur - b.position[i]), 2)), 0));
}
}
getAllPoints() {
const points = [];
const traverse = (node) => {
if (!node)
return;
points.push(node.kdPoint);
traverse(node.left);
traverse(node.right);
};
traverse(this.root);
return points;
}
addNode(point, node = this.root, depth = 0) {
const axis = depth % this.k;
if (!node) {
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edumeet-common",
"version": "0.6.0",
"version": "0.6.1",
"description": "Common code for edumeet",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -15,20 +15,19 @@
},
"dependencies": {
"debug": "^4.3.4",
"socket.io-client": "^4.6.1",
"socket.io-server": "^1.0.0-b",
"typescript": "^5.0.2"
"socket.io-client": "^4.7.2",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/events": "^3.0.0",
"@types/node": "^18.15.3",
"@types/debug": "^4.1.10",
"@types/events": "^3.0.2",
"@types/node": "^20.8.10",
"husky": "^8.0.3",
"eslint": "^8.34.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@types/jest": "^29.4.0",
"jest": "^29.4.3",
"ts-jest": "^29.0.5"
"eslint": "^8.53.0",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@types/jest": "^29.5.7",
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
}
}
17 changes: 17 additions & 0 deletions src/KDTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ export class KDTree {
}
}

public getAllPoints(): KDPoint[] {
const points: KDPoint[] = [];

const traverse = (node?: KDNode) => {
if (!node) return;

points.push(node.kdPoint);

traverse(node.left);
traverse(node.right);
};

traverse(this.root);

return points;
}

public addNode(point: KDPoint, node: KDNode | undefined = this.root, depth = 0): void {
const axis = depth % this.k;

Expand Down
Loading

0 comments on commit aa97d00

Please # to comment.