🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@turf/ellipse

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/ellipse - npm Package Compare versions

Comparing version

to
5.1.0

main.mjs

72

index.js

@@ -1,4 +0,5 @@

import { polygon, lengthToDegrees, isObject, isNumber } from '@turf/helpers';
import { degreesToRadians, polygon, isObject, isNumber } from '@turf/helpers';
import rhumbDestination from '@turf/rhumb-destination';
import transformRotate from '@turf/transform-rotate';
import { getCoord } from '@turf/invariant';
import transformRotate from '@turf/transform-rotate';

@@ -8,3 +9,3 @@ /**

*
* @param {Feature<Point>|Array<number>} center center point
* @param {Coord} center center point
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis

@@ -14,3 +15,3 @@ * @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis

* @param {number} [options.angle=0] angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise
* @param {Geometry|Feature<Point>|Array<number>} [options.pivot='origin'] point around which the rotation will be performed
* @param {Coord} [options.pivot='origin'] point around which the rotation will be performed
* @param {number} [options.steps=64] number of steps

@@ -35,3 +36,3 @@ * @param {string} [options.units='kilometers'] unit of measurement for axes

var angle = options.angle || 0;
var pivot = options.pivot || null;
var pivot = options.pivot || center;
var properties = options.properties || center.properties || {};

@@ -48,37 +49,48 @@

var centerCoords = getCoord(center);
xSemiAxis = lengthToDegrees(xSemiAxis, units);
ySemiAxis = lengthToDegrees(ySemiAxis, units);
if (units === 'degrees') {
var angleRad = degreesToRadians(angle);
} else {
xSemiAxis = rhumbDestination(center, xSemiAxis, 90, {units: units});
ySemiAxis = rhumbDestination(center, ySemiAxis, 0, {units: units});
xSemiAxis = getCoord(xSemiAxis)[0] - centerCoords[0];
ySemiAxis = getCoord(ySemiAxis)[1] - centerCoords[1];
}
var coordinates = [];
for (var i = 0; i < steps; i += 1) {
angle = i * -360 / steps;
var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(angle), 2))));
var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(angle), 2))));
if (angle < -90 && angle >= -270) {
x = -x;
var stepAngle = i * -360 / steps;
var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2))));
var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2))));
if (stepAngle < -90 && stepAngle >= -270) x = -x;
if (stepAngle < -180 && stepAngle >= -360) y = -y;
if (units === 'degrees') {
var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
x = newx;
y = newy;
}
if (angle < -180 && angle >= -360) {
y = -y;
}
coordinates.push([x + centerCoords[0],
y + centerCoords[1]
]);
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
return transformRotate(polygon([coordinates], properties), angle, { pivot: pivot });
/**
* Get Tan Degrees
*
* @private
* @param {number} deg Degrees
* @returns {number} Tan Degrees
*/
function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
if (units === 'degrees') {
return polygon([coordinates], properties);
} else {
return transformRotate(polygon([coordinates], properties), angle, { pivot: pivot });
}
}
/**
* Get Tan Degrees
*
* @private
* @param {number} deg Degrees
* @returns {number} Tan Degrees
*/
function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
}
export default ellipse;

@@ -6,4 +6,5 @@ 'use strict';

var helpers = require('@turf/helpers');
var rhumbDestination = _interopDefault(require('@turf/rhumb-destination'));
var transformRotate = _interopDefault(require('@turf/transform-rotate'));
var invariant = require('@turf/invariant');
var transformRotate = _interopDefault(require('@turf/transform-rotate'));

