Skip to content

Commit 670f9b6

Browse files
committed
Version 5.2.0.
1 parent e8ab77d commit 670f9b6

File tree

10 files changed

+13265
-11382
lines changed

10 files changed

+13265
-11382
lines changed

build/sparse-octree.js

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* sparse-octree v5.1.1 build Wed Feb 06 2019
2+
* sparse-octree v5.2.0 build Mon Feb 11 2019
33
* https://github.com/vanruesc/sparse-octree
44
* Copyright 2019 Raoul van Rüschen, Zlib
55
*/
@@ -5143,81 +5143,101 @@
51435143
}
51445144

51455145
function _findNearestPoint(point, maxDistance, skipSelf, octant) {
5146-
var points = octant.points;
5147-
var children = octant.children;
51485146
var result = null;
5149-
var bestDist = maxDistance;
5147+
var bestDistance = maxDistance;
51505148
var i, l;
5151-
var p, distSq;
5152-
var sortedChildren;
5153-
var child, childResult;
51545149

5155-
if (children !== null) {
5156-
sortedChildren = children.map(function (child) {
5150+
if (octant.children !== null) {
5151+
var sortedChildren = octant.children.map(function (child) {
51575152
return {
51585153
octant: child,
51595154
distance: child.distanceToCenterSquared(point)
51605155
};
51615156
}).sort(function (a, b) {
51625157
return a.distance - b.distance;
51635158
});
5159+
var child, intermediateResult;
51645160

51655161
for (i = 0, l = sortedChildren.length; i < l; ++i) {
51665162
child = sortedChildren[i].octant;
51675163

5168-
if (child.contains(point, bestDist)) {
5169-
childResult = _findNearestPoint(point, bestDist, skipSelf, child);
5164+
if (child.contains(point, bestDistance)) {
5165+
intermediateResult = _findNearestPoint(point, bestDistance, skipSelf, child);
51705166

5171-
if (childResult !== null) {
5172-
distSq = childResult.point.distanceToSquared(point);
5167+
if (intermediateResult !== null) {
5168+
bestDistance = intermediateResult.distance;
5169+
result = intermediateResult;
51735170

5174-
if ((!skipSelf || distSq > 0.0) && distSq < bestDist) {
5175-
bestDist = distSq;
5176-
result = childResult;
5171+
if (bestDistance === 0.0) {
5172+
break;
51775173
}
51785174
}
51795175
}
51805176
}
5181-
} else if (points !== null) {
5177+
} else if (octant.points !== null) {
5178+
var points = octant.points;
5179+
var index = -1;
5180+
var distance;
5181+
51825182
for (i = 0, l = points.length; i < l; ++i) {
5183-
p = points[i];
5184-
distSq = point.distanceToSquared(p);
5183+
if (points[i].equals(point)) {
5184+
if (!skipSelf) {
5185+
bestDistance = 0.0;
5186+
index = i;
5187+
break;
5188+
}
5189+
} else {
5190+
distance = point.distanceTo(points[i]);
51855191

5186-
if ((!skipSelf || distSq > 0.0) && distSq < bestDist) {
5187-
bestDist = distSq;
5188-
result = {
5189-
point: p.clone(),
5190-
data: octant.data[i]
5191-
};
5192+
if (distance < bestDistance) {
5193+
bestDistance = distance;
5194+
index = i;
5195+
}
51925196
}
51935197
}
5198+
5199+
if (index >= 0) {
5200+
result = {
5201+
point: points[index],
5202+
data: octant.data[index],
5203+
distance: bestDistance
5204+
};
5205+
}
51945206
}
51955207

51965208
return result;
51975209
}
51985210

51995211
function _findPoints(point, radius, skipSelf, octant, result) {
5200-
var points = octant.points;
52015212
var children = octant.children;
5202-
var rSq = radius * radius;
52035213
var i, l;
5204-
var p, distSq;
5205-
var child;
52065214

52075215
if (children !== null) {
5216+
var child;
5217+
52085218
for (i = 0, l = children.length; i < l; ++i) {
52095219
child = children[i];
52105220

52115221
if (child.contains(point, radius)) {
52125222
_findPoints(point, radius, skipSelf, child, result);
52135223
}
52145224
}
5215-
} else if (points !== null) {
5225+
} else if (octant.points !== null) {
5226+
var points = octant.points;
5227+
var rSq = radius * radius;
5228+
var p;
5229+
52165230
for (i = 0, l = points.length; i < l; ++i) {
52175231
p = points[i];
5218-
distSq = point.distanceToSquared(p);
52195232

5220-
if ((!skipSelf || distSq > 0.0) && distSq <= rSq) {
5233+
if (p.equals(point)) {
5234+
if (!skipSelf) {
5235+
result.push({
5236+
point: p.clone(),
5237+
data: octant.data[i]
5238+
});
5239+
}
5240+
} else if (p.distanceToSquared(point) <= rSq) {
52215241
result.push({
52225242
point: p.clone(),
52235243
data: octant.data[i]
@@ -5278,7 +5298,14 @@
52785298
value: function findNearestPoint(point) {
52795299
var maxDistance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
52805300
var skipSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5281-
return _findNearestPoint(point, maxDistance, skipSelf, this.root);
5301+
5302+
var result = _findNearestPoint(point, maxDistance, skipSelf, this.root);
5303+
5304+
if (result !== null) {
5305+
result.point = result.point.clone();
5306+
}
5307+
5308+
return result;
52825309
}
52835310
}, {
52845311
key: "findPoints",

build/sparse-octree.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sparse-octree",
3-
"version": "5.1.1",
3+
"version": "5.2.0",
44
"description": "A sparse octree data structure.",
55
"homepage": "https://github.com/vanruesc/sparse-octree",
66
"main": "build/sparse-octree.js",

public/demo/index.js

Lines changed: 59 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/demo/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)