-
Notifications
You must be signed in to change notification settings - Fork 991
Open
Description
It seems to be related to the fact that the previous angle variable is actually a local variable of the inner loop over the vertices so that it is incorrectly reset at each vertex. Here is a suggested modification of the code, which also appears to be more simple:
for (var i = 0; i < count; i++) {
var startingPoint = turf.randomPosition(bbox);
var vertices = [startingPoint];
var priorAngle = Math.random() * 2 * Math.PI;
for (var j = 0; j < num_vertices - 1; j++) {
var angle = priorAngle + (Math.random() - 0.5) * max_rotation * 2;
priorAngle = angle;
var distance = Math.random() * max_length;
vertices.push([
vertices[j][0] + distance * Math.cos(angle),
vertices[j][1] + distance * Math.sin(angle),
]);
}
features.push(turf.lineString(vertices));
}
I would be pleased to try to create a PR if you think this fix is correct, althought it might take some time to me for a first contribution to study how to write a relevent test, update the build, etc.
Metadata
Metadata
Assignees
Labels
No labels