@turf/transform-scale 6.4.0 → 7.0.0-alpha.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.
package/README.md CHANGED
@@ -7,15 +7,16 @@
7
7
  Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
8
8
  If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.
9
9
 
10
- **Parameters**
10
+ ### Parameters
11
11
 
12
- - `geojson` **[GeoJSON][1]** GeoJSON to be scaled
13
- - `factor` **[number][2]** of scaling, positive or negative values greater than 0
14
- - `options` **[Object][3]** Optional parameters (optional, default `{}`)
15
- - `options.origin` **([string][4] \| [Coord][5])** Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) (optional, default `'centroid'`)
16
- - `options.mutate` **[boolean][6]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
12
+ * `geojson` **[GeoJSON][1]** GeoJSON to be scaled
13
+ * `factor` **[number][2]** 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.
14
+ * `options` **[Object][3]** Optional parameters (optional, default `{}`)
17
15
 
18
- **Examples**
16
+ * `options.origin` **([string][4] | [Coord][5])** Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) (optional, default `'centroid'`)
17
+ * `options.mutate` **[boolean][6]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
18
+
19
+ ### Examples
19
20
 
20
21
  ```javascript
21
22
  var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
package/dist/es/index.js CHANGED
@@ -5,9 +5,9 @@ import turfBBox from '@turf/bbox';
5
5
  import rhumbBearing from '@turf/rhumb-bearing';
6
6
  import rhumbDistance from '@turf/rhumb-distance';
7
7
  import rhumbDestination from '@turf/rhumb-destination';
8
- import { coordEach, featureEach } from '@turf/meta';
9
- import { point, isObject } from '@turf/helpers';
10
- import { getCoord, getCoords, getType } from '@turf/invariant';
8
+ import { featureEach, coordEach } from '@turf/meta';
9
+ import { isObject, point } from '@turf/helpers';
10
+ import { getType, getCoords, getCoord } from '@turf/invariant';
11
11
 
12
12
  /**
13
13
  * Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
@@ -15,7 +15,7 @@ import { getCoord, getCoords, getType } from '@turf/invariant';
15
15
  *
16
16
  * @name transformScale
17
17
  * @param {GeoJSON} geojson GeoJSON to be scaled
18
- * @param {number} factor of scaling, positive or negative values greater than 0
18
+ * @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.
19
19
  * @param {Object} [options={}] Optional parameters
20
20
  * @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
21
21
  * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
@@ -37,7 +37,7 @@ function transformScale(geojson, factor, options) {
37
37
 
38
38
  // Input validation
39
39
  if (!geojson) throw new Error("geojson required");
40
- if (typeof factor !== "number" || factor === 0)
40
+ if (typeof factor !== "number" || factor <= 0)
41
41
  throw new Error("invalid factor");
42
42
  var originIsPoint = Array.isArray(origin) || typeof origin === "object";
43
43
 
@@ -83,6 +83,8 @@ function scale(feature, factor, origin) {
83
83
  if (coord.length === 3) coord[2] *= factor;
84
84
  });
85
85
 
86
+ delete feature.bbox;
87
+
86
88
  return feature;
87
89
  }
88
90
 
@@ -103,7 +105,9 @@ function defineOrigin(geojson, origin) {
103
105
  return getCoord(origin);
104
106
 
105
107
  // Define BBox
106
- var bbox = geojson.bbox ? geojson.bbox : turfBBox(geojson);
108
+ var bbox = geojson.bbox
109
+ ? geojson.bbox
110
+ : turfBBox(geojson, { recalculate: true });
107
111
  var west = bbox[0];
108
112
  var south = bbox[1];
109
113
  var east = bbox[2];
package/dist/js/index.js CHANGED
@@ -1,25 +1,33 @@
1
1
  'use strict';
2
2
 
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var clone = _interopDefault(require('@turf/clone'));
6
- var center = _interopDefault(require('@turf/center'));
7
- var centroid = _interopDefault(require('@turf/centroid'));
8
- var turfBBox = _interopDefault(require('@turf/bbox'));
9
- var rhumbBearing = _interopDefault(require('@turf/rhumb-bearing'));
10
- var rhumbDistance = _interopDefault(require('@turf/rhumb-distance'));
11
- var rhumbDestination = _interopDefault(require('@turf/rhumb-destination'));
3
+ var clone = require('@turf/clone');
4
+ var center = require('@turf/center');
5
+ var centroid = require('@turf/centroid');
6
+ var turfBBox = require('@turf/bbox');
7
+ var rhumbBearing = require('@turf/rhumb-bearing');
8
+ var rhumbDistance = require('@turf/rhumb-distance');
9
+ var rhumbDestination = require('@turf/rhumb-destination');
12
10
  var meta = require('@turf/meta');
13
11
  var helpers = require('@turf/helpers');
14
12
  var invariant = require('@turf/invariant');
15
13
 
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
17
+ var center__default = /*#__PURE__*/_interopDefaultLegacy(center);
18
+ var centroid__default = /*#__PURE__*/_interopDefaultLegacy(centroid);
19
+ var turfBBox__default = /*#__PURE__*/_interopDefaultLegacy(turfBBox);
20
+ var rhumbBearing__default = /*#__PURE__*/_interopDefaultLegacy(rhumbBearing);
21
+ var rhumbDistance__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDistance);
22
+ var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestination);
23
+
16
24
  /**
17
25
  * Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger).
18
26
  * If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.
19
27
  *
20
28
  * @name transformScale
21
29
  * @param {GeoJSON} geojson GeoJSON to be scaled
22
- * @param {number} factor of scaling, positive or negative values greater than 0
30
+ * @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.
23
31
  * @param {Object} [options={}] Optional parameters
24
32
  * @param {string|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
25
33
  * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
@@ -41,12 +49,12 @@ function transformScale(geojson, factor, options) {
41
49
 
42
50
  // Input validation
43
51
  if (!geojson) throw new Error("geojson required");
44
- if (typeof factor !== "number" || factor === 0)
52
+ if (typeof factor !== "number" || factor <= 0)
45
53
  throw new Error("invalid factor");
46
54
  var originIsPoint = Array.isArray(origin) || typeof origin === "object";
47
55
 
48
56
  // Clone geojson to avoid side effects
49
- if (mutate !== true) geojson = clone(geojson);
57
+ if (mutate !== true) geojson = clone__default['default'](geojson);
50
58
 
51
59
  // Scale each Feature separately
52
60
  if (geojson.type === "FeatureCollection" && !originIsPoint) {
@@ -78,15 +86,17 @@ function scale(feature, factor, origin) {
78
86
 
79
87
  // Scale each coordinate
80
88
  meta.coordEach(feature, function (coord) {
81
- var originalDistance = rhumbDistance(origin, coord);
82
- var bearing = rhumbBearing(origin, coord);
89
+ var originalDistance = rhumbDistance__default['default'](origin, coord);
90
+ var bearing = rhumbBearing__default['default'](origin, coord);
83
91
  var newDistance = originalDistance * factor;
84
- var newCoord = invariant.getCoords(rhumbDestination(origin, newDistance, bearing));
92
+ var newCoord = invariant.getCoords(rhumbDestination__default['default'](origin, newDistance, bearing));
85
93
  coord[0] = newCoord[0];
86
94
  coord[1] = newCoord[1];
87
95
  if (coord.length === 3) coord[2] *= factor;
88
96
  });
89
97
 
98
+ delete feature.bbox;
99
+
90
100
  return feature;
91
101
  }
92
102
 
@@ -107,7 +117,9 @@ function defineOrigin(geojson, origin) {
107
117
  return invariant.getCoord(origin);
108
118
 
109
119
  // Define BBox
110
- var bbox = geojson.bbox ? geojson.bbox : turfBBox(geojson);
120
+ var bbox = geojson.bbox
121
+ ? geojson.bbox
122
+ : turfBBox__default['default'](geojson, { recalculate: true });
111
123
  var west = bbox[0];
112
124
  var south = bbox[1];
113
125
  var east = bbox[2];
@@ -135,14 +147,15 @@ function defineOrigin(geojson, origin) {
135
147
  case "topright":
136
148
  return helpers.point([east, north]);
137
149
  case "center":
138
- return center(geojson);
150
+ return center__default['default'](geojson);
139
151
  case undefined:
140
152
  case null:
141
153
  case "centroid":
142
- return centroid(geojson);
154
+ return centroid__default['default'](geojson);
143
155
  default:
144
156
  throw new Error("invalid origin");
145
157
  }
146
158
  }
147
159
 
148
160
  module.exports = transformScale;
161
+ module.exports.default = transformScale;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/transform-scale",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf transform-scale module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -16,6 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git://github.com/Turfjs/turf.git"
18
18
  },
19
+ "funding": "https://opencollective.com/turf",
19
20
  "publishConfig": {
20
21
  "access": "public"
21
22
  },
@@ -50,12 +51,12 @@
50
51
  "docs": "node ../../scripts/generate-readmes",
51
52
  "test": "npm-run-all test:*",
52
53
  "test:tape": "node -r esm test.js",
53
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
54
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
54
55
  },
55
56
  "devDependencies": {
56
- "@turf/bbox-polygon": "^6.4.0",
57
- "@turf/hex-grid": "^6.4.0",
58
- "@turf/truncate": "^6.4.0",
57
+ "@turf/bbox-polygon": "^7.0.0-alpha.0",
58
+ "@turf/hex-grid": "^7.0.0-alpha.0",
59
+ "@turf/truncate": "^7.0.0-alpha.0",
59
60
  "benchmark": "*",
60
61
  "load-json-file": "*",
61
62
  "npm-run-all": "*",
@@ -64,16 +65,16 @@
64
65
  "write-json-file": "*"
65
66
  },
66
67
  "dependencies": {
67
- "@turf/bbox": "^6.4.0",
68
- "@turf/center": "^6.4.0",
69
- "@turf/centroid": "^6.4.0",
70
- "@turf/clone": "^6.4.0",
71
- "@turf/helpers": "^6.4.0",
72
- "@turf/invariant": "^6.4.0",
73
- "@turf/meta": "^6.4.0",
74
- "@turf/rhumb-bearing": "^6.4.0",
75
- "@turf/rhumb-destination": "^6.4.0",
76
- "@turf/rhumb-distance": "^6.4.0"
68
+ "@turf/bbox": "^7.0.0-alpha.0",
69
+ "@turf/center": "^7.0.0-alpha.0",
70
+ "@turf/centroid": "^7.0.0-alpha.0",
71
+ "@turf/clone": "^7.0.0-alpha.0",
72
+ "@turf/helpers": "^7.0.0-alpha.0",
73
+ "@turf/invariant": "^7.0.0-alpha.0",
74
+ "@turf/meta": "^7.0.0-alpha.0",
75
+ "@turf/rhumb-bearing": "^7.0.0-alpha.0",
76
+ "@turf/rhumb-destination": "^7.0.0-alpha.0",
77
+ "@turf/rhumb-distance": "^7.0.0-alpha.0"
77
78
  },
78
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
79
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
79
80
  }