Skip to content

Commit

Permalink
Removing minDistance param from turf-shortest-path per this convo #25…
Browse files Browse the repository at this point in the history
…38 (comment) Changing options handling to not change the options object in place. Removing a couple of missed d.ts files.
  • Loading branch information
smallsaucepan committed Nov 27, 2023
1 parent 12f7452 commit 18f5a6e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 54 deletions.
3 changes: 1 addition & 2 deletions packages/turf-flip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ function flip<T extends AllGeoJSON>(
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
options.mutate = options.mutate || false;
const { mutate } = options;
const mutate = options.mutate || false;

if (!geojson) throw new Error("geojson is required");
// ensure that we don't modify features in-place and changes to the
Expand Down
11 changes: 0 additions & 11 deletions packages/turf-polygon-smooth/index.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/turf-rewind/index.d.ts

This file was deleted.

10 changes: 4 additions & 6 deletions packages/turf-rewind/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ import type { AllGeoJSON } from "@turf/helpers";
*/
function rewind<T extends AllGeoJSON>(
geojson: T,
options?: {
options: {
reverse?: boolean;
mutate?: boolean;
}
} = {}
): Geometry | Feature | FeatureCollection {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
options.mutate = options.mutate || false;
options.reverse = options.reverse || false;

const { reverse, mutate } = options;
const mutate = options.mutate || false;
const reverse = options.reverse || false;

// Prevent input mutation if requested.
if (!mutate) geojson = clone(geojson);
Expand Down
8 changes: 3 additions & 5 deletions packages/turf-sector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ function sector(
radius: number,
bearing1: number,
bearing2: number,
options?: {
options: {
steps?: number;
units?: Units;
properties?: GeoJsonProperties;
}
} = {}
): Feature<Polygon> {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
options.steps = options.steps || 64;
options.units = options.units || "kilometers";
// Most options only for passing through to circle()
const { properties } = options;
const properties = options.properties;

// validation
if (!center) throw new Error("center is required");
Expand Down
15 changes: 4 additions & 11 deletions packages/turf-shortest-path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { Graph, GridNode, astar } from "./lib/javascript-astar";
* @param {Coord} end point
* @param {Object} [options={}] optional parameters
* @param {Geometry|Feature|FeatureCollection<Polygon>} [options.obstacles] areas which path cannot travel
* @param {number} [options.minDistance] minimum distance between shortest path and obstacles
* @param {string} [options.units='kilometers'] unit in which resolution & minimum distance will be expressed in; it can be degrees, radians, miles, kilometers, ...
* @param {number} [options.resolution=100] distance between matrix points on which the path will be calculated
* @returns {Feature<LineString>} shortest path between start and end
Expand All @@ -53,29 +52,23 @@ import { Graph, GridNode, astar } from "./lib/javascript-astar";
function shortestPath(
start: Coord,
end: Coord,
options?: {
options: {
obstacles?: Polygon | Feature<Polygon> | FeatureCollection<Polygon>;
minDistance?: number;
units?: Units;
resolution?: number;
}
} = {}
): Feature<LineString> {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
options.obstacles = options.obstacles || featureCollection([]);
options.units = options.units || "kilometers";
options.resolution = options.resolution || 100;
const { minDistance } = options;
let { obstacles, resolution } = options;
let obstacles = options.obstacles || featureCollection([]);
let resolution = options.resolution || 100;

// validation
if (!start) throw new Error("start is required");
if (!end) throw new Error("end is required");
if (resolution && (!isNumber(resolution) || resolution <= 0))
throw new Error("options.resolution must be a number, greater than 0");
if (minDistance)
throw new Error("options.minDistance is not yet implemented");

// Normalize Inputs
const startCoord = getCoord(start);
Expand Down
12 changes: 5 additions & 7 deletions packages/turf-simplify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,18 @@ import simplifyJS from "./lib/simplify";
*/
function simplify<T extends AllGeoJSON>(
geojson: T,
options?: {
options: {
tolerance?: number;
highQuality?: boolean;
mutate?: boolean;
}
} = {}
): T {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
options.tolerance = options.tolerance !== undefined ? options.tolerance : 1;
options.highQuality = options.highQuality || false;
options.mutate = options.mutate || false;

const { tolerance, highQuality, mutate } = options;
const tolerance = options.tolerance !== undefined ? options.tolerance : 1;
const highQuality = options.highQuality || false;
const mutate = options.mutate || false;

if (!geojson) throw new Error("geojson is required");
if (tolerance && tolerance < 0) throw new Error("invalid tolerance");
Expand Down

0 comments on commit 18f5a6e

Please sign in to comment.