@turf/ellipse 7.0.0-alpha.1 → 7.0.0-alpha.110
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 +5 -10
- package/dist/cjs/index.cjs +82 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +34 -0
- package/dist/esm/index.d.mts +34 -0
- package/dist/esm/index.mjs +82 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +41 -32
- package/dist/es/index.js +0 -104
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -112
- package/index.d.ts +0 -29
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Takes a [Point][1] and calculates the ellipse polygon given two semi-axes expres
|
|
|
14
14
|
* `options` **[Object][4]** Optional parameters (optional, default `{}`)
|
|
15
15
|
|
|
16
16
|
* `options.angle` **[number][3]** angle of rotation in decimal degrees, positive clockwise (optional, default `0`)
|
|
17
|
-
* `options.pivot` **[Coord][2]** point around which
|
|
17
|
+
* `options.pivot` **[Coord][2]** point around which any rotation will be performed (optional, default `center`)
|
|
18
18
|
* `options.steps` **[number][3]** number of steps (optional, default `64`)
|
|
19
19
|
* `options.units` **[string][5]** unit of measurement for axes (optional, default `'kilometers'`)
|
|
20
20
|
* `options.properties` **[Object][4]** properties (optional, default `{}`)
|
|
@@ -47,26 +47,21 @@ Returns **[Feature][6]<[Polygon][7]>** ellipse polygon
|
|
|
47
47
|
|
|
48
48
|
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
49
49
|
|
|
50
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
51
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
52
|
-
./scripts/generate-readmes in the turf project. -->
|
|
50
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
53
51
|
|
|
54
52
|
---
|
|
55
53
|
|
|
56
|
-
This module is part of the [Turfjs project](
|
|
57
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
58
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
59
|
-
PRs and issues.
|
|
54
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
60
55
|
|
|
61
56
|
### Installation
|
|
62
57
|
|
|
63
|
-
Install this module individually:
|
|
58
|
+
Install this single module individually:
|
|
64
59
|
|
|
65
60
|
```sh
|
|
66
61
|
$ npm install @turf/ellipse
|
|
67
62
|
```
|
|
68
63
|
|
|
69
|
-
Or install the
|
|
64
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
70
65
|
|
|
71
66
|
```sh
|
|
72
67
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _helpers = require('@turf/helpers');
|
|
11
|
+
var _rhumbdestination = require('@turf/rhumb-destination');
|
|
12
|
+
var _transformrotate = require('@turf/transform-rotate');
|
|
13
|
+
var _invariant = require('@turf/invariant');
|
|
14
|
+
function ellipse(center, xSemiAxis, ySemiAxis, options) {
|
|
15
|
+
options = options || {};
|
|
16
|
+
const steps = options.steps || 64;
|
|
17
|
+
const units = options.units || "kilometers";
|
|
18
|
+
const angle = options.angle || 0;
|
|
19
|
+
const pivot = options.pivot || center;
|
|
20
|
+
const properties = options.properties || {};
|
|
21
|
+
if (!center)
|
|
22
|
+
throw new Error("center is required");
|
|
23
|
+
if (!xSemiAxis)
|
|
24
|
+
throw new Error("xSemiAxis is required");
|
|
25
|
+
if (!ySemiAxis)
|
|
26
|
+
throw new Error("ySemiAxis is required");
|
|
27
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
28
|
+
throw new Error("options must be an object");
|
|
29
|
+
if (!_helpers.isNumber.call(void 0, steps))
|
|
30
|
+
throw new Error("steps must be a number");
|
|
31
|
+
if (!_helpers.isNumber.call(void 0, angle))
|
|
32
|
+
throw new Error("angle must be a number");
|
|
33
|
+
const centerCoords = _invariant.getCoord.call(void 0, center);
|
|
34
|
+
if (units !== "degrees") {
|
|
35
|
+
const xDest = _rhumbdestination.rhumbDestination.call(void 0, center, xSemiAxis, 90, { units });
|
|
36
|
+
const yDest = _rhumbdestination.rhumbDestination.call(void 0, center, ySemiAxis, 0, { units });
|
|
37
|
+
xSemiAxis = _invariant.getCoord.call(void 0, xDest)[0] - centerCoords[0];
|
|
38
|
+
ySemiAxis = _invariant.getCoord.call(void 0, yDest)[1] - centerCoords[1];
|
|
39
|
+
}
|
|
40
|
+
const coordinates = [];
|
|
41
|
+
for (let i = 0; i < steps; i += 1) {
|
|
42
|
+
const stepAngle = i * -360 / steps;
|
|
43
|
+
let x = xSemiAxis * ySemiAxis / Math.sqrt(
|
|
44
|
+
Math.pow(ySemiAxis, 2) + Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)
|
|
45
|
+
);
|
|
46
|
+
let y = xSemiAxis * ySemiAxis / Math.sqrt(
|
|
47
|
+
Math.pow(xSemiAxis, 2) + Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)
|
|
48
|
+
);
|
|
49
|
+
if (stepAngle < -90 && stepAngle >= -270)
|
|
50
|
+
x = -x;
|
|
51
|
+
if (stepAngle < -180 && stepAngle >= -360)
|
|
52
|
+
y = -y;
|
|
53
|
+
if (units === "degrees") {
|
|
54
|
+
const angleRad = _helpers.degreesToRadians.call(void 0, angle);
|
|
55
|
+
const newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
|
|
56
|
+
const newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
|
|
57
|
+
x = newx;
|
|
58
|
+
y = newy;
|
|
59
|
+
}
|
|
60
|
+
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
|
|
61
|
+
}
|
|
62
|
+
coordinates.push(coordinates[0]);
|
|
63
|
+
if (units === "degrees") {
|
|
64
|
+
return _helpers.polygon.call(void 0, [coordinates], properties);
|
|
65
|
+
} else {
|
|
66
|
+
return _transformrotate.transformRotate.call(void 0, _helpers.polygon.call(void 0, [coordinates], properties), angle, {
|
|
67
|
+
pivot
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__name(ellipse, "ellipse");
|
|
72
|
+
function getTanDeg(deg) {
|
|
73
|
+
const rad = deg * Math.PI / 180;
|
|
74
|
+
return Math.tan(rad);
|
|
75
|
+
}
|
|
76
|
+
__name(getTanDeg, "getTanDeg");
|
|
77
|
+
var turf_ellipse_default = ellipse;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
exports.default = turf_ellipse_default; exports.ellipse = ellipse;
|
|
82
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AAyBzB,SAAS,QACP,QACA,WACA,WACA,SAOkB;AAElB,YAAU,WAAW,CAAC;AACtB,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,aAAa,QAAQ,cAAc,CAAC;AAG1C,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AACjD,MAAI,CAAC;AAAW,UAAM,IAAI,MAAM,uBAAuB;AACvD,MAAI,CAAC;AAAW,UAAM,IAAI,MAAM,uBAAuB;AACvD,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,2BAA2B;AACnE,MAAI,CAAC,SAAS,KAAK;AAAG,UAAM,IAAI,MAAM,wBAAwB;AAC9D,MAAI,CAAC,SAAS,KAAK;AAAG,UAAM,IAAI,MAAM,wBAAwB;AAE9D,QAAM,eAAe,SAAS,MAAM;AACpC,MAAI,UAAU,WAAW;AACvB,UAAM,QAAQ,iBAAiB,QAAQ,WAAW,IAAI,EAAE,MAAM,CAAC;AAC/D,UAAM,QAAQ,iBAAiB,QAAQ,WAAW,GAAG,EAAE,MAAM,CAAC;AAC9D,gBAAY,SAAS,KAAK,EAAE,CAAC,IAAI,aAAa,CAAC;AAC/C,gBAAY,SAAS,KAAK,EAAE,CAAC,IAAI,aAAa,CAAC;AAAA,EACjD;AAEA,QAAM,cAA0B,CAAC;AACjC,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK,GAAG;AACjC,UAAM,YAAa,IAAI,OAAQ;AAC/B,QAAI,IACD,YAAY,YACb,KAAK;AAAA,MACH,KAAK,IAAI,WAAW,CAAC,IACnB,KAAK,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AAAA,IAC7D;AACF,QAAI,IACD,YAAY,YACb,KAAK;AAAA,MACH,KAAK,IAAI,WAAW,CAAC,IACnB,KAAK,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AAAA,IAC7D;AAEF,QAAI,YAAY,OAAO,aAAa;AAAM,UAAI,CAAC;AAC/C,QAAI,YAAY,QAAQ,aAAa;AAAM,UAAI,CAAC;AAChD,QAAI,UAAU,WAAW;AACvB,YAAM,WAAW,iBAAiB,KAAK;AACvC,YAAM,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,QAAQ;AAC3D,YAAM,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,QAAQ;AAC3D,UAAI;AACJ,UAAI;AAAA,IACN;AAEA,gBAAY,KAAK,CAAC,IAAI,aAAa,CAAC,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC;AAAA,EAC7D;AACA,cAAY,KAAK,YAAY,CAAC,CAAC;AAC/B,MAAI,UAAU,WAAW;AACvB,WAAO,QAAQ,CAAC,WAAW,GAAG,UAAU;AAAA,EAC1C,OAAO;AACL,WAAO,gBAAgB,QAAQ,CAAC,WAAW,GAAG,UAAU,GAAG,OAAO;AAAA,MAChE;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAxES;AAiFT,SAAS,UAAU,KAAa;AAC9B,QAAM,MAAO,MAAM,KAAK,KAAM;AAC9B,SAAO,KAAK,IAAI,GAAG;AACrB;AAHS;AAMT,IAAO,uBAAQ","sourcesContent":["import {\n degreesToRadians,\n polygon,\n isObject,\n isNumber,\n Coord,\n Units,\n} from \"@turf/helpers\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { transformRotate } from \"@turf/transform-rotate\";\nimport { getCoord } from \"@turf/invariant\";\nimport { GeoJsonProperties, Feature, Polygon } from \"geojson\";\n\n/**\n * Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.\n *\n * @param {Coord} center center point\n * @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis\n * @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise\n * @param {Coord} [options.pivot=center] point around which any rotation will be performed\n * @param {number} [options.steps=64] number of steps\n * @param {string} [options.units='kilometers'] unit of measurement for axes\n * @param {Object} [options.properties={}] properties\n * @returns {Feature<Polygon>} ellipse polygon\n * @example\n * var center = [-75, 40];\n * var xSemiAxis = 5;\n * var ySemiAxis = 2;\n * var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);\n *\n * //addToMap\n * var addToMap = [turf.point(center), ellipse]\n */\nfunction ellipse(\n center: Coord,\n xSemiAxis: number,\n ySemiAxis: number,\n options: {\n steps?: number;\n units?: Units;\n angle?: number;\n pivot?: Coord;\n properties?: GeoJsonProperties;\n }\n): Feature<Polygon> {\n // Optional params\n options = options || {};\n const steps = options.steps || 64;\n const units = options.units || \"kilometers\";\n const angle = options.angle || 0;\n const pivot = options.pivot || center;\n const properties = options.properties || {};\n\n // validation\n if (!center) throw new Error(\"center is required\");\n if (!xSemiAxis) throw new Error(\"xSemiAxis is required\");\n if (!ySemiAxis) throw new Error(\"ySemiAxis is required\");\n if (!isObject(options)) throw new Error(\"options must be an object\");\n if (!isNumber(steps)) throw new Error(\"steps must be a number\");\n if (!isNumber(angle)) throw new Error(\"angle must be a number\");\n\n const centerCoords = getCoord(center);\n if (units !== \"degrees\") {\n const xDest = rhumbDestination(center, xSemiAxis, 90, { units });\n const yDest = rhumbDestination(center, ySemiAxis, 0, { units });\n xSemiAxis = getCoord(xDest)[0] - centerCoords[0];\n ySemiAxis = getCoord(yDest)[1] - centerCoords[1];\n }\n\n const coordinates: number[][] = [];\n for (let i = 0; i < steps; i += 1) {\n const stepAngle = (i * -360) / steps;\n let x =\n (xSemiAxis * ySemiAxis) /\n Math.sqrt(\n Math.pow(ySemiAxis, 2) +\n Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)\n );\n let y =\n (xSemiAxis * ySemiAxis) /\n Math.sqrt(\n Math.pow(xSemiAxis, 2) +\n Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)\n );\n\n if (stepAngle < -90 && stepAngle >= -270) x = -x;\n if (stepAngle < -180 && stepAngle >= -360) y = -y;\n if (units === \"degrees\") {\n const angleRad = degreesToRadians(angle);\n const newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);\n const newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);\n x = newx;\n y = newy;\n }\n\n coordinates.push([x + centerCoords[0], y + centerCoords[1]]);\n }\n coordinates.push(coordinates[0]);\n if (units === \"degrees\") {\n return polygon([coordinates], properties);\n } else {\n return transformRotate(polygon([coordinates], properties), angle, {\n pivot,\n });\n }\n}\n\n/**\n * Get Tan Degrees\n *\n * @private\n * @param {number} deg Degrees\n * @returns {number} Tan Degrees\n */\nfunction getTanDeg(deg: number) {\n const rad = (deg * Math.PI) / 180;\n return Math.tan(rad);\n}\n\nexport { ellipse };\nexport default ellipse;\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Coord, Units } from '@turf/helpers';
|
|
2
|
+
import { GeoJsonProperties, Feature, Polygon } from 'geojson';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
|
|
6
|
+
*
|
|
7
|
+
* @param {Coord} center center point
|
|
8
|
+
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis
|
|
9
|
+
* @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis
|
|
10
|
+
* @param {Object} [options={}] Optional parameters
|
|
11
|
+
* @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise
|
|
12
|
+
* @param {Coord} [options.pivot=center] point around which any rotation will be performed
|
|
13
|
+
* @param {number} [options.steps=64] number of steps
|
|
14
|
+
* @param {string} [options.units='kilometers'] unit of measurement for axes
|
|
15
|
+
* @param {Object} [options.properties={}] properties
|
|
16
|
+
* @returns {Feature<Polygon>} ellipse polygon
|
|
17
|
+
* @example
|
|
18
|
+
* var center = [-75, 40];
|
|
19
|
+
* var xSemiAxis = 5;
|
|
20
|
+
* var ySemiAxis = 2;
|
|
21
|
+
* var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);
|
|
22
|
+
*
|
|
23
|
+
* //addToMap
|
|
24
|
+
* var addToMap = [turf.point(center), ellipse]
|
|
25
|
+
*/
|
|
26
|
+
declare function ellipse(center: Coord, xSemiAxis: number, ySemiAxis: number, options: {
|
|
27
|
+
steps?: number;
|
|
28
|
+
units?: Units;
|
|
29
|
+
angle?: number;
|
|
30
|
+
pivot?: Coord;
|
|
31
|
+
properties?: GeoJsonProperties;
|
|
32
|
+
}): Feature<Polygon>;
|
|
33
|
+
|
|
34
|
+
export { ellipse as default, ellipse };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Coord, Units } from '@turf/helpers';
|
|
2
|
+
import { GeoJsonProperties, Feature, Polygon } from 'geojson';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
|
|
6
|
+
*
|
|
7
|
+
* @param {Coord} center center point
|
|
8
|
+
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis
|
|
9
|
+
* @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis
|
|
10
|
+
* @param {Object} [options={}] Optional parameters
|
|
11
|
+
* @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise
|
|
12
|
+
* @param {Coord} [options.pivot=center] point around which any rotation will be performed
|
|
13
|
+
* @param {number} [options.steps=64] number of steps
|
|
14
|
+
* @param {string} [options.units='kilometers'] unit of measurement for axes
|
|
15
|
+
* @param {Object} [options.properties={}] properties
|
|
16
|
+
* @returns {Feature<Polygon>} ellipse polygon
|
|
17
|
+
* @example
|
|
18
|
+
* var center = [-75, 40];
|
|
19
|
+
* var xSemiAxis = 5;
|
|
20
|
+
* var ySemiAxis = 2;
|
|
21
|
+
* var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);
|
|
22
|
+
*
|
|
23
|
+
* //addToMap
|
|
24
|
+
* var addToMap = [turf.point(center), ellipse]
|
|
25
|
+
*/
|
|
26
|
+
declare function ellipse(center: Coord, xSemiAxis: number, ySemiAxis: number, options: {
|
|
27
|
+
steps?: number;
|
|
28
|
+
units?: Units;
|
|
29
|
+
angle?: number;
|
|
30
|
+
pivot?: Coord;
|
|
31
|
+
properties?: GeoJsonProperties;
|
|
32
|
+
}): Feature<Polygon>;
|
|
33
|
+
|
|
34
|
+
export { ellipse as default, ellipse };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import {
|
|
6
|
+
degreesToRadians,
|
|
7
|
+
polygon,
|
|
8
|
+
isObject,
|
|
9
|
+
isNumber
|
|
10
|
+
} from "@turf/helpers";
|
|
11
|
+
import { rhumbDestination } from "@turf/rhumb-destination";
|
|
12
|
+
import { transformRotate } from "@turf/transform-rotate";
|
|
13
|
+
import { getCoord } from "@turf/invariant";
|
|
14
|
+
function ellipse(center, xSemiAxis, ySemiAxis, options) {
|
|
15
|
+
options = options || {};
|
|
16
|
+
const steps = options.steps || 64;
|
|
17
|
+
const units = options.units || "kilometers";
|
|
18
|
+
const angle = options.angle || 0;
|
|
19
|
+
const pivot = options.pivot || center;
|
|
20
|
+
const properties = options.properties || {};
|
|
21
|
+
if (!center)
|
|
22
|
+
throw new Error("center is required");
|
|
23
|
+
if (!xSemiAxis)
|
|
24
|
+
throw new Error("xSemiAxis is required");
|
|
25
|
+
if (!ySemiAxis)
|
|
26
|
+
throw new Error("ySemiAxis is required");
|
|
27
|
+
if (!isObject(options))
|
|
28
|
+
throw new Error("options must be an object");
|
|
29
|
+
if (!isNumber(steps))
|
|
30
|
+
throw new Error("steps must be a number");
|
|
31
|
+
if (!isNumber(angle))
|
|
32
|
+
throw new Error("angle must be a number");
|
|
33
|
+
const centerCoords = getCoord(center);
|
|
34
|
+
if (units !== "degrees") {
|
|
35
|
+
const xDest = rhumbDestination(center, xSemiAxis, 90, { units });
|
|
36
|
+
const yDest = rhumbDestination(center, ySemiAxis, 0, { units });
|
|
37
|
+
xSemiAxis = getCoord(xDest)[0] - centerCoords[0];
|
|
38
|
+
ySemiAxis = getCoord(yDest)[1] - centerCoords[1];
|
|
39
|
+
}
|
|
40
|
+
const coordinates = [];
|
|
41
|
+
for (let i = 0; i < steps; i += 1) {
|
|
42
|
+
const stepAngle = i * -360 / steps;
|
|
43
|
+
let x = xSemiAxis * ySemiAxis / Math.sqrt(
|
|
44
|
+
Math.pow(ySemiAxis, 2) + Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)
|
|
45
|
+
);
|
|
46
|
+
let y = xSemiAxis * ySemiAxis / Math.sqrt(
|
|
47
|
+
Math.pow(xSemiAxis, 2) + Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)
|
|
48
|
+
);
|
|
49
|
+
if (stepAngle < -90 && stepAngle >= -270)
|
|
50
|
+
x = -x;
|
|
51
|
+
if (stepAngle < -180 && stepAngle >= -360)
|
|
52
|
+
y = -y;
|
|
53
|
+
if (units === "degrees") {
|
|
54
|
+
const angleRad = degreesToRadians(angle);
|
|
55
|
+
const newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
|
|
56
|
+
const newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
|
|
57
|
+
x = newx;
|
|
58
|
+
y = newy;
|
|
59
|
+
}
|
|
60
|
+
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
|
|
61
|
+
}
|
|
62
|
+
coordinates.push(coordinates[0]);
|
|
63
|
+
if (units === "degrees") {
|
|
64
|
+
return polygon([coordinates], properties);
|
|
65
|
+
} else {
|
|
66
|
+
return transformRotate(polygon([coordinates], properties), angle, {
|
|
67
|
+
pivot
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__name(ellipse, "ellipse");
|
|
72
|
+
function getTanDeg(deg) {
|
|
73
|
+
const rad = deg * Math.PI / 180;
|
|
74
|
+
return Math.tan(rad);
|
|
75
|
+
}
|
|
76
|
+
__name(getTanDeg, "getTanDeg");
|
|
77
|
+
var turf_ellipse_default = ellipse;
|
|
78
|
+
export {
|
|
79
|
+
turf_ellipse_default as default,
|
|
80
|
+
ellipse
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n degreesToRadians,\n polygon,\n isObject,\n isNumber,\n Coord,\n Units,\n} from \"@turf/helpers\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { transformRotate } from \"@turf/transform-rotate\";\nimport { getCoord } from \"@turf/invariant\";\nimport { GeoJsonProperties, Feature, Polygon } from \"geojson\";\n\n/**\n * Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.\n *\n * @param {Coord} center center point\n * @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis\n * @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise\n * @param {Coord} [options.pivot=center] point around which any rotation will be performed\n * @param {number} [options.steps=64] number of steps\n * @param {string} [options.units='kilometers'] unit of measurement for axes\n * @param {Object} [options.properties={}] properties\n * @returns {Feature<Polygon>} ellipse polygon\n * @example\n * var center = [-75, 40];\n * var xSemiAxis = 5;\n * var ySemiAxis = 2;\n * var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);\n *\n * //addToMap\n * var addToMap = [turf.point(center), ellipse]\n */\nfunction ellipse(\n center: Coord,\n xSemiAxis: number,\n ySemiAxis: number,\n options: {\n steps?: number;\n units?: Units;\n angle?: number;\n pivot?: Coord;\n properties?: GeoJsonProperties;\n }\n): Feature<Polygon> {\n // Optional params\n options = options || {};\n const steps = options.steps || 64;\n const units = options.units || \"kilometers\";\n const angle = options.angle || 0;\n const pivot = options.pivot || center;\n const properties = options.properties || {};\n\n // validation\n if (!center) throw new Error(\"center is required\");\n if (!xSemiAxis) throw new Error(\"xSemiAxis is required\");\n if (!ySemiAxis) throw new Error(\"ySemiAxis is required\");\n if (!isObject(options)) throw new Error(\"options must be an object\");\n if (!isNumber(steps)) throw new Error(\"steps must be a number\");\n if (!isNumber(angle)) throw new Error(\"angle must be a number\");\n\n const centerCoords = getCoord(center);\n if (units !== \"degrees\") {\n const xDest = rhumbDestination(center, xSemiAxis, 90, { units });\n const yDest = rhumbDestination(center, ySemiAxis, 0, { units });\n xSemiAxis = getCoord(xDest)[0] - centerCoords[0];\n ySemiAxis = getCoord(yDest)[1] - centerCoords[1];\n }\n\n const coordinates: number[][] = [];\n for (let i = 0; i < steps; i += 1) {\n const stepAngle = (i * -360) / steps;\n let x =\n (xSemiAxis * ySemiAxis) /\n Math.sqrt(\n Math.pow(ySemiAxis, 2) +\n Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)\n );\n let y =\n (xSemiAxis * ySemiAxis) /\n Math.sqrt(\n Math.pow(xSemiAxis, 2) +\n Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)\n );\n\n if (stepAngle < -90 && stepAngle >= -270) x = -x;\n if (stepAngle < -180 && stepAngle >= -360) y = -y;\n if (units === \"degrees\") {\n const angleRad = degreesToRadians(angle);\n const newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);\n const newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);\n x = newx;\n y = newy;\n }\n\n coordinates.push([x + centerCoords[0], y + centerCoords[1]]);\n }\n coordinates.push(coordinates[0]);\n if (units === \"degrees\") {\n return polygon([coordinates], properties);\n } else {\n return transformRotate(polygon([coordinates], properties), angle, {\n pivot,\n });\n }\n}\n\n/**\n * Get Tan Degrees\n *\n * @private\n * @param {number} deg Degrees\n * @returns {number} Tan Degrees\n */\nfunction getTanDeg(deg: number) {\n const rad = (deg * Math.PI) / 180;\n return Math.tan(rad);\n}\n\nexport { ellipse };\nexport default ellipse;\n"],"mappings":";;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AAyBzB,SAAS,QACP,QACA,WACA,WACA,SAOkB;AAElB,YAAU,WAAW,CAAC;AACtB,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,aAAa,QAAQ,cAAc,CAAC;AAG1C,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AACjD,MAAI,CAAC;AAAW,UAAM,IAAI,MAAM,uBAAuB;AACvD,MAAI,CAAC;AAAW,UAAM,IAAI,MAAM,uBAAuB;AACvD,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,2BAA2B;AACnE,MAAI,CAAC,SAAS,KAAK;AAAG,UAAM,IAAI,MAAM,wBAAwB;AAC9D,MAAI,CAAC,SAAS,KAAK;AAAG,UAAM,IAAI,MAAM,wBAAwB;AAE9D,QAAM,eAAe,SAAS,MAAM;AACpC,MAAI,UAAU,WAAW;AACvB,UAAM,QAAQ,iBAAiB,QAAQ,WAAW,IAAI,EAAE,MAAM,CAAC;AAC/D,UAAM,QAAQ,iBAAiB,QAAQ,WAAW,GAAG,EAAE,MAAM,CAAC;AAC9D,gBAAY,SAAS,KAAK,EAAE,CAAC,IAAI,aAAa,CAAC;AAC/C,gBAAY,SAAS,KAAK,EAAE,CAAC,IAAI,aAAa,CAAC;AAAA,EACjD;AAEA,QAAM,cAA0B,CAAC;AACjC,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK,GAAG;AACjC,UAAM,YAAa,IAAI,OAAQ;AAC/B,QAAI,IACD,YAAY,YACb,KAAK;AAAA,MACH,KAAK,IAAI,WAAW,CAAC,IACnB,KAAK,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AAAA,IAC7D;AACF,QAAI,IACD,YAAY,YACb,KAAK;AAAA,MACH,KAAK,IAAI,WAAW,CAAC,IACnB,KAAK,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AAAA,IAC7D;AAEF,QAAI,YAAY,OAAO,aAAa;AAAM,UAAI,CAAC;AAC/C,QAAI,YAAY,QAAQ,aAAa;AAAM,UAAI,CAAC;AAChD,QAAI,UAAU,WAAW;AACvB,YAAM,WAAW,iBAAiB,KAAK;AACvC,YAAM,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,QAAQ;AAC3D,YAAM,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,QAAQ;AAC3D,UAAI;AACJ,UAAI;AAAA,IACN;AAEA,gBAAY,KAAK,CAAC,IAAI,aAAa,CAAC,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC;AAAA,EAC7D;AACA,cAAY,KAAK,YAAY,CAAC,CAAC;AAC/B,MAAI,UAAU,WAAW;AACvB,WAAO,QAAQ,CAAC,WAAW,GAAG,UAAU;AAAA,EAC1C,OAAO;AACL,WAAO,gBAAgB,QAAQ,CAAC,WAAW,GAAG,UAAU,GAAG,OAAO;AAAA,MAChE;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAxES;AAiFT,SAAS,UAAU,KAAa;AAC9B,QAAM,MAAO,MAAM,KAAK,KAAM;AAC9B,SAAO,KAAK,IAAI,GAAG;AACrB;AAHS;AAMT,IAAO,uBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/ellipse",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf ellipse module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -23,49 +23,58 @@
|
|
|
23
23
|
"turf",
|
|
24
24
|
"ellipse"
|
|
25
25
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"type": "commonjs",
|
|
27
|
+
"main": "dist/cjs/index.cjs",
|
|
28
|
+
"module": "dist/esm/index.mjs",
|
|
29
|
+
"types": "dist/cjs/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
"./package.json": "./package.json",
|
|
30
32
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.mts",
|
|
35
|
+
"default": "./dist/esm/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
},
|
|
36
|
-
"types": "index.d.ts",
|
|
37
43
|
"sideEffects": false,
|
|
38
44
|
"files": [
|
|
39
|
-
"dist"
|
|
40
|
-
"index.d.ts"
|
|
45
|
+
"dist"
|
|
41
46
|
],
|
|
42
47
|
"scripts": {
|
|
43
|
-
"bench": "tsx bench.
|
|
44
|
-
"build": "
|
|
45
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
46
|
-
"test": "npm-run-all test:*",
|
|
47
|
-
"test:tape": "tsx test.
|
|
48
|
+
"bench": "tsx bench.ts",
|
|
49
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
50
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
51
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
52
|
+
"test:tape": "tsx test.ts"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@mapbox/geojsonhint": "
|
|
51
|
-
"@turf/bbox-polygon": "^7.0.0-alpha.
|
|
52
|
-
"@turf/circle": "^7.0.0-alpha.
|
|
53
|
-
"@turf/destination": "^7.0.0-alpha.
|
|
54
|
-
"@turf/truncate": "^7.0.0-alpha.
|
|
55
|
-
"benchmark": "
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
55
|
+
"@mapbox/geojsonhint": "^3.2.0",
|
|
56
|
+
"@turf/bbox-polygon": "^7.0.0-alpha.110+1411d63a7",
|
|
57
|
+
"@turf/circle": "^7.0.0-alpha.110+1411d63a7",
|
|
58
|
+
"@turf/destination": "^7.0.0-alpha.110+1411d63a7",
|
|
59
|
+
"@turf/truncate": "^7.0.0-alpha.110+1411d63a7",
|
|
60
|
+
"@types/benchmark": "^2.1.5",
|
|
61
|
+
"@types/tape": "^4.2.32",
|
|
62
|
+
"benchmark": "^2.1.4",
|
|
63
|
+
"glob": "^10.3.10",
|
|
64
|
+
"load-json-file": "^7.0.1",
|
|
65
|
+
"npm-run-all": "^4.1.5",
|
|
66
|
+
"tape": "^5.7.2",
|
|
67
|
+
"tsup": "^8.0.1",
|
|
68
|
+
"tsx": "^4.6.2",
|
|
69
|
+
"typescript": "^5.2.2",
|
|
70
|
+
"write-json-file": "^5.0.0"
|
|
63
71
|
},
|
|
64
72
|
"dependencies": {
|
|
65
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
66
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
67
|
-
"@turf/rhumb-destination": "^7.0.0-alpha.
|
|
68
|
-
"@turf/transform-rotate": "^7.0.0-alpha.
|
|
73
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
74
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
75
|
+
"@turf/rhumb-destination": "^7.0.0-alpha.110+1411d63a7",
|
|
76
|
+
"@turf/transform-rotate": "^7.0.0-alpha.110+1411d63a7",
|
|
77
|
+
"tslib": "^2.6.2"
|
|
69
78
|
},
|
|
70
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
71
80
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { isObject, isNumber, degreesToRadians, polygon } from '@turf/helpers';
|
|
2
|
-
import rhumbDestination from '@turf/rhumb-destination';
|
|
3
|
-
import transformRotate from '@turf/transform-rotate';
|
|
4
|
-
import { getCoord } from '@turf/invariant';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
|
|
8
|
-
*
|
|
9
|
-
* @param {Coord} center center point
|
|
10
|
-
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis
|
|
11
|
-
* @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis
|
|
12
|
-
* @param {Object} [options={}] Optional parameters
|
|
13
|
-
* @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise
|
|
14
|
-
* @param {Coord} [options.pivot='origin'] point around which the rotation will be performed
|
|
15
|
-
* @param {number} [options.steps=64] number of steps
|
|
16
|
-
* @param {string} [options.units='kilometers'] unit of measurement for axes
|
|
17
|
-
* @param {Object} [options.properties={}] properties
|
|
18
|
-
* @returns {Feature<Polygon>} ellipse polygon
|
|
19
|
-
* @example
|
|
20
|
-
* var center = [-75, 40];
|
|
21
|
-
* var xSemiAxis = 5;
|
|
22
|
-
* var ySemiAxis = 2;
|
|
23
|
-
* var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);
|
|
24
|
-
*
|
|
25
|
-
* //addToMap
|
|
26
|
-
* var addToMap = [turf.point(center), ellipse]
|
|
27
|
-
*/
|
|
28
|
-
function ellipse(center, xSemiAxis, ySemiAxis, options) {
|
|
29
|
-
// Optional params
|
|
30
|
-
options = options || {};
|
|
31
|
-
var steps = options.steps || 64;
|
|
32
|
-
var units = options.units || "kilometers";
|
|
33
|
-
var angle = options.angle || 0;
|
|
34
|
-
var pivot = options.pivot || center;
|
|
35
|
-
var properties = options.properties || center.properties || {};
|
|
36
|
-
|
|
37
|
-
// validation
|
|
38
|
-
if (!center) throw new Error("center is required");
|
|
39
|
-
if (!xSemiAxis) throw new Error("xSemiAxis is required");
|
|
40
|
-
if (!ySemiAxis) throw new Error("ySemiAxis is required");
|
|
41
|
-
if (!isObject(options)) throw new Error("options must be an object");
|
|
42
|
-
if (!isNumber(steps)) throw new Error("steps must be a number");
|
|
43
|
-
if (!isNumber(angle)) throw new Error("angle must be a number");
|
|
44
|
-
|
|
45
|
-
var centerCoords = getCoord(center);
|
|
46
|
-
if (units === "degrees") {
|
|
47
|
-
var angleRad = degreesToRadians(angle);
|
|
48
|
-
} else {
|
|
49
|
-
xSemiAxis = rhumbDestination(center, xSemiAxis, 90, { units: units });
|
|
50
|
-
ySemiAxis = rhumbDestination(center, ySemiAxis, 0, { units: units });
|
|
51
|
-
xSemiAxis = getCoord(xSemiAxis)[0] - centerCoords[0];
|
|
52
|
-
ySemiAxis = getCoord(ySemiAxis)[1] - centerCoords[1];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var coordinates = [];
|
|
56
|
-
for (var i = 0; i < steps; i += 1) {
|
|
57
|
-
var stepAngle = (i * -360) / steps;
|
|
58
|
-
var x =
|
|
59
|
-
(xSemiAxis * ySemiAxis) /
|
|
60
|
-
Math.sqrt(
|
|
61
|
-
Math.pow(ySemiAxis, 2) +
|
|
62
|
-
Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)
|
|
63
|
-
);
|
|
64
|
-
var y =
|
|
65
|
-
(xSemiAxis * ySemiAxis) /
|
|
66
|
-
Math.sqrt(
|
|
67
|
-
Math.pow(xSemiAxis, 2) +
|
|
68
|
-
Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (stepAngle < -90 && stepAngle >= -270) x = -x;
|
|
72
|
-
if (stepAngle < -180 && stepAngle >= -360) y = -y;
|
|
73
|
-
if (units === "degrees") {
|
|
74
|
-
var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
|
|
75
|
-
var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
|
|
76
|
-
x = newx;
|
|
77
|
-
y = newy;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
|
|
81
|
-
}
|
|
82
|
-
coordinates.push(coordinates[0]);
|
|
83
|
-
if (units === "degrees") {
|
|
84
|
-
return polygon([coordinates], properties);
|
|
85
|
-
} else {
|
|
86
|
-
return transformRotate(polygon([coordinates], properties), angle, {
|
|
87
|
-
pivot: pivot,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get Tan Degrees
|
|
94
|
-
*
|
|
95
|
-
* @private
|
|
96
|
-
* @param {number} deg Degrees
|
|
97
|
-
* @returns {number} Tan Degrees
|
|
98
|
-
*/
|
|
99
|
-
function getTanDeg(deg) {
|
|
100
|
-
var rad = (deg * Math.PI) / 180;
|
|
101
|
-
return Math.tan(rad);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default ellipse;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var helpers = require('@turf/helpers');
|
|
4
|
-
var rhumbDestination = require('@turf/rhumb-destination');
|
|
5
|
-
var transformRotate = require('@turf/transform-rotate');
|
|
6
|
-
var invariant = require('@turf/invariant');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestination);
|
|
11
|
-
var transformRotate__default = /*#__PURE__*/_interopDefaultLegacy(transformRotate);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Takes a {@link Point} and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
|
|
15
|
-
*
|
|
16
|
-
* @param {Coord} center center point
|
|
17
|
-
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis
|
|
18
|
-
* @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis
|
|
19
|
-
* @param {Object} [options={}] Optional parameters
|
|
20
|
-
* @param {number} [options.angle=0] angle of rotation in decimal degrees, positive clockwise
|
|
21
|
-
* @param {Coord} [options.pivot='origin'] point around which the rotation will be performed
|
|
22
|
-
* @param {number} [options.steps=64] number of steps
|
|
23
|
-
* @param {string} [options.units='kilometers'] unit of measurement for axes
|
|
24
|
-
* @param {Object} [options.properties={}] properties
|
|
25
|
-
* @returns {Feature<Polygon>} ellipse polygon
|
|
26
|
-
* @example
|
|
27
|
-
* var center = [-75, 40];
|
|
28
|
-
* var xSemiAxis = 5;
|
|
29
|
-
* var ySemiAxis = 2;
|
|
30
|
-
* var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);
|
|
31
|
-
*
|
|
32
|
-
* //addToMap
|
|
33
|
-
* var addToMap = [turf.point(center), ellipse]
|
|
34
|
-
*/
|
|
35
|
-
function ellipse(center, xSemiAxis, ySemiAxis, options) {
|
|
36
|
-
// Optional params
|
|
37
|
-
options = options || {};
|
|
38
|
-
var steps = options.steps || 64;
|
|
39
|
-
var units = options.units || "kilometers";
|
|
40
|
-
var angle = options.angle || 0;
|
|
41
|
-
var pivot = options.pivot || center;
|
|
42
|
-
var properties = options.properties || center.properties || {};
|
|
43
|
-
|
|
44
|
-
// validation
|
|
45
|
-
if (!center) throw new Error("center is required");
|
|
46
|
-
if (!xSemiAxis) throw new Error("xSemiAxis is required");
|
|
47
|
-
if (!ySemiAxis) throw new Error("ySemiAxis is required");
|
|
48
|
-
if (!helpers.isObject(options)) throw new Error("options must be an object");
|
|
49
|
-
if (!helpers.isNumber(steps)) throw new Error("steps must be a number");
|
|
50
|
-
if (!helpers.isNumber(angle)) throw new Error("angle must be a number");
|
|
51
|
-
|
|
52
|
-
var centerCoords = invariant.getCoord(center);
|
|
53
|
-
if (units === "degrees") {
|
|
54
|
-
var angleRad = helpers.degreesToRadians(angle);
|
|
55
|
-
} else {
|
|
56
|
-
xSemiAxis = rhumbDestination__default['default'](center, xSemiAxis, 90, { units: units });
|
|
57
|
-
ySemiAxis = rhumbDestination__default['default'](center, ySemiAxis, 0, { units: units });
|
|
58
|
-
xSemiAxis = invariant.getCoord(xSemiAxis)[0] - centerCoords[0];
|
|
59
|
-
ySemiAxis = invariant.getCoord(ySemiAxis)[1] - centerCoords[1];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var coordinates = [];
|
|
63
|
-
for (var i = 0; i < steps; i += 1) {
|
|
64
|
-
var stepAngle = (i * -360) / steps;
|
|
65
|
-
var x =
|
|
66
|
-
(xSemiAxis * ySemiAxis) /
|
|
67
|
-
Math.sqrt(
|
|
68
|
-
Math.pow(ySemiAxis, 2) +
|
|
69
|
-
Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2)
|
|
70
|
-
);
|
|
71
|
-
var y =
|
|
72
|
-
(xSemiAxis * ySemiAxis) /
|
|
73
|
-
Math.sqrt(
|
|
74
|
-
Math.pow(xSemiAxis, 2) +
|
|
75
|
-
Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2)
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
if (stepAngle < -90 && stepAngle >= -270) x = -x;
|
|
79
|
-
if (stepAngle < -180 && stepAngle >= -360) y = -y;
|
|
80
|
-
if (units === "degrees") {
|
|
81
|
-
var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
|
|
82
|
-
var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
|
|
83
|
-
x = newx;
|
|
84
|
-
y = newy;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
|
|
88
|
-
}
|
|
89
|
-
coordinates.push(coordinates[0]);
|
|
90
|
-
if (units === "degrees") {
|
|
91
|
-
return helpers.polygon([coordinates], properties);
|
|
92
|
-
} else {
|
|
93
|
-
return transformRotate__default['default'](helpers.polygon([coordinates], properties), angle, {
|
|
94
|
-
pivot: pivot,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get Tan Degrees
|
|
101
|
-
*
|
|
102
|
-
* @private
|
|
103
|
-
* @param {number} deg Degrees
|
|
104
|
-
* @returns {number} Tan Degrees
|
|
105
|
-
*/
|
|
106
|
-
function getTanDeg(deg) {
|
|
107
|
-
var rad = (deg * Math.PI) / 180;
|
|
108
|
-
return Math.tan(rad);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
module.exports = ellipse;
|
|
112
|
-
module.exports.default = ellipse;
|
package/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Feature, Polygon, GeoJsonProperties } from "geojson";
|
|
2
|
-
import { Coord, Units } from "@turf/helpers";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* http://turfjs.org/docs/#ellipse
|
|
6
|
-
*/
|
|
7
|
-
export default function (
|
|
8
|
-
center: Coord,
|
|
9
|
-
xSemiAxis: number,
|
|
10
|
-
ySemiAxis: number,
|
|
11
|
-
options?: {
|
|
12
|
-
/** default 64 */
|
|
13
|
-
steps?: number;
|
|
14
|
-
/** default kilometers */
|
|
15
|
-
units?: Units;
|
|
16
|
-
properties?: GeoJsonProperties;
|
|
17
|
-
/**
|
|
18
|
-
* Angle of rotation in decimal degrees, positive clockwise
|
|
19
|
-
* default 0
|
|
20
|
-
*/
|
|
21
|
-
angle?: number;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* point around which the rotation will be performed
|
|
25
|
-
* default is the point specified by center
|
|
26
|
-
*/
|
|
27
|
-
pivot?: Coord;
|
|
28
|
-
}
|
|
29
|
-
): Feature<Polygon>;
|