Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'kdbush' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function makeShapes (props) {
Random.setSeed(config.seed);
const count = config.count;
points = Array.from(new Array(count)).map(() => {
const center = [ width / 2, height / 2 ];
const radius = width * config.radius;
return vec2.add([], center, Random.insideCircle(radius));
});
const index = kdbush(points);
lines.length = 0;
edges.length = 0;
const ignorePoints = [];
points.forEach(point => {
// skip some targets entirely
if (Random.chance(config.skipChance)) return;
const stepCount = config.stepCount;
let curPoint = point;
let steps = [ curPoint ];
for (let i = 0; i < stepCount; i++) {
const previous = steps.length > 1 ? steps[i - 1] : null;
const next = walk(index, curPoint, previous, ignorePoints);
if (!next) break;
curPoint = next;
function generate () {
Random.setSeed(config.seed);
stars = Array.from(new Array(config.starCount)).map(() => {
return {
position: vec2.add([], Random.insideCircle(config.mapSize), [ width / 2, height / 2 ]),
walked: false,
radius: Math.abs(Random.gaussian(config.starSizeMean, config.starSizeDeviation))
};
});
// spatial index of all stars
index = kdbush(stars.map(p => p.position));
const maxConstellations = Math.floor(stars.length * config.nConstellations);
const targets = Random.shuffle(stars).slice(0, maxConstellations);
// for each point, walk to others around it
constellations = targets.map(initialStar => {
const stepCount = config.stepCount;
let maxSteps = stepCount + Math.trunc(Random.gaussian(0, 3));
let currentStar = initialStar;
const steps = [ currentStar ];
const minDegree = 0;
const maxDegree = 40;
const minSearchDist = config.minSearchDist;
const constellationSearchRadius = Math.max(0, config.searchRadius + Random.gaussian(0, 0.1));
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;