@turf/transform-scale 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,17 +11,14 @@ var _helpers = require('@turf/helpers');
11
11
  var _invariant = require('@turf/invariant');
12
12
  function transformScale(geojson, factor, options) {
13
13
  options = options || {};
14
- if (!_helpers.isObject.call(void 0, options))
15
- throw new Error("options is invalid");
14
+ if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
16
15
  const origin = options.origin || "centroid";
17
16
  const mutate = options.mutate || false;
18
- if (!geojson)
19
- throw new Error("geojson required");
17
+ if (!geojson) throw new Error("geojson required");
20
18
  if (typeof factor !== "number" || factor <= 0)
21
19
  throw new Error("invalid factor");
22
20
  const originIsPoint = Array.isArray(origin) || typeof origin === "object";
23
- if (mutate !== true)
24
- geojson = _clone.clone.call(void 0, geojson);
21
+ if (mutate !== true) geojson = _clone.clone.call(void 0, geojson);
25
22
  if (geojson.type === "FeatureCollection" && !originIsPoint) {
26
23
  _meta.featureEach.call(void 0, geojson, function(feature, index) {
27
24
  geojson.features[index] = scale(
@@ -37,8 +34,7 @@ function transformScale(geojson, factor, options) {
37
34
  function scale(feature, factor, origin) {
38
35
  const isPoint = _invariant.getType.call(void 0, feature) === "Point";
39
36
  const originCoord = defineOrigin(feature, origin);
40
- if (factor === 1 || isPoint)
41
- return feature;
37
+ if (factor === 1 || isPoint) return feature;
42
38
  _meta.coordEach.call(void 0, feature, function(coord) {
43
39
  const originalDistance = _rhumbdistance.rhumbDistance.call(void 0, originCoord, coord);
44
40
  const bearing = _rhumbbearing.rhumbBearing.call(void 0, originCoord, coord);
@@ -48,15 +44,13 @@ function scale(feature, factor, origin) {
48
44
  );
49
45
  coord[0] = newCoord[0];
50
46
  coord[1] = newCoord[1];
51
- if (coord.length === 3)
52
- coord[2] *= factor;
47
+ if (coord.length === 3) coord[2] *= factor;
53
48
  });
54
49
  delete feature.bbox;
55
50
  return feature;
56
51
  }
57
52
  function defineOrigin(geojson, origin) {
58
- if (origin === void 0 || origin === null)
59
- origin = "centroid";
53
+ if (origin === void 0 || origin === null) origin = "centroid";
60
54
  if (Array.isArray(origin) || typeof origin === "object")
61
55
  return _invariant.getCoord.call(void 0, origin);
62
56
  const bbox = geojson.bbox ? geojson.bbox : _bbox.bbox.call(void 0, geojson, { recompute: true });
@@ -66,23 +60,35 @@ function defineOrigin(geojson, origin) {
66
60
  const north = bbox[3];
67
61
  switch (origin) {
68
62
  case "sw":
63
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
69
64
  case "southwest":
65
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
70
66
  case "westsouth":
67
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
71
68
  case "bottomleft":
72
69
  return _helpers.point.call(void 0, [west, south]);
73
70
  case "se":
71
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
74
72
  case "southeast":
73
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
75
74
  case "eastsouth":
75
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
76
76
  case "bottomright":
77
77
  return _helpers.point.call(void 0, [east, south]);
78
78
  case "nw":
79
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
79
80
  case "northwest":
81
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
80
82
  case "westnorth":
83
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
81
84
  case "topleft":
82
85
  return _helpers.point.call(void 0, [west, north]);
83
86
  case "ne":
87
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
84
88
  case "northeast":
89
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
85
90
  case "eastnorth":
91
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
86
92
  case "topright":
87
93
  return _helpers.point.call(void 0, [east, north]);
88
94
  case "center":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAEA,SAAS,aAAa;AACtB,SAAS,cAAc;AAC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geojson\";\nimport { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale GeoJSON objects from a given point by a scaling factor e.g. factor=2\n * would make each object 200% larger.\n * If a FeatureCollection is provided, the origin point will be calculated\n * based on each individual feature _unless_ an exact\n *\n * @name transformScale\n * @param {GeoJSON|GeometryCollection} geojson objects to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {Corners|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance improvement if true)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * const addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n factor: number,\n options?: {\n origin?: Corners | Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const origin = options.origin || \"centroid\";\n const mutate = options.mutate || false;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n const originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately if a feature collection AND the user didn't\n // pass a single explicit point to scale the whole collection from.\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n // The type guard above is not recognised in the callback so we have to\n // cast to accept responsibility.\n (geojson as FeatureCollection).features[index] = scale(\n feature,\n factor,\n origin\n );\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {GeoJSON|GeometryCollection} feature feature or geometry collection to scale\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {Corners|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON Feature/Geometry\n */\nfunction scale<T extends GeoJSON | GeometryCollection>(\n feature: T,\n factor: number,\n origin: Corners | Coord\n): T {\n // Default params\n const isPoint = getType(feature) === \"Point\";\n // Work with a Coord equivalent of the origin from here on.\n const originCoord: Coord = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n const originalDistance = rhumbDistance(originCoord, coord);\n const bearing = rhumbBearing(originCoord, coord);\n const newDistance = originalDistance * factor;\n const newCoord = getCoords(\n rhumbDestination(originCoord, newDistance, bearing)\n );\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON|GeometryCollection} geojson GeoJSON\n * @param {Corners|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(\n geojson: GeoJSON | GeometryCollection,\n origin: Corners | Coord\n): Coord {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n const bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recompute: true });\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n // Having to disable eslint below for lines which fail the no-fallthrough\n // rule, though only because of the ts-expect-error rules. Once we remove\n // southeast, bottomright, rightbottom, etc we should be able to remove all\n // these supressions.\n /* eslint-disable no-fallthrough */\n switch (origin) {\n case \"sw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n /* eslint-enable no-fallthrough */\n}\n\nexport { transformScale };\nexport default transformScale;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-transform-scale/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACEA,oCAAsB;AACtB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AA;AAAA,IACzB,OAAA;AACE,MAAA,MAAM,IAAI,KAAA,CAAM,gBAAgB,CAAA;AAAA,EACpC;AAEF;AAGA,IAAO,6BAAA,EAAQ,cAAA;AD1Ff;AACE;AACA;AACF,wFAAC","file":"/home/runner/work/turf/turf/packages/turf-transform-scale/dist/cjs/index.cjs","sourcesContent":[null,"import { Corners, Coord } from \"@turf/helpers\";\nimport { FeatureCollection, GeoJSON, GeometryCollection } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale GeoJSON objects from a given point by a scaling factor e.g. factor=2\n * would make each object 200% larger.\n * If a FeatureCollection is provided, the origin point will be calculated\n * based on each individual feature _unless_ an exact\n *\n * @function\n * @param {GeoJSON|GeometryCollection} geojson objects to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {Corners|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance improvement if true)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * const addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n factor: number,\n options?: {\n origin?: Corners | Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const origin = options.origin || \"centroid\";\n const mutate = options.mutate || false;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n const originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately if a feature collection AND the user didn't\n // pass a single explicit point to scale the whole collection from.\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n // The type guard above is not recognised in the callback so we have to\n // cast to accept responsibility.\n (geojson as FeatureCollection).features[index] = scale(\n feature,\n factor,\n origin\n );\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {GeoJSON|GeometryCollection} feature feature or geometry collection to scale\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {Corners|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON Feature/Geometry\n */\nfunction scale<T extends GeoJSON | GeometryCollection>(\n feature: T,\n factor: number,\n origin: Corners | Coord\n): T {\n // Default params\n const isPoint = getType(feature) === \"Point\";\n // Work with a Coord equivalent of the origin from here on.\n const originCoord: Coord = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n const originalDistance = rhumbDistance(originCoord, coord);\n const bearing = rhumbBearing(originCoord, coord);\n const newDistance = originalDistance * factor;\n const newCoord = getCoords(\n rhumbDestination(originCoord, newDistance, bearing)\n );\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON|GeometryCollection} geojson GeoJSON\n * @param {Corners|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(\n geojson: GeoJSON | GeometryCollection,\n origin: Corners | Coord\n): Coord {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n const bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recompute: true });\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n // Having to disable eslint below for lines which fail the no-fallthrough\n // rule, though only because of the ts-expect-error rules. Once we remove\n // southeast, bottomright, rightbottom, etc we should be able to remove all\n // these supressions.\n /* eslint-disable no-fallthrough */\n switch (origin) {\n case \"sw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n /* eslint-enable no-fallthrough */\n}\n\nexport { transformScale };\nexport default transformScale;\n"]}
@@ -7,7 +7,7 @@ import { GeoJSON, GeometryCollection } from 'geojson';
7
7
  * If a FeatureCollection is provided, the origin point will be calculated
8
8
  * based on each individual feature _unless_ an exact
9
9
  *
10
- * @name transformScale
10
+ * @function
11
11
  * @param {GeoJSON|GeometryCollection} geojson objects to be scaled
12
12
  * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
13
13
  * @param {Object} [options={}] Optional parameters
@@ -7,7 +7,7 @@ import { GeoJSON, GeometryCollection } from 'geojson';
7
7
  * If a FeatureCollection is provided, the origin point will be calculated
8
8
  * based on each individual feature _unless_ an exact
9
9
  *
10
- * @name transformScale
10
+ * @function
11
11
  * @param {GeoJSON|GeometryCollection} geojson objects to be scaled
12
12
  * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.
13
13
  * @param {Object} [options={}] Optional parameters
package/dist/esm/index.js CHANGED
@@ -11,17 +11,14 @@ import { point, isObject } from "@turf/helpers";
11
11
  import { getCoord, getCoords, getType } from "@turf/invariant";
12
12
  function transformScale(geojson, factor, options) {
13
13
  options = options || {};
14
- if (!isObject(options))
15
- throw new Error("options is invalid");
14
+ if (!isObject(options)) throw new Error("options is invalid");
16
15
  const origin = options.origin || "centroid";
17
16
  const mutate = options.mutate || false;
18
- if (!geojson)
19
- throw new Error("geojson required");
17
+ if (!geojson) throw new Error("geojson required");
20
18
  if (typeof factor !== "number" || factor <= 0)
21
19
  throw new Error("invalid factor");
22
20
  const originIsPoint = Array.isArray(origin) || typeof origin === "object";
23
- if (mutate !== true)
24
- geojson = clone(geojson);
21
+ if (mutate !== true) geojson = clone(geojson);
25
22
  if (geojson.type === "FeatureCollection" && !originIsPoint) {
26
23
  featureEach(geojson, function(feature, index) {
27
24
  geojson.features[index] = scale(
@@ -37,8 +34,7 @@ function transformScale(geojson, factor, options) {
37
34
  function scale(feature, factor, origin) {
38
35
  const isPoint = getType(feature) === "Point";
39
36
  const originCoord = defineOrigin(feature, origin);
40
- if (factor === 1 || isPoint)
41
- return feature;
37
+ if (factor === 1 || isPoint) return feature;
42
38
  coordEach(feature, function(coord) {
43
39
  const originalDistance = rhumbDistance(originCoord, coord);
44
40
  const bearing = rhumbBearing(originCoord, coord);
@@ -48,15 +44,13 @@ function scale(feature, factor, origin) {
48
44
  );
49
45
  coord[0] = newCoord[0];
50
46
  coord[1] = newCoord[1];
51
- if (coord.length === 3)
52
- coord[2] *= factor;
47
+ if (coord.length === 3) coord[2] *= factor;
53
48
  });
54
49
  delete feature.bbox;
55
50
  return feature;
56
51
  }
57
52
  function defineOrigin(geojson, origin) {
58
- if (origin === void 0 || origin === null)
59
- origin = "centroid";
53
+ if (origin === void 0 || origin === null) origin = "centroid";
60
54
  if (Array.isArray(origin) || typeof origin === "object")
61
55
  return getCoord(origin);
62
56
  const bbox = geojson.bbox ? geojson.bbox : turfBBox(geojson, { recompute: true });
@@ -66,23 +60,35 @@ function defineOrigin(geojson, origin) {
66
60
  const north = bbox[3];
67
61
  switch (origin) {
68
62
  case "sw":
63
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
69
64
  case "southwest":
65
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
70
66
  case "westsouth":
67
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
71
68
  case "bottomleft":
72
69
  return point([west, south]);
73
70
  case "se":
71
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
74
72
  case "southeast":
73
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
75
74
  case "eastsouth":
75
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
76
76
  case "bottomright":
77
77
  return point([east, south]);
78
78
  case "nw":
79
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
79
80
  case "northwest":
81
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
80
82
  case "westnorth":
83
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
81
84
  case "topleft":
82
85
  return point([west, north]);
83
86
  case "ne":
87
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
84
88
  case "northeast":
89
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
85
90
  case "eastnorth":
91
+ // @ts-expect-error undocumented, to be removed for v8 #techdebt
86
92
  case "topright":
87
93
  return point([east, north]);
88
94
  case "center":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Corners, Coord } from \"@turf/helpers\";\nimport { FeatureCollection, GeoJSON, GeometryCollection } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale GeoJSON objects from a given point by a scaling factor e.g. factor=2\n * would make each object 200% larger.\n * If a FeatureCollection is provided, the origin point will be calculated\n * based on each individual feature _unless_ an exact\n *\n * @name transformScale\n * @param {GeoJSON|GeometryCollection} geojson objects to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {Corners|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance improvement if true)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * const addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n factor: number,\n options?: {\n origin?: Corners | Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const origin = options.origin || \"centroid\";\n const mutate = options.mutate || false;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n const originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately if a feature collection AND the user didn't\n // pass a single explicit point to scale the whole collection from.\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n // The type guard above is not recognised in the callback so we have to\n // cast to accept responsibility.\n (geojson as FeatureCollection).features[index] = scale(\n feature,\n factor,\n origin\n );\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {GeoJSON|GeometryCollection} feature feature or geometry collection to scale\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {Corners|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON Feature/Geometry\n */\nfunction scale<T extends GeoJSON | GeometryCollection>(\n feature: T,\n factor: number,\n origin: Corners | Coord\n): T {\n // Default params\n const isPoint = getType(feature) === \"Point\";\n // Work with a Coord equivalent of the origin from here on.\n const originCoord: Coord = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n const originalDistance = rhumbDistance(originCoord, coord);\n const bearing = rhumbBearing(originCoord, coord);\n const newDistance = originalDistance * factor;\n const newCoord = getCoords(\n rhumbDestination(originCoord, newDistance, bearing)\n );\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON|GeometryCollection} geojson GeoJSON\n * @param {Corners|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(\n geojson: GeoJSON | GeometryCollection,\n origin: Corners | Coord\n): Coord {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n const bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recompute: true });\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n // Having to disable eslint below for lines which fail the no-fallthrough\n // rule, though only because of the ts-expect-error rules. Once we remove\n // southeast, bottomright, rightbottom, etc we should be able to remove all\n // these supressions.\n /* eslint-disable no-fallthrough */\n switch (origin) {\n case \"sw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n /* eslint-enable no-fallthrough */\n}\n\nexport { transformScale };\nexport default transformScale;\n"],"mappings":";AAEA,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,WAAW,mBAAmB;AACvC,SAAS,OAAO,gBAAgB;AAChC,SAAS,UAAU,WAAW,eAAe;AAuB7C,SAAS,eACP,SACA,QACA,SAIG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU;AAGjC,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,kBAAkB;AAChD,MAAI,OAAO,WAAW,YAAY,UAAU;AAC1C,UAAM,IAAI,MAAM,gBAAgB;AAClC,QAAM,gBAAgB,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW;AAGjE,MAAI,WAAW;AAAM,cAAU,MAAM,OAAO;AAI5C,MAAI,QAAQ,SAAS,uBAAuB,CAAC,eAAe;AAC1D,gBAAY,SAAS,SAAU,SAAS,OAAO;AAG7C,MAAC,QAA8B,SAAS,KAAK,IAAI;AAAA,QAC/C;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;A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AAA,IAEL,KAAK;AACH,aAAO,MAAM,CAAC,MAAM,KAAK,CAAC;AAAA,IAC5B,KAAK;AAAA,IAEL,KAAK;AAAA,IAEL,KAAK;AAAA,IAEL,KAAK;AACH,aAAO,MAAM,CAAC,MAAM,KAAK,CAAC;AAAA,IAC5B,KAAK;AACH,aAAO,OAAO,OAAO;AAAA,IACvB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS,OAAO;AAAA,IACzB;AACE,YAAM,IAAI,MAAM,gBAAgB;AAAA,EACpC;AAEF;AAGA,IAAO,+BAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Corners, Coord } from \"@turf/helpers\";\nimport { FeatureCollection, GeoJSON, GeometryCollection } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale GeoJSON objects from a given point by a scaling factor e.g. factor=2\n * would make each object 200% larger.\n * If a FeatureCollection is provided, the origin point will be calculated\n * based on each individual feature _unless_ an exact\n *\n * @function\n * @param {GeoJSON|GeometryCollection} geojson objects to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {Corners|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance improvement if true)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * const addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n factor: number,\n options?: {\n origin?: Corners | Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const origin = options.origin || \"centroid\";\n const mutate = options.mutate || false;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n const originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately if a feature collection AND the user didn't\n // pass a single explicit point to scale the whole collection from.\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n // The type guard above is not recognised in the callback so we have to\n // cast to accept responsibility.\n (geojson as FeatureCollection).features[index] = scale(\n feature,\n factor,\n origin\n );\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {GeoJSON|GeometryCollection} feature feature or geometry collection to scale\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {Corners|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON Feature/Geometry\n */\nfunction scale<T extends GeoJSON | GeometryCollection>(\n feature: T,\n factor: number,\n origin: Corners | Coord\n): T {\n // Default params\n const isPoint = getType(feature) === \"Point\";\n // Work with a Coord equivalent of the origin from here on.\n const originCoord: Coord = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n const originalDistance = rhumbDistance(originCoord, coord);\n const bearing = rhumbBearing(originCoord, coord);\n const newDistance = originalDistance * factor;\n const newCoord = getCoords(\n rhumbDestination(originCoord, newDistance, bearing)\n );\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON|GeometryCollection} geojson GeoJSON\n * @param {Corners|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature<Point>} Point origin\n */\nfunction defineOrigin(\n geojson: GeoJSON | GeometryCollection,\n origin: Corners | Coord\n): Coord {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n const bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recompute: true });\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n // Having to disable eslint below for lines which fail the no-fallthrough\n // rule, though only because of the ts-expect-error rules. Once we remove\n // southeast, bottomright, rightbottom, etc we should be able to remove all\n // these supressions.\n /* eslint-disable no-fallthrough */\n switch (origin) {\n case \"sw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n /* eslint-enable no-fallthrough */\n}\n\nexport { transformScale };\nexport default transformScale;\n"],"mappings":";AAEA,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,WAAW,mBAAmB;AACvC,SAAS,OAAO,gBAAgB;AAChC,SAAS,UAAU,WAAW,eAAe;AAuB7C,SAAS,eACP,SACA,QACA,SAIG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU;AAGjC,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,kBAAkB;AAChD,MAAI,OAAO,WAAW,YAAY,UAAU;AAC1C,UAAM,IAAI,MAAM,gBAAgB;AAClC,QAAM,gBAAgB,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW;AAGjE,MAAI,WAAW,KAAM,WAAU,MAAM,OAAO;AAI5C,MAAI,QAAQ,SAAS,uBAAuB,CAAC,eAAe;AAC1D,gBAAY,SAAS,SAAU,SAAS,OAAO;AAG7C,MAAC,QAA8B,SAAS,KAAK,IAAI;AAAA,QAC/C;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAEA,SAAO,MAAM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EL,KAAK;AAAA;AAAA,IAEL,KAAK;AACH,aAAO,MAAM,CAAC,MAAM,KAAK,CAAC;AAAA,IAC5B,KAAK;AAAA;AAAA,IAEL,KAAK;AAAA;AAAA,IAEL,KAAK;AAAA;AAAA,IAEL,KAAK;AACH,aAAO,MAAM,CAAC,MAAM,KAAK,CAAC;AAAA,IAC5B,KAAK;AACH,aAAO,OAAO,OAAO;AAAA,IACvB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS,OAAO;AAAA,IACzB;AACE,YAAM,IAAI,MAAM,gBAAgB;AAAA,EACpC;AAEF;AAGA,IAAO,+BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/transform-scale",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "turf transform-scale module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -60,33 +60,33 @@
60
60
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
61
61
  },
62
62
  "devDependencies": {
63
- "@turf/bbox-polygon": "^7.1.0",
64
- "@turf/hex-grid": "^7.1.0",
65
- "@turf/truncate": "^7.1.0",
63
+ "@turf/bbox-polygon": "^7.2.0",
64
+ "@turf/hex-grid": "^7.2.0",
65
+ "@turf/truncate": "^7.2.0",
66
66
  "@types/benchmark": "^2.1.5",
67
- "@types/tape": "^4.2.32",
67
+ "@types/tape": "^4.13.4",
68
68
  "benchmark": "^2.1.4",
69
69
  "load-json-file": "^7.0.1",
70
70
  "npm-run-all": "^4.1.5",
71
- "tape": "^5.7.2",
72
- "tsup": "^8.0.1",
73
- "tsx": "^4.6.2",
74
- "typescript": "^5.2.2",
71
+ "tape": "^5.9.0",
72
+ "tsup": "^8.3.5",
73
+ "tsx": "^4.19.2",
74
+ "typescript": "^5.5.4",
75
75
  "write-json-file": "^5.0.0"
76
76
  },
77
77
  "dependencies": {
78
- "@turf/bbox": "^7.1.0",
79
- "@turf/center": "^7.1.0",
80
- "@turf/centroid": "^7.1.0",
81
- "@turf/clone": "^7.1.0",
82
- "@turf/helpers": "^7.1.0",
83
- "@turf/invariant": "^7.1.0",
84
- "@turf/meta": "^7.1.0",
85
- "@turf/rhumb-bearing": "^7.1.0",
86
- "@turf/rhumb-destination": "^7.1.0",
87
- "@turf/rhumb-distance": "^7.1.0",
78
+ "@turf/bbox": "^7.2.0",
79
+ "@turf/center": "^7.2.0",
80
+ "@turf/centroid": "^7.2.0",
81
+ "@turf/clone": "^7.2.0",
82
+ "@turf/helpers": "^7.2.0",
83
+ "@turf/invariant": "^7.2.0",
84
+ "@turf/meta": "^7.2.0",
85
+ "@turf/rhumb-bearing": "^7.2.0",
86
+ "@turf/rhumb-destination": "^7.2.0",
87
+ "@turf/rhumb-distance": "^7.2.0",
88
88
  "@types/geojson": "^7946.0.10",
89
- "tslib": "^2.6.2"
89
+ "tslib": "^2.8.1"
90
90
  },
91
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
91
+ "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
92
92
  }