Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buildSpatialIndices() {
this.nodesIndex = new KDBush(this.nodes, p => p.position.x, p => p.position.y);
}
const setPoints = newPoints => {
isInit = false;
numPoints = newPoints.length;
stateTex = createStateTexture(newPoints);
normalPointsIndexBuffer({
usage: 'static',
type: 'float',
data: createPointIndex(numPoints)
});
searchIndex = new KDBush(newPoints, p => p[0], p => p[1], 16);
isInit = true;
};
addFeatures (features) {
this.features = this.features.concat(features);
this.originData = kdbush(this.features, (p) => p.getGeometry().getCoordinates()[0], (p) => p.getGeometry().getCoordinates()[1]);
}
async _getPossibleSnapPoints(x, y) {
const snapPoints = await this._getAllSnapPoints();
let possibleSnapPoints;
if (snapPoints.length < 2) {
possibleSnapPoints = snapPoints;
} else {
if (this._snapPointsIndex === null) {
this._snapPointsIndex = kdbush(
snapPoints,
p => p.x,
p => p.y,
64,
Int32Array,
);
}
const pointsWithinSnapDistance = this._snapPointsIndex
.within(x, y, SNAP_DISTANCE)
.map(id => snapPoints[id]);
if (pointsWithinSnapDistance.length > 0) {
const closestPoint = _minBy(
pointsWithinSnapDistance,
point => distance(x, y, point.x, point.y),
addFeatures (features) {
this.features = this.features.concat(features);
this.originData = kdbush(this.features, (p) => p.getGeometry().getCoordinates()[0], (p) => p.getGeometry().getCoordinates()[1]);
}
function forceMove() {
var before = getGraphBBox();
const points = new KDBush(nodeArr, p => p.x, p => p.y);
nodeArr.forEach((pos, idx) => {
var sx = 0, sy = 0, count = 0;
var neighbors = points.within(pos.x, pos.y, edgeLength/2);
neighbors.forEach(otherIndex => {
if (otherIndex === idx) return;
var other = nodeArr[otherIndex];
var dx = pos.x - other.x;
var dy = pos.y - other.y;
var l = Math.sqrt(dx * dx + dy * dy);
if (l < 1e-10) l = 1;
var tR = 1;
pos.incX += pos.x + k4 * (edgeLength - l) * dx/l * tR;
pos.incY += pos.y + k4 * (edgeLength - l) * dy/l * tR;
pos.incLength += 1;