(polygon, number, coordinates_number, max_distance)
| 37 | |
| 38 | // Generate random coordinate points within a polygon boundary for route testing |
| 39 | function generate_points(polygon, number, coordinates_number, max_distance) { |
| 40 | const query_points = []; |
| 41 | while (query_points.length < number) { |
| 42 | let points = []; |
| 43 | |
| 44 | while(points.length < coordinates_number) { |
| 45 | const chunk = turf |
| 46 | .randomPoint(coordinates_number, { bbox: turf.bbox(polygon)}) |
| 47 | .features |
| 48 | .map(x => x.geometry.coordinates) |
| 49 | .filter(pt => turf.booleanPointInPolygon(turf.point(pt), polygon)); |
| 50 | |
| 51 | if (max_distance > 0) |
| 52 | { |
| 53 | chunk.forEach(pt => { |
| 54 | if (points.length == 0) |
| 55 | { |
| 56 | points.push(pt); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | const distance = turf.distance(pt, points[points.length-1], 'meters'); |
| 61 | if (distance < max_distance) |
| 62 | { |
| 63 | points.push(pt); |
| 64 | } |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | points = points.concat(chunk); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | query_points.push(points); |
| 75 | } |
| 76 | |
| 77 | return query_points; |
| 78 | } |
| 79 | |
| 80 | // Convert coordinate points into OSRM API query URLs |
| 81 | function generate_queries(options, query_points) { |
no test coverage detected