@turf/bezier-spline
Advanced tools
Comparing version 5.1.0 to 5.1.5
52
main.js
@@ -35,4 +35,2 @@ 'use strict'; | ||
var Spline = function (options) { | ||
var this$1 = this; | ||
this.points = options.points || []; | ||
@@ -47,7 +45,7 @@ this.duration = options.duration || 10000; | ||
// this is to ensure compatibility with the 2d version | ||
for (var i = 0; i < this.length; i++) { this$1.points[i].z = this$1.points[i].z || 0; } | ||
for (var i = 0; i < this.length; i++) this.points[i].z = this.points[i].z || 0; | ||
for (var i = 0; i < this.length - 1; i++) { | ||
var p1 = this$1.points[i]; | ||
var p2 = this$1.points[i + 1]; | ||
this$1.centers.push({ | ||
var p1 = this.points[i]; | ||
var p2 = this.points[i + 1]; | ||
this.centers.push({ | ||
x: (p1.x + p2.x) / 2, | ||
@@ -60,15 +58,15 @@ y: (p1.y + p2.y) / 2, | ||
for (var i = 0; i < this.centers.length - 1; i++) { | ||
var p1 = this$1.centers[i]; | ||
var p2 = this$1.centers[i + 1]; | ||
var dx = this$1.points[i + 1].x - (this$1.centers[i].x + this$1.centers[i + 1].x) / 2; | ||
var dy = this$1.points[i + 1].y - (this$1.centers[i].y + this$1.centers[i + 1].y) / 2; | ||
var dz = this$1.points[i + 1].z - (this$1.centers[i].y + this$1.centers[i + 1].z) / 2; | ||
this$1.controls.push([{ | ||
x: (1.0 - this$1.sharpness) * this$1.points[i + 1].x + this$1.sharpness * (this$1.centers[i].x + dx), | ||
y: (1.0 - this$1.sharpness) * this$1.points[i + 1].y + this$1.sharpness * (this$1.centers[i].y + dy), | ||
z: (1.0 - this$1.sharpness) * this$1.points[i + 1].z + this$1.sharpness * (this$1.centers[i].z + dz)}, | ||
var p1 = this.centers[i]; | ||
var p2 = this.centers[i + 1]; | ||
var dx = this.points[i + 1].x - (this.centers[i].x + this.centers[i + 1].x) / 2; | ||
var dy = this.points[i + 1].y - (this.centers[i].y + this.centers[i + 1].y) / 2; | ||
var dz = this.points[i + 1].z - (this.centers[i].y + this.centers[i + 1].z) / 2; | ||
this.controls.push([{ | ||
x: (1.0 - this.sharpness) * this.points[i + 1].x + this.sharpness * (this.centers[i].x + dx), | ||
y: (1.0 - this.sharpness) * this.points[i + 1].y + this.sharpness * (this.centers[i].y + dy), | ||
z: (1.0 - this.sharpness) * this.points[i + 1].z + this.sharpness * (this.centers[i].z + dz)}, | ||
{ | ||
x: (1.0 - this$1.sharpness) * this$1.points[i + 1].x + this$1.sharpness * (this$1.centers[i + 1].x + dx), | ||
y: (1.0 - this$1.sharpness) * this$1.points[i + 1].y + this$1.sharpness * (this$1.centers[i + 1].y + dy), | ||
z: (1.0 - this$1.sharpness) * this$1.points[i + 1].z + this$1.sharpness * (this$1.centers[i + 1].z + dz)}]); | ||
x: (1.0 - this.sharpness) * this.points[i + 1].x + this.sharpness * (this.centers[i + 1].x + dx), | ||
y: (1.0 - this.sharpness) * this.points[i + 1].y + this.sharpness * (this.centers[i + 1].y + dy), | ||
z: (1.0 - this.sharpness) * this.points[i + 1].z + this.sharpness * (this.centers[i + 1].z + dz)}]); | ||
} | ||
@@ -84,4 +82,2 @@ this.controls.push([this.points[this.length - 1], this.points[this.length - 1]]); | ||
Spline.prototype.cacheSteps = function (mindist) { | ||
var this$1 = this; | ||
var steps = []; | ||
@@ -91,3 +87,3 @@ var laststep = this.pos(0); | ||
for (var t = 0; t < this.duration; t += 10) { | ||
var step = this$1.pos(t); | ||
var step = this.pos(t); | ||
var dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) + (step.y - laststep.y) * (step.y - laststep.y) + (step.z - laststep.z) * (step.z - laststep.z)); | ||
@@ -137,7 +133,7 @@ if (dist > mindist) { | ||
var t = time - this.delay; | ||
if (t < 0) { t = 0; } | ||
if (t > this.duration) { t = this.duration - 1; } | ||
if (t < 0) t = 0; | ||
if (t > this.duration) t = this.duration - 1; | ||
//t = t-this.delay; | ||
var t2 = (t) / this.duration; | ||
if (t2 >= 1) { return this.points[this.length - 1]; } | ||
if (t2 >= 1) return this.points[this.length - 1]; | ||
@@ -181,3 +177,3 @@ var n = Math.floor((this.points.length - 1) * t2); | ||
options = options || {}; | ||
if (!helpers.isObject(options)) { throw new Error('options is invalid'); } | ||
if (!helpers.isObject(options)) throw new Error('options is invalid'); | ||
var resolution = options.resolution || 10000; | ||
@@ -187,5 +183,5 @@ var sharpness = options.sharpness || 0.85; | ||
// validation | ||
if (!line) { throw new Error('line is required'); } | ||
if (!helpers.isNumber(resolution)) { throw new Error('resolution must be an number'); } | ||
if (!helpers.isNumber(sharpness)) { throw new Error('sharpness must be an number'); } | ||
if (!line) throw new Error('line is required'); | ||
if (!helpers.isNumber(resolution)) throw new Error('resolution must be an number'); | ||
if (!helpers.isNumber(sharpness)) throw new Error('sharpness must be an number'); | ||
@@ -192,0 +188,0 @@ var coords = []; |
{ | ||
"name": "@turf/bezier-spline", | ||
"version": "5.1.0", | ||
"version": "5.1.5", | ||
"description": "turf bezier-spline module", | ||
"main": "main.js", | ||
"module": "main.mjs", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
@@ -13,3 +13,3 @@ "files": [ | ||
"lib", | ||
"main.mjs" | ||
"main.es.js" | ||
], | ||
@@ -19,2 +19,3 @@ "scripts": { | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
@@ -45,3 +46,2 @@ "docs": "node ../../scripts/generate-readmes" | ||
"rollup": "*", | ||
"rollup-plugin-buble": "*", | ||
"tape": "*", | ||
@@ -51,4 +51,4 @@ "write-json-file": "*" | ||
"dependencies": { | ||
"@turf/helpers": "^5.1.0", | ||
"@turf/invariant": "^5.1.0" | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/invariant": "^5.1.5" | ||
}, | ||
@@ -55,0 +55,0 @@ "@std/esm": { |
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
6
27649
561
Updated@turf/helpers@^5.1.5
Updated@turf/invariant@^5.1.5