Skip to content

Commit

Permalink
Merge branch 'master' into spherical-calc-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
smallsaucepan authored Sep 22, 2024
2 parents 4cac6cd + f4a00b2 commit 3aa07ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 11 additions & 10 deletions packages/turf-random/bench.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// I don't think this bench test does anything? There is no entry point into
// the module called random() that takes a string?
import Benchmark, { Event } from "benchmark";
import { randomPolygon } from "./index.js";

import { random } from "./index.js";
import Benchmark from "benchmark";
let totalTime = 0.0;
const suite = new Benchmark.Suite("turf-random");

var suite = new Benchmark.Suite("turf-random");
suite
.add("turf-random", function () {
random("point");
})
.on("cycle", function (event) {
console.log(String(event.target));
.add("turf-random", () => randomPolygon(1, { num_vertices: 100000 }), {
onComplete: (e: Event) =>
(totalTime = totalTime += e.target.times?.elapsed),
})
.on("cycle", (e: Event) => console.log(String(e.target)))
.on("complete", () =>
console.log(`completed in ${totalTime.toFixed(2)} seconds`)
)
.run();
12 changes: 6 additions & 6 deletions packages/turf-random/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ function randomPolygon(

const features = [];
for (let i = 0; i < count; i++) {
let vertices: any[] = [];
let vertices: number[][] = [];
const circleOffsets = [...Array(options.num_vertices + 1)].map(Math.random);

// Sum Offsets
circleOffsets.forEach((cur: any, index: number, arr: any[]) => {
circleOffsets.forEach((cur, index, arr) => {
arr[index] = index > 0 ? cur + arr[index - 1] : cur;
});

// scaleOffsets
circleOffsets.forEach((cur: any) => {
circleOffsets.forEach((cur) => {
cur = (cur * 2 * Math.PI) / circleOffsets[circleOffsets.length - 1];
const radialScaler = Math.random();
vertices.push([
Expand All @@ -165,9 +165,9 @@ function randomPolygon(
vertices[vertices.length - 1] = vertices[0]; // close the ring

// center the polygon around something
vertices = vertices.map(
vertexToCoordinate(randomPositionUnchecked(paddedBbox))
);
vertices = vertices
.reverse() // Make counter-clockwise to adhere to right hand rule.
.map(vertexToCoordinate(randomPositionUnchecked(paddedBbox)));
features.push(polygon([vertices]));
}
return featureCollection(features);
Expand Down

0 comments on commit 3aa07ee

Please sign in to comment.