Comparing version 1.1.3 to 1.1.4
@@ -128,2 +128,6 @@ import { DLine } from './DLine'; | ||
/** | ||
* Check if point looks like radians | ||
*/ | ||
get likeRadians(): boolean; | ||
/** | ||
* Check if point looks like `EPSG:4326` (degrees) | ||
@@ -130,0 +134,0 @@ */ |
@@ -6,3 +6,5 @@ "use strict"; | ||
const DPolygon_1 = require("./DPolygon"); | ||
const utils_1 = require("./utils"); | ||
const diff = 0; | ||
const radiansPolygon = new DPolygon_1.DPolygon(); | ||
/** | ||
@@ -75,2 +77,5 @@ * Meters | ||
getTileFromCoords(zoom = this.z) { | ||
utils_1.checkFunction('getTileFromCoords') | ||
.checkArgument('this') | ||
.shouldBeDegree(this); | ||
const x = Math.floor((this.x + exports.PI_IN_DEGREE) / exports.DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom))); | ||
@@ -81,2 +86,5 @@ const y = Math.floor((1 - Math.log(Math.tan(this.y * exports.PI_TO_DEGREE) + 1 / Math.cos(this.y * exports.PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom))); | ||
getCoordsFromTile(zoom = this.z) { | ||
utils_1.checkFunction('getCoordsFromTile') | ||
.checkArgument('this') | ||
.shouldBeUInt(this); | ||
const n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom)); | ||
@@ -98,2 +106,7 @@ const x = this.x / (Math.pow(2, zoom)) * exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE; | ||
findLine(p) { | ||
utils_1.checkFunction('findLine') | ||
.checkArgument('this') | ||
.shouldBeMeters(this) | ||
.checkArgument('p') | ||
.shouldBeMeters(p); | ||
if (this.equal(p)) { | ||
@@ -114,2 +127,9 @@ return this.findLine(p.clone().moveCurrent(0, 1)); | ||
findInnerAngle(p1, p3) { | ||
utils_1.checkFunction('findInnerAngle') | ||
.checkArgument('this') | ||
.shouldBeMeters(this) | ||
.checkArgument('p1') | ||
.shouldBeMeters(p1) | ||
.checkArgument('p3') | ||
.shouldBeMeters(p3); | ||
const a1 = this.findLine(p1).getFi(); | ||
@@ -149,2 +169,7 @@ const a2 = this.findLine(p3).getFi(); | ||
distance(p) { | ||
utils_1.checkFunction('distance') | ||
.checkArgument('this') | ||
.shouldBeMeters(this) | ||
.checkArgument('p') | ||
.shouldBeMeters(p); | ||
const dx = p.x - this.x; | ||
@@ -276,5 +301,11 @@ const dy = p.y - this.y; | ||
asRadians() { | ||
utils_1.checkFunction('asRadians') | ||
.checkArgument('this') | ||
.shouldBeDegree(this); | ||
return this.scaleCurrent(exports.PI_TO_DEGREE); | ||
} | ||
asDegrees() { | ||
utils_1.checkFunction('asDegrees') | ||
.checkArgument('this') | ||
.shouldBeRadians(this); | ||
return this.scaleCurrent(exports.DEGREE_TO_PI); | ||
@@ -347,2 +378,11 @@ } | ||
/** | ||
* Check if point looks like radians | ||
*/ | ||
get likeRadians() { | ||
if (radiansPolygon.length === 0) { | ||
radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2)); | ||
} | ||
return radiansPolygon.simpleInclude(this); | ||
} | ||
/** | ||
* Check if point looks like `EPSG:4326` (degrees) | ||
@@ -354,3 +394,3 @@ */ | ||
} | ||
return worldGeodeticPolygon.simpleInclude(this); | ||
return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this); | ||
} | ||
@@ -364,3 +404,3 @@ /** | ||
} | ||
return !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this); | ||
return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this); | ||
} | ||
@@ -380,5 +420,11 @@ get w() { | ||
get area() { | ||
utils_1.checkFunction('area') | ||
.checkArgument('this') | ||
.shouldBeMeters(this); | ||
return this.w * this.h; | ||
} | ||
get hip() { | ||
utils_1.checkFunction('hip') | ||
.checkArgument('this') | ||
.shouldBeMeters(this); | ||
return Math.sqrt(this.w * this.w + this.h * this.h); | ||
@@ -425,2 +471,7 @@ } | ||
orthodromicPath(point, pointsCount = 360) { | ||
utils_1.checkFunction('orthodromicPath') | ||
.checkArgument('this') | ||
.shouldBeDegree(this) | ||
.checkArgument('point') | ||
.shouldBeDegree(point); | ||
const t = this.clone().asRadians(); | ||
@@ -439,2 +490,5 @@ const p = point.clone().asRadians(); | ||
degrees2meters() { | ||
utils_1.checkFunction('degrees2meters') | ||
.checkArgument('this') | ||
.shouldBeDegree(this); | ||
const x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE; | ||
@@ -448,2 +502,5 @@ const y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) * | ||
meters2degrees() { | ||
utils_1.checkFunction('meters2degrees') | ||
.checkArgument('this') | ||
.shouldBeMeters(this); | ||
const lon = this.x * DEGREES_IN_ONE_MITER; | ||
@@ -450,0 +507,0 @@ const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) * |
@@ -7,2 +7,5 @@ import { DPoint } from '../src'; | ||
shouldBeMeters: CheckFunc; | ||
shouldBeInt: CheckFunc; | ||
shouldBeUInt: CheckFunc; | ||
shouldBeRadians: CheckFunc; | ||
} | ||
@@ -9,0 +12,0 @@ interface CheckFunction { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const index_1 = require("./index"); | ||
const src_1 = require("../src"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -14,2 +15,17 @@ const warn = (...args) => { | ||
exports.warn = warn; | ||
const hook = (scope) => () => scope; | ||
const shouldBeInt = (scope, funcName, argName) => (p) => { | ||
if (!p.clone().roundCurrent() | ||
.equal(p)) { | ||
exports.warn(`"${funcName}" -> "${argName}" should be Int!`); | ||
} | ||
return scope; | ||
}; | ||
const shouldBeUInt = (scope, funcName, argName) => (p) => { | ||
if (!p.clone().roundCurrent() | ||
.equal(p) || p.gtOrEqual(src_1.DPoint.Zero())) { | ||
exports.warn(`"${funcName}" -> "${argName}" should be UInt!`); | ||
} | ||
return scope; | ||
}; | ||
const shouldBeDegree = (scope, funcName, argName) => (p) => { | ||
@@ -21,2 +37,8 @@ if (!p.likeWorldGeodeticSystem) { | ||
}; | ||
const shouldBeRadians = (scope, funcName, argName) => (p) => { | ||
if (!p.likeRadians) { | ||
exports.warn(`"${funcName}" -> "${argName}" should be radians!`); | ||
} | ||
return scope; | ||
}; | ||
const shouldBeMeters = (scope, funcName, argName) => (p) => { | ||
@@ -29,7 +51,19 @@ if (!p.likePseudoMercator) { | ||
const checkFunction = (funcName) => ({ | ||
// eslint-disable-next-line func-names | ||
// eslint-disable-next-line func-names, object-shorthand | ||
checkArgument: function (argName) { | ||
if (!index_1.DGeo.DEBUG) { | ||
return { | ||
shouldBeDegree: hook(this), | ||
shouldBeMeters: hook(this), | ||
shouldBeInt: hook(this), | ||
shouldBeUInt: hook(this), | ||
shouldBeRadians: hook(this) | ||
}; | ||
} | ||
return { | ||
shouldBeDegree: shouldBeDegree(this, funcName, argName), | ||
shouldBeMeters: shouldBeMeters(this, funcName, argName) | ||
shouldBeMeters: shouldBeMeters(this, funcName, argName), | ||
shouldBeInt: shouldBeInt(this, funcName, argName), | ||
shouldBeUInt: shouldBeUInt(this, funcName, argName), | ||
shouldBeRadians: shouldBeRadians(this, funcName, argName) | ||
}; | ||
@@ -36,0 +70,0 @@ } |
{ | ||
"name": "dgeoutils", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "", | ||
"scripts": { | ||
"build": "node_modules/.bin/tsc", | ||
"prepare": "npm run doc && npm run test && npm run test:badges && npm run build", | ||
"prepare": "npm run lint && npm run doc && npm run test && npm run test:badges && npm run build", | ||
"lint": "node_modules/.bin/eslint src/", | ||
@@ -9,0 +9,0 @@ "doc": "node_modules/.bin/typedoc", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94738
2898