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

@turf/bezier-spline

Package Overview
Dependencies
Maintainers
4
Versions
30
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.0.0 to 6.0.1

index.d.ts

9

index.js
"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 = require("./lib/spline");
var helpers_1 = require("@turf/helpers");
var spline_1 = __importDefault(require("./lib/spline"));
/**

@@ -46,5 +49,5 @@ * Takes a {@link LineString|line} and returns a curved version

var spline = new spline_1.default({
duration: resolution,
points: points,
sharpness: sharpness,
duration: resolution,
});

@@ -51,0 +54,0 @@ for (var i = 0; i < spline.duration; i += 10) {

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

interface Point {
x: number,
y: number,
z: number
export interface Point {
x: number;
y: number;
z: number;
}

@@ -34,13 +34,13 @@

export default class Spline {
public duration: number
public points: Point[]
public sharpness: number
public centers: Point[]
public controls: [Point, Point][]
public stepLength: number
public length: number
public delay: number
public steps: number[]
public duration: number;
public points: Point[];
public sharpness: number;
public centers: Point[];
public controls: Array<[Point, Point]>;
public stepLength: number;
public length: number;
public delay: number;
public steps: number[];
constructor (options?: any) {
constructor(options?: any) {
this.points = options.points || [];

@@ -56,19 +56,19 @@ this.duration = options.duration || 10000;

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

@@ -90,9 +90,12 @@ x: (1.0 - this.sharpness) * this.points[i + 1].x + this.sharpness * (this.centers[i].x + dx),

*/
cacheSteps (mindist) {
var steps = [];
var laststep = this.pos(0);
public cacheSteps(mindist: number) {
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) + (step.y - laststep.y) * (step.y - laststep.y) + (step.z - laststep.z) * (step.z - laststep.z));
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) +
(step.z - laststep.z) * (step.z - laststep.z));
if (dist > mindist) {

@@ -104,3 +107,3 @@ steps.push(t);

return steps;
};
}

@@ -110,10 +113,13 @@ /**

*/
vector (t) {
var p1 = this.pos(t + 10);
var p2 = this.pos(t - 10);
public vector(t: number) {
const p1 = this.pos(t + 10);
const p2 = this.pos(t - 10);
return {
angle:180 * Math.atan2(p1.y - p2.y, p1.x - p2.x) / 3.14,
speed:Math.sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y) + (p2.z - p1.z) * (p2.z - p1.z))
angle: 180 * Math.atan2(p1.y - p2.y, p1.x - p2.x) / 3.14,
speed: Math.sqrt(
(p2.x - p1.x) * (p2.x - p1.x) +
(p2.y - p1.y) * (p2.y - p1.y) +
(p2.z - p1.z) * (p2.z - p1.z)),
};
};
}

@@ -127,27 +133,29 @@ /**

*/
pos (time) {
function bezier(t, p1, c1, c2, p2) {
var B = function (t) {
var t2 = t * t, t3 = t2 * t;
return [(t3), (3 * t2 * (1 - t)), (3 * t * (1 - t) * (1 - t)), ((1 - t) * (1 - t) * (1 - t))];
};
var b = B(t);
var pos = {
x : p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],
y : p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],
z : p2.z * b[0] + c2.z * b[1] + c1.z * b[2] + p1.z * b[3]
};
return pos;
}
var t = time - this.delay;
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];
public pos(time: number) {
let t = time - this.delay;
if (t < 0) { t = 0; }
if (t > this.duration) { t = this.duration - 1; }
// t = t-this.delay;
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]);
}
}
function bezier(t: number, p1: Point, c1: Point, c2: Point, p2: Point) {
const b = B(t);
const pos = {
x : p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],
y : p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],
z : p2.z * b[0] + c2.z * b[1] + c1.z * b[2] + p1.z * b[3],
};
return pos;
}
function B(t: number) {
const t2 = t * t;
const t3 = t2 * t;
return [(t3), (3 * t2 * (1 - t)), (3 * t * (1 - t) * (1 - t)), ((1 - t) * (1 - t) * (1 - t))];
}
{
"name": "@turf/bezier-spline",
"version": "6.0.0",
"version": "6.0.1",
"description": "turf bezier-spline module",
"main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.ts",
"index.d.ts",
"lib"

@@ -40,3 +41,5 @@ ],

"typescript": "*",
"write-json-file": "*"
"write-json-file": "*",
"tslint": "*",
"@types/tape": "*"
},

@@ -43,0 +46,0 @@ "dependencies": {

@@ -7,14 +7,15 @@ # @turf/bezier-spline

Takes a [line](https://tools.ietf.org/html/rfc7946#section-3.1.4) and returns a curved version
by applying a [Bezier spline](http://en.wikipedia.org/wiki/B%C3%A9zier_spline)
Takes a [line][1] and returns a curved version
by applying a [Bezier spline][2]
algorithm.
The bezier spline implementation is by [Leszek Rybicki](http://leszek.rybicki.cc/).
The bezier spline implementation is by [Leszek Rybicki][3].
**Parameters**
- `line` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** input LineString
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.resolution` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** time in milliseconds between points (optional, default `10000`)
- `options.sharpness` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a measure of how curvy the path should be between splines (optional, default `0.85`)
- `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`)

@@ -40,4 +41,18 @@ **Examples**

Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** curved line
Returns **[Feature][4]&lt;[LineString][5]>** curved line
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[2]: http://en.wikipedia.org/wiki/B%C3%A9zier_spline
[3]: http://leszek.rybicki.cc/
[4]: https://tools.ietf.org/html/rfc7946#section-3.2
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
<!-- This file is automatically generated. Please don't edit it directly:

@@ -44,0 +59,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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