Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/ellipse

Package Overview
Dependencies
Maintainers
6
Versions
25
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 6.2.0-alpha.2 to 6.2.0-alpha.3

dist/es/package.json

104

dist/es/index.js

@@ -29,51 +29,63 @@ import { degreesToRadians, polygon, isObject, isNumber } from '@turf/helpers';

function ellipse(center, xSemiAxis, ySemiAxis, options) {
// Optional params
options = options || {};
var steps = options.steps || 64;
var units = options.units || 'kilometers';
var angle = options.angle || 0;
var pivot = options.pivot || center;
var properties = options.properties || center.properties || {};
// Optional params
options = options || {};
var steps = options.steps || 64;
var units = options.units || "kilometers";
var angle = options.angle || 0;
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 (!isObject(options)) throw new Error('options must be an object');
if (!isNumber(steps)) throw new Error('steps must be a number');
if (!isNumber(angle)) throw new Error('angle must be a number');
// 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 (!isObject(options)) throw new Error("options must be an object");
if (!isNumber(steps)) throw new Error("steps must be a number");
if (!isNumber(angle)) throw new Error("angle must be a number");
var centerCoords = getCoord(center);
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 centerCoords = getCoord(center);
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) {
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))));
var coordinates = [];
for (var i = 0; i < steps; i += 1) {
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 (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;
}
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
if (units === 'degrees') {
return polygon([coordinates], properties);
} else {
return transformRotate(polygon([coordinates], properties), angle, { pivot: pivot });
}
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
if (units === "degrees") {
return polygon([coordinates], properties);
} else {
return transformRotate(polygon([coordinates], properties), angle, {
pivot: pivot,
});
}
}

@@ -89,6 +101,6 @@

function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
var rad = (deg * Math.PI) / 180;
return Math.tan(rad);
}
export default ellipse;

@@ -33,51 +33,63 @@ 'use strict';

function ellipse(center, xSemiAxis, ySemiAxis, options) {
// Optional params
options = options || {};
var steps = options.steps || 64;
var units = options.units || 'kilometers';
var angle = options.angle || 0;
var pivot = options.pivot || center;
var properties = options.properties || center.properties || {};
// Optional params
options = options || {};
var steps = options.steps || 64;
var units = options.units || "kilometers";
var angle = options.angle || 0;
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');
// 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");
var centerCoords = invariant.getCoord(center);
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 centerCoords = invariant.getCoord(center);
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) {
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))));
var coordinates = [];
for (var i = 0; i < steps; i += 1) {
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 (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;
}
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
if (units === 'degrees') {
return helpers.polygon([coordinates], properties);
} else {
return transformRotate(helpers.polygon([coordinates], properties), angle, { pivot: pivot });
}
coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
}
coordinates.push(coordinates[0]);
if (units === "degrees") {
return helpers.polygon([coordinates], properties);
} else {
return transformRotate(helpers.polygon([coordinates], properties), angle, {
pivot: pivot,
});
}
}

@@ -93,7 +105,6 @@

function getTanDeg(deg) {
var rad = deg * Math.PI / 180;
return Math.tan(rad);
var rad = (deg * Math.PI) / 180;
return Math.tan(rad);
}
module.exports = ellipse;
module.exports.default = ellipse;

@@ -1,2 +0,2 @@

import { Feature, Coord, Polygon, Units, Properties } from '@turf/helpers'
import { Feature, Coord, Polygon, Units, Properties } from "@turf/helpers";

@@ -7,10 +7,10 @@ /**

export default function (
center: Coord,
xSemiAxis: number,
ySemiAxis: number,
options?: {
steps?: number;
units?: Units;
properties?: Properties;
}
center: Coord,
xSemiAxis: number,
ySemiAxis: number,
options?: {
steps?: number;
units?: Units;
properties?: Properties;
}
): Feature<Polygon>;
{
"name": "@turf/ellipse",
"version": "6.2.0-alpha.2",
"version": "6.2.0-alpha.3",
"description": "turf ellipse module",

@@ -27,2 +27,6 @@ "author": "Turf Authors",

"module": "dist/es/index.js",
"exports": {
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
},
"types": "index.d.ts",

@@ -35,8 +39,7 @@ "sideEffects": false,

"scripts": {
"bench": "npm-run-all prepare bench:run",
"bench:run": "node bench.js",
"bench": "node -r esm bench.js",
"build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
"docs": "node ../../scripts/generate-readmes",
"posttest": "node -r esm ../../scripts/validate-es5-dependencies.js",
"prepare": "rollup -c ../../rollup.config.js",
"test": "npm-run-all prepare test:*",
"test": "npm-run-all test:*",
"test:tape": "node -r esm test.js"

@@ -46,6 +49,6 @@ },

"@mapbox/geojsonhint": "*",
"@turf/bbox-polygon": "^6.2.0-alpha.2",
"@turf/circle": "^6.2.0-alpha.2",
"@turf/destination": "^6.2.0-alpha.2",
"@turf/truncate": "^6.2.0-alpha.2",
"@turf/bbox-polygon": "^6.2.0-alpha.3",
"@turf/circle": "^6.2.0-alpha.3",
"@turf/destination": "^6.2.0-alpha.3",
"@turf/truncate": "^6.2.0-alpha.3",
"benchmark": "*",

@@ -60,8 +63,8 @@ "glob": "*",

"dependencies": {
"@turf/helpers": "^6.2.0-alpha.2",
"@turf/invariant": "^6.2.0-alpha.2",
"@turf/rhumb-destination": "^6.2.0-alpha.2",
"@turf/transform-rotate": "^6.2.0-alpha.2"
"@turf/helpers": "^6.2.0-alpha.3",
"@turf/invariant": "^6.2.0-alpha.3",
"@turf/rhumb-destination": "^6.2.0-alpha.3",
"@turf/transform-rotate": "^6.2.0-alpha.3"
},
"gitHead": "23d5cb91d77e0c1e2e903a2252f525797f1d0d09"
"gitHead": "dce9edfc705352e8cb9e0083c9330ba0e8d77409"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc