From 1691f265e986658d82df48f2862f6cbc6bff564d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 11 Jun 2016 15:45:46 +0300 Subject: [PATCH] Add faster kdtree initialization method. --- vendor/kdtree/core.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vendor/kdtree/core.js b/vendor/kdtree/core.js index cfce40563..f3d8481d7 100644 --- a/vendor/kdtree/core.js +++ b/vendor/kdtree/core.js @@ -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; });