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

@turf/bezier-spline

Package Overview
Dependencies
Maintainers
7
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/bezier-spline - npm Package Compare versions

Comparing version 6.5.0 to 7.0.0-alpha.0

19

dist/es/index.js

@@ -34,17 +34,16 @@ import { lineString } from "@turf/helpers";

*/
function bezier(line, options) {
if (options === void 0) { options = {}; }
function bezier(line, options = {}) {
// Optional params
var resolution = options.resolution || 10000;
var sharpness = options.sharpness || 0.85;
var coords = [];
var points = getGeom(line).coordinates.map(function (pt) {
const resolution = options.resolution || 10000;
const sharpness = options.sharpness || 0.85;
const coords = [];
const points = getGeom(line).coordinates.map((pt) => {
return { x: pt[0], y: pt[1] };
});
var spline = new Spline({
const spline = new Spline({
duration: resolution,
points: points,
sharpness: sharpness,
points,
sharpness,
});
var pushCoord = function (time) {
const pushCoord = (time) => {
var pos = spline.pos(time);

@@ -51,0 +50,0 @@ if (Math.floor(time / 100) % 2 === 0) {

@@ -27,4 +27,4 @@ /**

*/
var Spline = /** @class */ (function () {
function Spline(options) {
export default class Spline {
constructor(options) {
this.points = options.points || [];

@@ -39,8 +39,8 @@ this.duration = options.duration || 10000;

// this is to ensure compatibility with the 2d version
for (var i = 0; i < this.length; i++) {
for (let 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.points[i];
var p2 = this.points[i + 1];
for (let i = 0; i < this.length - 1; i++) {
const p1 = this.points[i];
const p2 = this.points[i + 1];
this.centers.push({

@@ -53,6 +53,6 @@ x: (p1.x + p2.x) / 2,

this.controls.push([this.points[0], this.points[0]]);
for (var i = 0; i < this.centers.length - 1; i++) {
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;
for (let i = 0; i < this.centers.length - 1; i++) {
const dx = this.points[i + 1].x - (this.centers[i].x + this.centers[i + 1].x) / 2;
const dy = this.points[i + 1].y - (this.centers[i].y + this.centers[i + 1].y) / 2;
const dz = this.points[i + 1].z - (this.centers[i].y + this.centers[i + 1].z) / 2;
this.controls.push([

@@ -87,9 +87,9 @@ {

*/
Spline.prototype.cacheSteps = function (mindist) {
var steps = [];
var laststep = this.pos(0);
cacheSteps(mindist) {
const steps = [];
let laststep = this.pos(0);
steps.push(0);
for (var t = 0; t < this.duration; t += 10) {
var step = this.pos(t);
var dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) +
for (let t = 0; t < this.duration; t += 10) {
const step = this.pos(t);
const dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) +
(step.y - laststep.y) * (step.y - laststep.y) +

@@ -103,9 +103,9 @@ (step.z - laststep.z) * (step.z - laststep.z));

return steps;
};
}
/**
* returns angle and speed in the given point in the curve
*/
Spline.prototype.vector = function (t) {
var p1 = this.pos(t + 10);
var p2 = this.pos(t - 10);
vector(t) {
const p1 = this.pos(t + 10);
const p2 = this.pos(t - 10);
return {

@@ -117,3 +117,3 @@ angle: (180 * Math.atan2(p1.y - p2.y, p1.x - p2.x)) / 3.14,

};
};
}
/**

@@ -126,4 +126,4 @@ * Gets the position of the point, given time.

*/
Spline.prototype.pos = function (time) {
var t = time - this.delay;
pos(time) {
let t = time - this.delay;
if (t < 0) {

@@ -136,16 +136,14 @@ t = 0;

// t = t-this.delay;
var t2 = t / this.duration;
const t2 = t / this.duration;
if (t2 >= 1) {
return this.points[this.length - 1];
}
var n = Math.floor((this.points.length - 1) * t2);
var t1 = (this.length - 1) * t2 - n;
const n = Math.floor((this.points.length - 1) * t2);
const t1 = (this.length - 1) * t2 - n;
return bezier(t1, this.points[n], this.controls[n][1], this.controls[n + 1][0], this.points[n + 1]);
};
return Spline;
}());
export default Spline;
}
}
function bezier(t, p1, c1, c2, p2) {
var b = B(t);
var pos = {
const b = B(t);
const pos = {
x: p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],

@@ -158,4 +156,4 @@ y: p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],

function B(t) {
var t2 = t * t;
var t3 = t2 * t;
const t2 = t * t;
const t3 = t2 * t;
return [

@@ -162,0 +160,0 @@ t3,

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

import { Feature, LineString, Properties } from "@turf/helpers";
import { Feature, LineString, GeoJsonProperties } from "geojson";
/**

@@ -32,3 +32,3 @@ * Takes a {@link LineString|line} and returns a curved version

*/
declare function bezier<P = Properties>(line: Feature<LineString> | LineString, options?: {
declare function bezier<P = GeoJsonProperties>(line: Feature<LineString> | LineString, options?: {
properties?: P;

@@ -35,0 +35,0 @@ resolution?: number;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
var spline_1 = __importDefault(require("./lib/spline"));
const tslib_1 = require("tslib");
const helpers_1 = require("@turf/helpers");
const invariant_1 = require("@turf/invariant");
const spline_1 = tslib_1.__importDefault(require("./lib/spline"));
/**

@@ -39,17 +37,16 @@ * Takes a {@link LineString|line} and returns a curved version

*/
function bezier(line, options) {
if (options === void 0) { options = {}; }
function bezier(line, options = {}) {
// Optional params
var resolution = options.resolution || 10000;
var sharpness = options.sharpness || 0.85;
var coords = [];
var points = invariant_1.getGeom(line).coordinates.map(function (pt) {
const resolution = options.resolution || 10000;
const sharpness = options.sharpness || 0.85;
const coords = [];
const points = invariant_1.getGeom(line).coordinates.map((pt) => {
return { x: pt[0], y: pt[1] };
});
var spline = new spline_1.default({
const spline = new spline_1.default({
duration: resolution,
points: points,
sharpness: sharpness,
points,
sharpness,
});
var pushCoord = function (time) {
const pushCoord = (time) => {
var pos = spline.pos(time);

@@ -56,0 +53,0 @@ if (Math.floor(time / 100) % 2 === 0) {

@@ -29,4 +29,4 @@ "use strict";

*/
var Spline = /** @class */ (function () {
function Spline(options) {
class Spline {
constructor(options) {
this.points = options.points || [];

@@ -41,8 +41,8 @@ this.duration = options.duration || 10000;

// this is to ensure compatibility with the 2d version
for (var i = 0; i < this.length; i++) {
for (let 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.points[i];
var p2 = this.points[i + 1];
for (let i = 0; i < this.length - 1; i++) {
const p1 = this.points[i];
const p2 = this.points[i + 1];
this.centers.push({

@@ -55,6 +55,6 @@ x: (p1.x + p2.x) / 2,

this.controls.push([this.points[0], this.points[0]]);
for (var i = 0; i < this.centers.length - 1; i++) {
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;
for (let i = 0; i < this.centers.length - 1; i++) {
const dx = this.points[i + 1].x - (this.centers[i].x + this.centers[i + 1].x) / 2;
const dy = this.points[i + 1].y - (this.centers[i].y + this.centers[i + 1].y) / 2;
const dz = this.points[i + 1].z - (this.centers[i].y + this.centers[i + 1].z) / 2;
this.controls.push([

@@ -89,9 +89,9 @@ {

*/
Spline.prototype.cacheSteps = function (mindist) {
var steps = [];
var laststep = this.pos(0);
cacheSteps(mindist) {
const steps = [];
let laststep = this.pos(0);
steps.push(0);
for (var t = 0; t < this.duration; t += 10) {
var step = this.pos(t);
var dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) +
for (let t = 0; t < this.duration; t += 10) {
const step = this.pos(t);
const dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) +
(step.y - laststep.y) * (step.y - laststep.y) +

@@ -105,9 +105,9 @@ (step.z - laststep.z) * (step.z - laststep.z));

return steps;
};
}
/**
* returns angle and speed in the given point in the curve
*/
Spline.prototype.vector = function (t) {
var p1 = this.pos(t + 10);
var p2 = this.pos(t - 10);
vector(t) {
const p1 = this.pos(t + 10);
const p2 = this.pos(t - 10);
return {

@@ -119,3 +119,3 @@ angle: (180 * Math.atan2(p1.y - p2.y, p1.x - p2.x)) / 3.14,

};
};
}
/**

@@ -128,4 +128,4 @@ * Gets the position of the point, given time.

*/
Spline.prototype.pos = function (time) {
var t = time - this.delay;
pos(time) {
let t = time - this.delay;
if (t < 0) {

@@ -138,16 +138,15 @@ t = 0;

// t = t-this.delay;
var t2 = t / this.duration;
const t2 = t / this.duration;
if (t2 >= 1) {
return this.points[this.length - 1];
}
var n = Math.floor((this.points.length - 1) * t2);
var t1 = (this.length - 1) * t2 - n;
const n = Math.floor((this.points.length - 1) * t2);
const t1 = (this.length - 1) * t2 - n;
return bezier(t1, this.points[n], this.controls[n][1], this.controls[n + 1][0], this.points[n + 1]);
};
return Spline;
}());
}
}
exports.default = Spline;
function bezier(t, p1, c1, c2, p2) {
var b = B(t);
var pos = {
const b = B(t);
const pos = {
x: p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],

@@ -160,4 +159,4 @@ y: p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],

function B(t) {
var t2 = t * t;
var t3 = t2 * t;
const t2 = t * t;
const t3 = t2 * t;
return [

@@ -164,0 +163,0 @@ t3,

{
"name": "@turf/bezier-spline",
"version": "6.5.0",
"version": "7.0.0-alpha.0",
"description": "turf bezier-spline module",

@@ -61,6 +61,7 @@ "author": "Turf Authors",

"dependencies": {
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0"
"@turf/helpers": "^7.0.0-alpha.0",
"@turf/invariant": "^7.0.0-alpha.0",
"tslib": "^2.3.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
}

@@ -13,12 +13,13 @@ # @turf/bezier-spline

**Parameters**
### Parameters
- `line` **[Feature][4]&lt;[LineString][5]>** input LineString
- `options` **[Object][6]** Optional parameters (optional, default `{}`)
- `options.properties` **[Object][6]** Translate properties to output (optional, default `{}`)
- `options.resolution` **[number][7]** time in milliseconds between points (optional, default `10000`)
- `options.sharpness` **[number][7]** a measure of how curvy the path should be between splines (optional, default `0.85`)
* `line` **[Feature][4]<[LineString][5]>** input LineString
* `options` **[Object][6]** Optional parameters (optional, default `{}`)
**Examples**
* `options.properties` **[Object][6]** Translate properties to output (optional, default `{}`)
* `options.resolution` **[number][7]** time in milliseconds between points (optional, default `10000`)
* `options.sharpness` **[number][7]** a measure of how curvy the path should be between splines (optional, default `0.85`)
### Examples
```javascript

@@ -41,3 +42,3 @@ var line = turf.lineString([

Returns **[Feature][4]&lt;[LineString][5]>** curved line
Returns **[Feature][4]<[LineString][5]>** curved line

@@ -44,0 +45,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.4

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