@@ -13,3 +14,3 @@ /**

*
* @param {Feature<Point>|Array<number>} center center point
* @param {Coord} center center point
* @param {number} xSemiAxis semi (major) axis of the ellipse along the x-axis

@@ -19,3 +20,3 @@ * @param {number} ySemiAxis semi (minor) axis of the ellipse along the y-axis

* @param {number} [options.angle=0] angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise
* @param {Geometry|Feature<Point>|Array<number>} [options.pivot='origin'] point around which the rotation will be performed
* @param {Coord} [options.pivot='origin'] point around which the rotation will be performed
* @param {number} [options.steps=64] number of steps

@@ -40,47 +41,58 @@ * @param {string} [options.units='kilometers'] unit of measurement for axes

var angle = options.angle || 0;
var pivot = options.pivot || null;
var pivot = options.pivot || center;
var properties = options.properties || center.properties || {};
// validation
if (!center) throw new Error('center is required');
if (!xSemiAxis) throw new Error('xSemiAxis is required');
if (!ySemiAxis) throw new Error('ySemiAxis is required');
if (!helpers.isObject(options)) throw new Error('options must be an object');
if (!helpers.isNumber(steps)) throw new Error('steps must be a number');
if (!helpers.isNumber(angle)) throw new Error('angle must be a number');
if (!center) { throw new Error('center is required'); }
if (!xSemiAxis) { throw new Error('xSemiAxis is required'); }
if (!ySemiAxis) { throw new Error('ySemiAxis is required'); }
if (!helpers.isObject(options)) { throw new Error('options must be an object'); }
if (!helpers.isNumber(steps)) { throw new Error('steps must be a number'); }
if (!helpers.isNumber(angle)) { throw new Error('angle must be a number'); }
var centerCoords = invariant.getCoord(center);
xSemiAxis = helpers.lengthToDegrees(xSemiAxis, units);
ySemiAxis = helpers.lengthToDegrees(ySemiAxis, units);
if (units === 'degrees') {
var angleRad = helpers.degreesToRadians(angle);
} else {
xSemiAxis = rhumbDestination(center, xSemiAxis, 90, {units: units});
ySemiAxis = rhumbDestination(center, ySemiAxis, 0, {units: units});
xSemiAxis = invariant.getCoord(xSemiAxis)[0] - centerCoords[0];
ySemiAxis = invariant.getCoord(ySemiAxis)[1] - centerCoords[1];
}
var coordinates = [];
for (var i = 0; i < steps; i += 1) {
angle = i * -360 / steps;
var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(angle), 2))));
var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(angle), 2))));
if (angle < -90 && angle >= -270) {
x = -x;
var stepAngle = i * -360 / steps;
var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2))));
var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2))));
if (stepAngle < -90 && stepAngle >= -270) { x = -x; }
if (stepAngle < -180 && stepAngle >= -360) { y = -y; }
if (units === 'degrees') {
var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
x = newx;
y = newy;
}
if (angle < -180 && angle >= -360) {
y = -y;
}
coordinates.push([x + centerCoords[0],
y + centerCoords[1]
]);
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
return transformRotate(helpers.polygon([coordinates], properties), angle, { pivot: pivot });
/**
* Get Tan Degrees
*
* @private
* @param {number} deg Degrees
* @returns {number} Tan Degrees
*/
function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
if (units === 'degrees') {
return helpers.polygon([coordinates], properties);
} else {
return transformRotate(helpers.polygon([coordinates], properties), angle, { pivot: pivot });
}
}
/**
* Get Tan Degrees
*
* @private
* @param {number} deg Degrees
* @returns {number} Tan Degrees
*/
function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
}

@@ -87,0 +99,0 @@

{
"name": "@turf/ellipse",
"version": "5.0.1",
"version": "5.1.0",
"description": "turf ellipse module",
"main": "main",
"module": "index",
"jsnext:main": "index",
"main": "main.js",
"module": "main.mjs",
"types": "index.d.ts",

@@ -12,3 +11,4 @@ "files": [

"index.d.ts",
"main.js"
"main.js",
"main.mjs"
],

@@ -18,3 +18,4 @@ "scripts": {

"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
"bench": "node -r @std/esm bench.js",
"docs": "node ../../scripts/generate-readmes"
},

@@ -41,6 +42,11 @@ "repository": {

"@std/esm": "*",
"@turf/bbox-polygon": "^5.1.0",
"@turf/circle": "^5.1.0",
"@turf/destination": "^5.1.0",
"@turf/truncate": "^5.1.0",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "^0.51.7",
"rollup": "*",
"rollup-plugin-buble": "*",
"tape": "*",

@@ -50,5 +56,6 @@ "write-json-file": "*"

"dependencies": {
"@turf/helpers": "^5.0.4",
"@turf/transform-rotate": "^5.0.4",
"@turf/invariant": "^5.0.4"
"@turf/helpers": "^5.1.0",
"@turf/invariant": "^5.1.0",
"@turf/rhumb-destination": "^5.1.0",
"@turf/transform-rotate": "^5.1.0"
},

@@ -55,0 +62,0 @@ "@std/esm": {

@@ -7,7 +7,7 @@ # @turf/ellipse

Takes a [Point](http://geojson.org/geojson-spec.html#point) and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
Takes a [Point](https://tools.ietf.org/html/rfc7946#section-3.1.2) and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.
**Parameters**
- `center` **([Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** center point
- `center` **[Coord](https://tools.ietf.org/html/rfc7946#section-3.1.1)** center point
- `xSemiAxis` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** semi (major) axis of the ellipse along the x-axis

@@ -17,3 +17,3 @@ - `ySemiAxis` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** semi (minor) axis of the ellipse along the y-axis

- `options.angle` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise (optional, default `0`)
- `options.pivot` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** point around which the rotation will be performed (optional, default `'origin'`)
- `options.pivot` **[Coord](https://tools.ietf.org/html/rfc7946#section-3.1.1)** point around which the rotation will be performed (optional, default `'origin'`)
- `options.steps` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of steps (optional, default `64`)

@@ -35,3 +35,3 @@ - `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** unit of measurement for axes (optional, default `'kilometers'`)

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Polygon](http://geojson.org/geojson-spec.html#polygon)>** ellipse polygon
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** ellipse polygon

@@ -38,0 +38,0 @@ <!-- This file is automatically generated. Please don't edit it directly: