0
Fork 0
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:
Andrey Antukh 2016-06-11 15:45:46 +03:00
parent 2fbd3f6007
commit 1691f265e9
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

16
vendor/kdtree/core.js vendored
View file

@ -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;
});