mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
Add faster kdtree initialization method.
This commit is contained in:
parent
2fbd3f6007
commit
1691f265e9
1 changed files with 16 additions and 0 deletions
16
vendor/kdtree/core.js
vendored
16
vendor/kdtree/core.js
vendored
|
@ -176,9 +176,25 @@ goog.scope(function() {
|
|||
return tree;
|
||||
};
|
||||
|
||||
function initialize(tree, width, height, widthStep, heightStep) {
|
||||
const totalSize = Math.floor((width/widthStep) * (height/heightStep));
|
||||
const points = new Array(totalSize);
|
||||
let pos = 0;
|
||||
|
||||
for (let i = 0; i <= width; i += widthStep){
|
||||
for (let z = 0; z <= height; z += heightStep){
|
||||
points[pos++] = [i, z];
|
||||
}
|
||||
}
|
||||
|
||||
tree.initialize(points);
|
||||
return tree;
|
||||
}
|
||||
|
||||
// Types
|
||||
kdtree.core.KDTree = KDTree;
|
||||
|
||||
// Factory functions
|
||||
kdtree.core.create = create;
|
||||
kdtree.core.initialize = initialize;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue