p5bezier 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,14 +10,14 @@
10
10
 
11
11
  <!-- [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/7Z2pRG-TB) -->
12
12
 
13
- [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/mVXzWEJbT)
13
+ [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/mVXzWEJbT) | [**Play with examples**](https://p5bezier.netlify.app)
14
14
 
15
- While **p5.bezier** is designed to integrate with p5.js, it operates independently as well. It's necessary to initialize the library and specify the target canvas by invoking `initBezier(canvas)` at the start of your code.
16
-
17
- To draw a Bézier curve on canvas, you can simply use `newBezier()`:
15
+ While **p5.bezier** is designed to integrate with p5.js, it operates independently as well. To draw a Bézier curve on canvas, you can simply use `p5bezier.draw()`:
18
16
 
19
17
  ```js
20
- newBezier([
18
+ let p5bezier = initBezier(canvas)
19
+
20
+ p5bezier.draw([
21
21
  [85, 20],
22
22
  [10, 10],
23
23
  [90, 90],
@@ -44,11 +44,7 @@ Alternatively, you can use the library through a content delivery network (CDN):
44
44
  <script src="https://cdn.jsdelivr.net/npm/p5bezier@latest"></script>
45
45
  ```
46
46
 
47
- Once included, the entire library is encapsulated within the `p5bezier` object. To call the functions provided by the library, prepend `p5bezier` to the function name:
48
-
49
- ```js
50
- p5bezier.initBezier(c)
51
- ```
47
+ Once included, you will have access to the `initBezier` function.
52
48
 
53
49
  ### NPM
54
50
 
@@ -58,10 +54,10 @@ You can also install the library using the package manager NPM (recommended):
58
54
  npm install p5bezier
59
55
  ```
60
56
 
61
- Then, import the modules into your project:
57
+ Then, import the initialization function into your project:
62
58
 
63
59
  ```js
64
- import { initBezier, newBezier, newBezierObject } from 'p5bezier'
60
+ import initBezier from 'p5bezier'
65
61
  ```
66
62
 
67
63
  ## Init for Bézier
@@ -71,16 +67,16 @@ You must initialize the Bézier drawing system with the canvas you are drawing o
71
67
  ```diff
72
68
  function setup() {
73
69
  let c = createCanvas(100, 100)
74
- + initBezier(c)
70
+ + let p5bezier = initBezier(c)
75
71
  }
76
72
  ```
77
73
 
78
74
  ## Draw a Bézier Curve
79
75
 
80
- The simplest way to use the library is to call `newBezier()` in your `draw()` function. You can adjust the curve's style using `fill()` or `strokeWeight()` just like other shapes.
76
+ The simplest way to use the library is to call `p5bezier.draw()` in your `draw()` function. You can adjust the curve's style using `fill()` or `strokeWeight()` just like other shapes.
81
77
 
82
78
  ```
83
- newBezier(pointsArray [, closeType] [, accuracy]);
79
+ p5bezier.draw(pointsArray [, closeType] [, smoothness]);
84
80
  ```
85
81
 
86
82
  **pointsArray**
@@ -91,21 +87,21 @@ This is an array of [x, y] pairs, each representing a control point for the curv
91
87
 
92
88
  This is a string, either `"OPEN"` or `"CLOSE"`. Use `"CLOSE"` to automatically close the curve. The default is `"OPEN"`.
93
89
 
94
- **accuracy** (Optional)
90
+ **smoothness** (Optional)
95
91
 
96
- This is an integer between `0` and `10`, with a default value of `7`. This value determines the accuracy of the Bézier curve. Higher values mean more vertices are used, leading to a more accurate curve, but at the cost of additional computation.
92
+ This is an integer between `1` and `5`, with a default value of `3`. This value determines the smoothness of the Bézier curve. Higher values mean more vertices are used, leading to a more accurate and smoother curve, but at the cost of additional computation.
97
93
 
98
94
  ## Create a Bézier Object
99
95
 
100
- For advanced operations, such as computing the shortest distance from a point to the curve, use the `newBezierObj()` function. This method can also potentially optimize computation resources if placed within the `setup()` function, as vertices are calculated only once and can then be reused.
96
+ For advanced operations, such as computing the shortest distance from a point to the curve, use the `p5bezier.new()` function. This method can also potentially optimize computation resources if placed within the `setup()` function, as vertices are calculated only once and can then be reused.
101
97
 
102
- The usage of `newBezierObj()` is similar to `newBezier()`, but it returns a _Bézier Curve Object_ that can be stored in a variable:
98
+ The usage of `p5bezier.new()` is similar to `p5bezier.draw()`, but it returns a _Bézier Curve Object_ that can be stored in a variable:
103
99
 
104
100
  ```
105
- let bezierObject = newBezierObj(pointsArray [, closeType] [, accuracy]);
101
+ const bezierObject = p5bezier.new(pointsArray [, closeType] [, smoothness]);
106
102
  ```
107
103
 
108
- The call of `newBezierObj` will not draw the curve on canvas automatically. To draw the curve, use `.draw()` as one of many functions listed below:
104
+ The call of `p5bezier.new` will not draw the curve on canvas automatically. To draw the curve, use `.draw()` as one of many functions listed below:
109
105
 
110
106
  - `.draw([dash])`
111
107
 
@@ -140,39 +136,21 @@ The call of `newBezierObj` will not draw the curve on canvas automatically. To d
140
136
 
141
137
  ## Examples
142
138
 
143
- To execute the examples locally, download the repository to your local machine. Then, navigate to the `examples` directory using your terminal. Execute the following command:
144
-
145
- ```
146
- npm install
147
- node server.js name_of_example
148
- ```
149
-
150
- For instance, to run the _basic_ example, simply enter `node server.js basic`. Then, open your web browser and navigate to `localhost:8000`.
139
+ ![cover](img/example.png)
151
140
 
152
- Currently available examples:
153
-
154
- - **basic** draws a simple Bézier curve with 5 control points across the canvas.
155
- - **basic_object** create a simple Bézier object with 5 control points across the canvas.
156
- - **control_points** draws a curve and its control points, which can be dragged around.
157
- - **accuracy** showcases curves drawn with varying levels of accuracy.
158
- - **shortest_point** draws the shortest line from the mouse pointer to the curve.
159
- - **animation** draws animated Bézier curves.
160
-
161
- More complex examples to be updated.
141
+ Check out the examples page and their [source code](https://github.com/peilingjiang/p5.bezier/tree/main/examples/sketch.js).
162
142
 
163
143
  ### Projects and Demos
164
144
 
165
- - [**Hair**](https://no-loss.netlify.app/), a visualization. See the source code here: https://github.com/peilingjiang/hair.
145
+ - [**Hair**](https://no-loss.netlify.app/), a visualization. See the source code at https://github.com/peilingjiang/hair.
166
146
  - _p5.bezier Example - Basic_ on [CodePen](https://codepen.io/peilingjiang/pen/ZEOLVPx).
167
147
  - _p5.bezier Example - Animation_ on [CodePen](https://codepen.io/peilingjiang/pen/eYMRJax).
168
148
 
169
- Share your ideas and projects using the library!
170
-
171
149
  ## TODOs
172
150
 
173
- 1. More examples.
174
- 2. `offset()`, `intersection()`, and `curvature()`... functions for Bézier object.
175
- 3. Draw B-Spline curves.
151
+ 1. More examples
152
+ 2. `offset()`, `intersection()`, and `curvature()`... functions for Bézier object
153
+ 3. Draw B-Spline curves
176
154
 
177
155
  ## References
178
156
 
@@ -0,0 +1,6 @@
1
+ export declare const MAX_DEGREE = 160;
2
+ export type Smoothness = 1 | 2 | 3 | 4 | 5;
3
+ export declare const _smoothness: {
4
+ [A in Smoothness]: number;
5
+ };
6
+ export declare function _binomialCoefficient(n: number, i: number): number;
@@ -1,13 +1,12 @@
1
- type Accuracy = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
2
- type CloseType = 'OPEN' | 'CLOSE';
3
- type Dimension = 2 | 3;
4
- type Point = [number, number] | [number, number, number];
5
- type PointList = Point[];
6
- type Vertex = [number, number] | [number, number, number];
7
- type VertexList = Vertex[];
8
- declare function initBezier(canvas: any): void;
9
- declare function newBezier(pointList: PointList, closeType?: CloseType, accuracy?: Accuracy): void;
10
- declare function newBezierObj(pointList: PointList, closeType?: CloseType, accuracy?: Accuracy): BezierCurve;
1
+ import { type Smoothness } from './coefficients';
2
+ import { type BezierCanvas, type CloseType, type Dimension, type PointList, type Vertex, type VertexList } from './utils';
3
+ declare class P5Bezier {
4
+ private b;
5
+ constructor(canvas: any);
6
+ draw(pointList: PointList, closeType?: CloseType, smoothness?: Smoothness): PointList;
7
+ new(pointList: PointList, closeType?: CloseType, smoothness?: Smoothness): BezierCurve;
8
+ }
9
+ declare function initBezier(canvas: any): P5Bezier;
11
10
  declare class BezierCurve {
12
11
  controlPoints: PointList;
13
12
  closeType: CloseType;
@@ -16,13 +15,16 @@ declare class BezierCurve {
16
15
  private vertexList;
17
16
  private p;
18
17
  private n;
19
- constructor(points: PointList, closeType: CloseType, increment: number, dimension: Dimension, vertexList?: VertexList | null);
18
+ private b;
19
+ constructor(points: PointList, closeType: CloseType, increment: number, bezierCanvas: BezierCanvas, vertexList?: VertexList | null);
20
20
  private _buildVertexList;
21
21
  private _addVertex;
22
22
  private _distVertex;
23
23
  draw(dash?: [number, number]): void;
24
+ private _solidCurve;
25
+ private _dashedCurve;
24
26
  update(newControlPointList: PointList): void;
25
27
  move(x: number, y: number, z?: number | null, toDraw?: boolean, dash?: [number, number]): BezierCurve;
26
28
  shortest(pX: number, pY: number, pZ?: number): Vertex;
27
29
  }
28
- export { initBezier, newBezier, newBezierObj };
30
+ export default initBezier;
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see p5.bezier.min.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.p5bezier=e():t.p5bezier=e()}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{initBezier:()=>L,newBezier:()=>P,newBezierObj:()=>S});var i=function(t,e,i){if(i||2===arguments.length)for(var n,o=0,r=e.length;o<r;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))};window.console.log("[p5.bezier]");var n,o,r,s,h,p,l,a,d={0:.2,1:.1,2:.05,3:.04,4:.02,5:.01,6:.008,7:.002,8:.001,9:5e-4,10:1e-4},c=[1],f={};function u(t,e){return"WebGLRenderingContext"===t.constructor.name||e?3:2}function v(t){for(var e=c.length;e<=t;e++)c[e]=e*c[e-1]}function y(t){return c[t]}function x(t,e){return 0===e||e===t?1:(f[t]||(f[t]={}),void 0!==f[t][e]||(f[t][e]=function(t,e){return y(t)/(y(e)*y(t-e))}(t,e)),f[t][e])}function b(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 4===t.length?Math.hypot(t[0]-t[2],t[1]-t[3]):6===t.length?Math.hypot(t[0]-t[3],t[1]-t[4],t[2]-t[5]):0}function g(){n._doFill&&o.fill(),n._doStroke&&o.stroke()}function m(t){return t.map((function(t){return Array.from(t)}))}function w(t){var e=t[0],i=t[t.length-1],n=t[1],o=t[t.length-2];return[[2*i[0]-o[0],2*i[1]-o[1]],[2*e[0]-n[0],2*e[1]-n[1]],e]}function L(t){if(o=(n=t).drawingContext,"undefined"!=typeof p5&&t instanceof p5.Graphics)s=!0,r=u(o,!1);else{if(!("undefined"!=typeof p5&&t instanceof p5.Renderer||t.drawingContext))throw new Error("[p5.bezier] Canvas is not supported.");s=!1,"undefined"!=typeof p5&&("undefined"==typeof p5||t instanceof p5.Renderer)||window.console.warn("[p5.bezier] Support beyond p5.js is not tested."),r=u(o,t.isP3D)}!function(t,e,i){t?(h=e.beginShape,p=e.vertex,l=e.vertex,a=e.endShape):(h=i.beginPath.bind(i),p=i.moveTo.bind(i),l=i.lineTo.bind(i),a=i.closePath.bind(i))}(s,n,o)}function P(t,e,i){if(void 0===e&&(e="OPEN"),void 0===i&&(i=7),t=m(t),"CLOSE"===e){var n=w(t);t.push.apply(t,n)}var o=d[i],c=t.length-1;if(v(c),h(),p.apply(void 0,t[0]),2===r){var f=void 0,u=void 0,y=void 0;for(y=0;y<=1;y+=o){f=u=0;for(var b=0;b<=c;b++){f+=(P=x(c,b)*Math.pow(1-y,c-b)*Math.pow(y,b))*t[b][0],u+=P*t[b][1]}l(f,u)}}else if(3===r){y=void 0;for(y=0;y<=1;y+=o){var L=[0,0,0];for(b=0;b<=c;b++)for(var P=x(c,b)*Math.pow(1-y,c-b)*Math.pow(y,b),S=0;S<3;S++)L[S]+=P*t[b][S];l.apply(void 0,L)}}l.apply(void 0,t.slice(-1)[0]),s?a(e):"CLOSE"===e&&a(),g()}function S(t,e,i){void 0===e&&(e="OPEN"),void 0===i&&(i=7);var n=d[i];return new O(t,e,n,r)}v(10);var O=function(){function t(t,e,n,o,r){var s;void 0===r&&(r=null),this.controlPoints=m(t),"CLOSE"===e?((s=this.controlPoints).push.apply(s,w(this.controlPoints)),this.closeType="CLOSE"):this.closeType="OPEN",this.dimension=o,this.increment=n,this.vertexList=[],this.p=this.controlPoints.length,this.n=this.p-1,v(this.n),null===r?this._buildVertexList():this.vertexList=i([],r,!0)}return t.prototype._buildVertexList=function(){if(this.vertexList=[],2===this.dimension)for(var t=0;t<=1;t+=this.increment){for(var e=0,i=0,n=0;n<=this.n;n++){e+=(r=x(this.n,n)*Math.pow(1-t,this.n-n)*Math.pow(t,n))*this.controlPoints[n][0],i+=r*this.controlPoints[n][1]}this.vertexList.push([e,i])}else if(3===this.dimension)for(t=0;t<=1;t+=this.increment){var o=[0,0,0];for(n=0;n<=this.n;n++)for(var r=x(this.n,n)*Math.pow(1-t,this.n-n)*Math.pow(t,n),s=0;s<3;s++)o[s]+=r*this.controlPoints[n][s];this.vertexList.push(o)}return this._addVertex(this.controlPoints[this.controlPoints.length-1]),this.dimension=this.vertexList[0].length,this.vertexList},t.prototype._addVertex=function(t){l.apply(void 0,t)},t.prototype._distVertex=function(t,e){return 3===this.dimension&&3===t.length&&3===e.length?b(t[0],t[1],t[2],e[0],e[1],e[2]):2===this.dimension?b(t[0],t[1],e[0],e[1]):0},t.prototype.draw=function(t){var e,i,n,r=this;if(t){this.increment>.008&&(this.increment=.008);var d=Math.abs(t[0]),c=Math.abs(t[1]),f=!0,u=this.vertexList[0],v=1,y=this.vertexList[v],x=u,b=0,m=f?d:c;for(o.save(),o.fillStyle="rgba(0, 0, 0, 0)",h(),p.apply(void 0,u);v<this.vertexList.length;){for(y=this.vertexList[v],b=this._distVertex(u,y);b>=m;)i=y,n=m/b,x=2===(e=x).length&&2===i.length?[e[0]+(i[0]-e[0])*n,e[1]+(i[1]-e[1])*n]:3===e.length&&3===i.length?[e[0]+(i[0]-e[0])*n,e[1]+(i[1]-e[1])*n,e[2]+(i[2]-e[2])*n]:i,f?l.apply(void 0,x):p.apply(void 0,x),b-=m,m=(f=!f)?d:c;f?l.apply(void 0,y):p.apply(void 0,y),m-=this._distVertex(x,y),x=u=y,v++}g(),o.restore()}else h(),this.vertexList.map((function(t){return r._addVertex(t)})),"CLOSE"===this.closeType&&o.closePath(),s?a(this.closeType):"CLOSE"===this.closeType&&a(),g()},t.prototype.update=function(t){if(t.length!==this.controlPoints.length)throw new Error("[p5.bezier] The number of control points changed.");this.controlPoints.every((function(e,i){return e===t[i]}))||(this.controlPoints=t,this._buildVertexList())},t.prototype.move=function(e,i,n,o,r){if(void 0===n&&(n=null),void 0===o&&(o=!0),null===n&&3===this.dimension)throw new Error("[p5.bezier] X, Y, and Z are needed to move a 3D curve.");var s=[e,i];null!==n&&s.push(n);var h=this.vertexList.map((function(t){return t.slice()})),p=new t(this.controlPoints,this.closeType,this.increment,this.dimension,h);return p.vertexList=p.vertexList.map((function(t){return t.map((function(t,e){return t+s[e]}))})),o&&p.draw(r),p},t.prototype.shortest=function(t,e,n){var o=this;void 0===n&&(n=0);var r=[0,0,0],s=1/0;return this.vertexList.map((function(h){var p=o._distVertex(h,[t,e,n]);s>p&&(s=p,r=i([],h,!0))})),r},t}();return e})()));
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.initBezier=e():t.initBezier=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>m});var n={1:.1,2:.02,3:.001,4:5e-4,5:2e-4},i=[1],o={};function r(t){return i[t]}function s(t,e){return 0===e||e===t?1:o[t][e]}!function(t){for(var e=i.length;e<=t;e++)i[e]=e*i[e-1]}(161),function(t){for(var e=2;e<=t;e++){o[e]={};for(var n=1;n<e;n++)o[e][n]=r(e)/(r(n)*r(e-n))}}(161);var h=function(t,e,n){if(n||2===arguments.length)for(var i,o=0,r=e.length;o<r;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))};function a(t,e){return"WebGLRenderingContext"===t.constructor.name||e?3:2}function c(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t.length;if(4===n){var i=t[0]-t[2],o=t[1]-t[3];return Math.sqrt(i*i+o*o)}if(6===n){i=t[0]-t[3],o=t[1]-t[4];var r=t[2]-t[5];return Math.sqrt(i*i+o*o+r*r)}return 0}function u(t){t.canvas._doFill&&t.ctx.fill(),t.canvas._doStroke&&t.ctx.stroke()}var l=function(){function t(t){this.m=Math.pow(2,31)-1,this.a=1103515245,this.c=12345,this.state=t}return t.prototype.r=function(){return this.state=(this.a*this.state+this.c)%this.m,this.state/this.m},t.prototype.next=function(t,e){return Math.floor(this.r()*(e-t+1))+t},t}();function p(t,e){void 0===e&&(e=!1);var n=160-(e?3:0);if(t.length<=n)return f(t);var i=t.length-n,o=new l(1234),r=new Set;return h([],new Array(i),!0).map((function(t,e){for(var i=o.next(5+e,n-5+e);r.has(i);)i=o.next(5+e,n-5+e);r.add(i)})),f(t.filter((function(t,e){return!r.has(e)})))}function f(t){return t.map((function(t){return t.slice()}))}function v(t){var e=t.length;if(0===e)return[];var n=t[0],i=t[e-1];if(1===e)return f([n]);var o=t[1],r=t[e-2];return f([[2*i[0]-r[0],2*i[1]-r[1]],[2*n[0]-o[0],2*n[1]-o[1]],n])}var d=function(t,e,n){if(n||2===arguments.length)for(var i,o=0,r=e.length;o<r;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))};function b(t,e,n,i){for(var o=new Array(i).fill(0),r=1-n,h=0;h<=e;h++)for(var a=s(e,h)*Math.pow(r,e-h)*Math.pow(n,h),c=0;c<i;c++)o[c]+=a*t[h][c];return o}window.console.log("[p5.bezier] ".concat("0.7.0"));var x=function(){function t(t){if(this.b={canvas:null,ctx:null,dimension:2,useP5:!0,beginPath:function(){},moveTo:function(){},lineTo:function(){},closePath:function(){}},this.b.canvas=t,this.b.ctx=this.b.canvas.drawingContext,"undefined"!=typeof p5&&t instanceof p5.Graphics)this.b.useP5=!0,this.b.dimension=a(this.b.ctx,!1);else{if(!("undefined"!=typeof p5&&t instanceof p5.Renderer||t.drawingContext))throw new Error("[p5.bezier] Canvas is not supported");this.b.useP5=!1,"undefined"!=typeof p5&&("undefined"==typeof p5||t instanceof p5.Renderer)||window.console.warn("[p5.bezier] Support beyond p5.js is not tested"),this.b.dimension=a(this.b.ctx,t.isP3D)}var e;(e=this.b).useP5?(e.beginPath=e.canvas.beginShape,e.moveTo=e.canvas.vertex,e.lineTo=e.canvas.vertex,e.closePath=e.canvas.endShape):e.ctx instanceof WebGLRenderingContext?(e.beginPath=function(){},e.moveTo=function(t,n,i){return void 0===i&&(i=0),e.ctx.vertexAttrib3f(0,t,n,i)},e.lineTo=function(t,n,i){return void 0===i&&(i=0),e.ctx.vertexAttrib3f(0,t,n,i)},e.closePath=function(){}):(e.beginPath=e.ctx.beginPath.bind(e.ctx),e.moveTo=e.ctx.moveTo.bind(e.ctx),e.lineTo=e.ctx.lineTo.bind(e.ctx),e.closePath=e.ctx.closePath.bind(e.ctx))}return t.prototype.draw=function(t,e,i){var o,r;void 0===e&&(e="OPEN"),void 0===i&&(i=3);var s="CLOSE"===e?d(d([],p(t,!0),!0),v(t),!0):p(t);return this.b.beginPath(),(o=this.b).moveTo.apply(o,s[0]),function(t,e,i){for(var o=e.length-1,r=n[i],s=0;s<=1;s+=r){var h=b(e,o,s,t.dimension);t.lineTo.apply(t,h)}}(this.b,s,i),(r=this.b).lineTo.apply(r,s[s.length-1]),this.b.useP5?this.b.closePath(e):"CLOSE"===e&&this.b.closePath(),u(this.b),s},t.prototype.new=function(t,e,i){return void 0===e&&(e="OPEN"),void 0===i&&(i=3),new y(t,e,n[i],this.b)},t}();var y=function(){function t(t,e,n,i,o){var r;void 0===o&&(o=null),this.controlPoints=p(t,"CLOSE"===e),"CLOSE"===e?((r=this.controlPoints).push.apply(r,v(this.controlPoints)),this.closeType="CLOSE"):this.closeType="OPEN",this.dimension=i.dimension,this.increment=n,this.vertexList=[],this.p=this.controlPoints.length,this.n=this.p-1,this.b=i,null===o?this._buildVertexList():this.vertexList=d([],o,!0)}return t.prototype._buildVertexList=function(){this.vertexList=[];for(var t=0;t<=1;t+=this.increment){var e=b(this.controlPoints,this.n,t,this.dimension);this.vertexList.push(e)}return this._addVertex(this.controlPoints[this.controlPoints.length-1]),this.dimension=this.vertexList[0].length,this.vertexList},t.prototype._addVertex=function(t){var e;(e=this.b).lineTo.apply(e,t)},t.prototype._distVertex=function(t,e){return 3===this.dimension&&3===t.length&&3===e.length?c(t[0],t[1],t[2],e[0],e[1],e[2]):2===this.dimension?c(t[0],t[1],e[0],e[1]):0},t.prototype.draw=function(t){t?this._dashedCurve(t):this._solidCurve()},t.prototype._solidCurve=function(){var t=this;this.b.beginPath(),this.vertexList.map((function(e){return t._addVertex(e)})),"CLOSE"===this.closeType&&this.b.closePath(),this.b.useP5?this.b.closePath(this.closeType):"CLOSE"===this.closeType&&this.b.closePath(),u(this.b)},t.prototype._dashedCurve=function(t){var e,n,i,o,r;this.increment>.001&&(this.increment=.001,window.console.warn("[p5.bezier] Smoothness set to 3 for a dashed curve"));var s,h,a,c,l,p=t.map(Math.abs),f=p[0],v=p[1],d=!0,b=this.vertexList[0],x=1,y=b,m=0,P=f;for(this.b.ctx.save(),this.b.ctx.fillStyle="rgba(0, 0, 0, 0)",this.b.beginPath(),(e=this.b).moveTo.apply(e,b);x<this.vertexList.length;){var g=this.vertexList[x];for(m=this._distVertex(b,g);m>=P;)h=g,a=P/m,c=void 0,l=void 0,c=(s=y).length,l=h.length,y=2===c&&2===l?[s[0]+(h[0]-s[0])*a,s[1]+(h[1]-s[1])*a]:3===c&&3===l?[s[0]+(h[0]-s[0])*a,s[1]+(h[1]-s[1])*a,s[2]+(h[2]-s[2])*a]:h,d?(n=this.b).lineTo.apply(n,y):(i=this.b).moveTo.apply(i,y),m-=P,P=(d=!d)?f:v;d?(o=this.b).lineTo.apply(o,g):(r=this.b).moveTo.apply(r,g),P-=this._distVertex(y,g),y=b=g,x++}u(this.b),this.b.ctx.restore()},t.prototype.update=function(t){if(t.length!==this.controlPoints.length)throw new Error("[p5.bezier] The number of control points changed");this.controlPoints.every((function(e,n){return e===t[n]}))||(this.controlPoints=t,this._buildVertexList())},t.prototype.move=function(e,n,i,o,r){if(void 0===i&&(i=null),void 0===o&&(o=!0),null===i&&3===this.dimension)throw new Error("[p5.bezier] X, Y, and Z are needed to move a 3D curve");var s=[e,n];null!==i&&s.push(i);var h=this.vertexList.map((function(t){return t.slice()})),a=new t(this.controlPoints,this.closeType,this.increment,this.b,h);return a.vertexList=a.vertexList.map((function(t){return t.map((function(t,e){return t+s[e]}))})),o&&a.draw(r),a},t.prototype.shortest=function(t,e,n){var i=this;void 0===n&&(n=0);var o=[0,0,0],r=Number.POSITIVE_INFINITY;return this.vertexList.map((function(s){var h=i._distVertex(s,[t,e,n]);r>h&&(r=h,o=d([],s,!0))})),o},t}();const m=function(t){return new x(t)};return e=e.default})()));
3
3
  //# sourceMappingURL=p5.bezier.min.js.map
@@ -1,10 +1,10 @@
1
1
  /*!
2
2
  *
3
3
  * @license
4
- * p5bezier Version 0.6.0
4
+ * p5bezier Version 0.7.0
5
5
  * https://github.com/peilingjiang/p5.bezier
6
6
  *
7
- * Copyright 2018-2023 Peiling Jiang
7
+ * Copyright 2018-2024 Peiling Jiang
8
8
  * Available under MIT license
9
9
  *
10
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"p5.bezier.min.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,O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IAAM0E,EAAoBrH,EAAI,MAIrFxB,KAAKiH,cAAgB4B,EACrB7I,KAAKmH,mBAEb,EACAP,EAAYjG,UAAUoI,KAAO,SAAU5C,EAAGC,EAAG4C,EAAGC,EAAQtB,GAGpD,QAFU,IAANqB,IAAgBA,EAAI,WACT,IAAXC,IAAqBA,GAAS,GACxB,OAAND,GAAiC,IAAnBhJ,KAAK8G,UACnB,MAAM,IAAI9B,MAAM,0DAGhB,IAAIkE,EAAW,CAAC/C,EAAGC,GACT,OAAN4C,GACAE,EAASlD,KAAKgD,GAClB,IAAIG,EAAYnJ,KAAK+G,WAAW7C,KAAI,SAAUC,GAAK,OAAOA,EAAExC,OAAS,IACjEyH,EAAc,IAAIxC,EAAY5G,KAAKiH,cAAejH,KAAK6F,UAAW7F,KAAK2G,UAAW3G,KAAK8G,UAAWqC,GAItG,OAHAC,EAAYrC,WAAaqC,EAAYrC,WAAW7C,KAAI,SAAUC,GAAK,OAAOA,EAAED,KAAI,SAAUmF,EAAK7H,GAAK,OAAO6H,EAAMH,EAAS1H,EAAI,GAAI,IAC9HyH,GACAG,EAAY1B,KAAKC,GACdyB,CAEf,EACAxC,EAAYjG,UAAU2I,SAAW,SAAUC,EAAIC,EAAIC,GAC/C,IAAI3B,EAAQ9H,UACD,IAAPyJ,IAAiBA,EAAK,GAC1B,IAAIC,EAAY,CAAC,EAAG,EAAG,GACnBC,EAAOC,IAQX,OAPA5J,KAAK+G,WAAW7C,KAAI,SAAUC,GAC1B,IAAI0F,EAAS/B,EAAMP,YAAYpD,EAAG,CAACoF,EAAIC,EAAIC,IACvCE,EAAOE,IACPF,EAAOE,EACPH,EAAYzI,EAAc,GAAIkD,GAAG,GAEzC,IACOuF,CACX,EACO9C,CACX,CA3KgC,aLvLhC","sources":["webpack://p5bezier/webpack/universalModuleDefinition","webpack://p5bezier/webpack/bootstrap","webpack://p5bezier/webpack/runtime/define property getters","webpack://p5bezier/webpack/runtime/hasOwnProperty shorthand","webpack://p5bezier/webpack/runtime/make namespace object","webpack://p5bezier/./src/p5.bezier.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"p5bezier\"] = factory();\n\telse\n\t\troot[\"p5bezier\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\np5.bezier library by Peiling Jiang\n2020\n\nupdated Dec 2023\n*/\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nwindow.console.log('[p5.bezier]');\n// accuracy 0 - 10, default 7\nvar _p5bezierAccuracyListAll = {\n 0: 0.2,\n 1: 0.1,\n 2: 0.05,\n 3: 0.04,\n 4: 0.02,\n 5: 0.01,\n 6: 0.008,\n 7: 0.002,\n 8: 0.001,\n 9: 0.0005,\n 10: 0.0001,\n};\nvar _canvas, _ctx, _dimension, _useP5, _beginPath, _moveTo, _lineTo, _closePath;\nvar ENSURED_FACTORIAL_COUNT = 10;\nvar _calculatedFactorials = [1];\nvar _calculatedBinomialCoefficients = {};\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n// helpers\nfunction _determineDimension(context, isP3D) {\n return context.constructor.name === 'WebGLRenderingContext' || isP3D ? 3 : 2;\n}\nfunction _setCanvasFunctions(useP5, canvas, context) {\n if (useP5) {\n _beginPath = canvas.beginShape;\n _moveTo = canvas.vertex;\n _lineTo = canvas.vertex;\n _closePath = canvas.endShape;\n }\n else {\n _beginPath = context.beginPath.bind(context);\n _moveTo = context.moveTo.bind(context);\n _lineTo = context.lineTo.bind(context);\n _closePath = context.closePath.bind(context);\n }\n}\nfunction _ensureFactorials(n) {\n for (var i = _calculatedFactorials.length; i <= n; i++)\n _calculatedFactorials[i] = i * _calculatedFactorials[i - 1];\n}\n_ensureFactorials(ENSURED_FACTORIAL_COUNT);\nfunction _helper_factorial(i) {\n return _calculatedFactorials[i];\n}\nfunction _helper_binomialCoefficient(n, i) {\n return (_helper_factorial(n) / (_helper_factorial(i) * _helper_factorial(n - i)));\n}\nfunction _binomialCoefficient(n, i) {\n if (i === 0 || i === n)\n return 1;\n // _ensureFactorials(n)\n if (!_calculatedBinomialCoefficients[n])\n _calculatedBinomialCoefficients[n] = {};\n if (_calculatedBinomialCoefficients[n][i] !== undefined)\n return _calculatedBinomialCoefficients[n][i];\n _calculatedBinomialCoefficients[n][i] = _helper_binomialCoefficient(n, i);\n return _calculatedBinomialCoefficients[n][i];\n}\nfunction _helper_dist() {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n if (args.length === 4)\n return Math.hypot(args[0] - args[2], args[1] - args[3]);\n else if (args.length === 6)\n return Math.hypot(args[0] - args[3], args[1] - args[4], args[2] - args[5]);\n return 0;\n}\nfunction _helper_style() {\n if (_canvas._doFill)\n _ctx.fill();\n if (_canvas._doStroke)\n _ctx.stroke();\n}\nfunction _deepCopyPoints(arr) {\n return arr.map(function (v) { return Array.from(v); });\n}\nfunction _findCloseCurveExtraPoints(pointList) {\n var first = pointList[0];\n var last = pointList[pointList.length - 1];\n var second = pointList[1];\n var secondLast = pointList[pointList.length - 2];\n var point1 = [\n 2 * last[0] - secondLast[0],\n 2 * last[1] - secondLast[1],\n ];\n var point2 = [2 * first[0] - second[0], 2 * first[1] - second[1]];\n return [point1, point2, first];\n}\nfunction _interpolateVertex(v1, v2, t) {\n if (v1.length === 2 && v2.length === 2)\n return [v1[0] + (v2[0] - v1[0]) * t, v1[1] + (v2[1] - v1[1]) * t];\n if (v1.length === 3 && v2.length === 3)\n return [\n v1[0] + (v2[0] - v1[0]) * t,\n v1[1] + (v2[1] - v1[1]) * t,\n v1[2] + (v2[2] - v1[2]) * t,\n ];\n return v2;\n}\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\nfunction initBezier(canvas) {\n _canvas = canvas;\n _ctx = _canvas.drawingContext;\n if (typeof p5 !== 'undefined' && canvas instanceof p5.Graphics) {\n _useP5 = true;\n _dimension = _determineDimension(_ctx, false);\n }\n else if ((typeof p5 !== 'undefined' && canvas instanceof p5.Renderer) ||\n canvas.drawingContext) {\n _useP5 = false;\n if (typeof p5 === 'undefined' ||\n (typeof p5 !== 'undefined' && !(canvas instanceof p5.Renderer)))\n window.console.warn('[p5.bezier] Support beyond p5.js is not tested.');\n _dimension = _determineDimension(_ctx, canvas.isP3D);\n }\n else\n throw new Error('[p5.bezier] Canvas is not supported.');\n _setCanvasFunctions(_useP5, _canvas, _ctx);\n}\nfunction newBezier(pointList, closeType, accuracy) {\n if (closeType === void 0) { closeType = 'OPEN'; }\n if (accuracy === void 0) { accuracy = 7; }\n pointList = _deepCopyPoints(pointList);\n if (closeType === 'CLOSE') {\n var closeCurveExtraPoints = _findCloseCurveExtraPoints(pointList);\n pointList.push.apply(pointList, closeCurveExtraPoints);\n }\n var tIncrement = _p5bezierAccuracyListAll[accuracy];\n var p = pointList.length; // pointList has p points for (p - 1) degree curves\n var n = p - 1;\n _ensureFactorials(n);\n _beginPath();\n _moveTo.apply(void 0, pointList[0]);\n if (_dimension === 2) {\n var x = void 0, y = void 0, t = void 0;\n for (t = 0; t <= 1; t += tIncrement) {\n x = y = 0;\n for (var i = 0; i <= n; i++) {\n var coefficient = _binomialCoefficient(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);\n x += coefficient * pointList[i][0];\n y += coefficient * pointList[i][1];\n }\n _lineTo(x, y);\n }\n }\n else if (_dimension === 3) {\n var t = void 0;\n for (t = 0; t <= 1; t += tIncrement) {\n var xyz = [0, 0, 0];\n for (var i = 0; i <= n; i++) {\n var coefficient = _binomialCoefficient(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);\n for (var d = 0; d < 3; d++)\n xyz[d] += coefficient * pointList[i][d];\n }\n _lineTo.apply(void 0, xyz);\n }\n }\n _lineTo.apply(void 0, pointList.slice(-1)[0]);\n if (_useP5)\n _closePath(closeType);\n else if (closeType === 'CLOSE')\n _closePath();\n _helper_style();\n}\nfunction newBezierObj(pointList, closeType, accuracy) {\n if (closeType === void 0) { closeType = 'OPEN'; }\n if (accuracy === void 0) { accuracy = 7; }\n var increment = _p5bezierAccuracyListAll[accuracy];\n return new BezierCurve(pointList, closeType, increment, _dimension);\n}\nvar BezierCurve = /** @class */ (function () {\n // take pointList, closeType, tIncrement, bezierDimension into constructor\n function BezierCurve(points, closeType, increment, dimension, vertexList) {\n var _a;\n if (vertexList === void 0) { vertexList = null; }\n this.controlPoints = _deepCopyPoints(points);\n if (closeType === 'CLOSE') {\n (_a = this.controlPoints).push.apply(_a, _findCloseCurveExtraPoints(this.controlPoints));\n this.closeType = 'CLOSE';\n }\n else\n this.closeType = 'OPEN';\n this.dimension = dimension;\n this.increment = increment;\n this.vertexList = [];\n this.p = this.controlPoints.length; // has p points for (p - 1) degree curves\n this.n = this.p - 1; // degree\n // ensure enough factorials are calculated up to this.n\n _ensureFactorials(this.n);\n if (vertexList === null)\n this._buildVertexList();\n else\n this.vertexList = __spreadArray([], vertexList, true);\n }\n BezierCurve.prototype._buildVertexList = function () {\n this.vertexList = [];\n if (this.dimension === 2) {\n for (var t = 0; t <= 1; t += this.increment) {\n var x = 0;\n var y = 0;\n for (var i = 0; i <= this.n; i++) {\n var binomialCoefficient = _binomialCoefficient(this.n, i);\n var term = binomialCoefficient * Math.pow(1 - t, this.n - i) * Math.pow(t, i);\n x += term * this.controlPoints[i][0];\n y += term * this.controlPoints[i][1];\n }\n this.vertexList.push([x, y]);\n }\n }\n else if (this.dimension === 3) {\n for (var t = 0; t <= 1; t += this.increment) {\n var xyz = [0, 0, 0];\n for (var i = 0; i <= this.n; i++) {\n var binomialCoefficient = _binomialCoefficient(this.n, i);\n var term = binomialCoefficient * Math.pow(1 - t, this.n - i) * Math.pow(t, i);\n for (var d = 0; d < 3; d++) {\n xyz[d] += term * this.controlPoints[i][d];\n }\n }\n this.vertexList.push(xyz);\n }\n }\n this._addVertex(this.controlPoints[this.controlPoints.length - 1]);\n this.dimension = this.vertexList[0].length; // update dimension\n return this.vertexList;\n };\n BezierCurve.prototype._addVertex = function (vArray) {\n // vArray is an array of [x, y] or [x, y, z]\n _lineTo.apply(void 0, vArray);\n };\n BezierCurve.prototype._distVertex = function (vArray1, vArray2) {\n if (this.dimension === 3 && vArray1.length === 3 && vArray2.length === 3) {\n return _helper_dist(vArray1[0], vArray1[1], vArray1[2], vArray2[0], vArray2[1], vArray2[2]);\n }\n else if (this.dimension === 2) {\n return _helper_dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1]);\n }\n return 0;\n };\n BezierCurve.prototype.draw = function (dash) {\n var _this = this;\n if (!dash) {\n _beginPath();\n this.vertexList.map(function (v) { return _this._addVertex(v); });\n if (this.closeType === 'CLOSE')\n _ctx.closePath();\n if (_useP5)\n _closePath(this.closeType);\n else if (this.closeType === 'CLOSE')\n _closePath();\n _helper_style();\n }\n else {\n if (this.increment > 0.008) {\n this.increment = 0.008;\n console.warn('[p5.bezier] Accuracy is changed to 6 for a dash curve.');\n }\n // draw a dash curve\n var solidPart = Math.abs(dash[0]), gapPart = Math.abs(dash[1]), solid = true;\n var lastVertex = this.vertexList[0];\n var toUseVertexInd = 1, toUseVertex = this.vertexList[toUseVertexInd];\n var currentVirtualVertex = lastVertex;\n var availableDist = 0, neededDist = solid ? solidPart : gapPart;\n _ctx.save(); // push\n _ctx.fillStyle = 'rgba(0, 0, 0, 0)'; // TODO\n _beginPath();\n _moveTo.apply(void 0, lastVertex);\n while (toUseVertexInd < this.vertexList.length) {\n toUseVertex = this.vertexList[toUseVertexInd];\n var newDist = this._distVertex(lastVertex, toUseVertex);\n availableDist = newDist;\n while (availableDist >= neededDist) {\n currentVirtualVertex = _interpolateVertex(currentVirtualVertex, toUseVertex, neededDist / availableDist);\n if (solid)\n _lineTo.apply(void 0, currentVirtualVertex);\n else\n _moveTo.apply(void 0, currentVirtualVertex);\n availableDist -= neededDist;\n solid = !solid;\n neededDist = solid ? solidPart : gapPart;\n }\n // available dist is not enough, used as much as possible\n if (solid)\n _lineTo.apply(void 0, toUseVertex);\n else\n _moveTo.apply(void 0, toUseVertex);\n var usedDist = this._distVertex(currentVirtualVertex, toUseVertex);\n neededDist -= usedDist;\n lastVertex = toUseVertex;\n currentVirtualVertex = lastVertex;\n toUseVertexInd++;\n }\n _helper_style();\n _ctx.restore();\n }\n };\n BezierCurve.prototype.update = function (newControlPointList) {\n if (newControlPointList.length !== this.controlPoints.length) {\n throw new Error('[p5.bezier] The number of control points changed.');\n }\n else if (this.controlPoints.every(function (v, i) { return v === newControlPointList[i]; })) {\n return;\n }\n else {\n this.controlPoints = newControlPointList;\n this._buildVertexList();\n }\n };\n BezierCurve.prototype.move = function (x, y, z, toDraw, dash) {\n if (z === void 0) { z = null; }\n if (toDraw === void 0) { toDraw = true; }\n if (z === null && this.dimension === 3) {\n throw new Error('[p5.bezier] X, Y, and Z are needed to move a 3D curve.');\n }\n else {\n var toMove_1 = [x, y];\n if (z !== null)\n toMove_1.push(z);\n var newCurveV = this.vertexList.map(function (v) { return v.slice(); });\n var newCurveObj = new BezierCurve(this.controlPoints, this.closeType, this.increment, this.dimension, newCurveV);\n newCurveObj.vertexList = newCurveObj.vertexList.map(function (v) { return v.map(function (val, i) { return val + toMove_1[i]; }); });\n if (toDraw)\n newCurveObj.draw(dash);\n return newCurveObj;\n }\n };\n BezierCurve.prototype.shortest = function (pX, pY, pZ) {\n var _this = this;\n if (pZ === void 0) { pZ = 0; }\n var minVertex = [0, 0, 0];\n var dMin = Infinity;\n this.vertexList.map(function (v) {\n var nowMin = _this._distVertex(v, [pX, pY, pZ]);\n if (dMin > nowMin) {\n dMin = nowMin;\n minVertex = __spreadArray([], v, true);\n }\n });\n return minVertex;\n };\n return BezierCurve;\n}());\nexport { initBezier, newBezier, newBezierObj };\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","__spreadArray","to","from","pack","arguments","length","ar","i","l","Array","slice","concat","window","console","log","_canvas","_ctx","_dimension","_useP5","_beginPath","_moveTo","_lineTo","_closePath","_p5bezierAccuracyListAll","_calculatedFactorials","_calculatedBinomialCoefficients","_determineDimension","context","isP3D","constructor","name","_ensureFactorials","n","_helper_factorial","_binomialCoefficient","undefined","_helper_binomialCoefficient","_helper_dist","args","_i","Math","hypot","_helper_style","_doFill","fill","_doStroke","stroke","_deepCopyPoints","arr","map","v","_findCloseCurveExtraPoints","pointList","first","last","second","secondLast","initBezier","canvas","drawingContext","p5","Graphics","Renderer","Error","warn","useP5","beginShape","vertex","endShape","beginPath","bind","moveTo","lineTo","closePath","_setCanvasFunctions","newBezier","closeType","accuracy","closeCurveExtraPoints","push","apply","tIncrement","x","y","t","coefficient","pow","xyz","d","newBezierObj","increment","BezierCurve","points","dimension","vertexList","_a","controlPoints","p","_buildVertexList","term","_addVertex","vArray","_distVertex","vArray1","vArray2","draw","dash","v1","v2","_this","solidPart","abs","gapPart","solid","lastVertex","toUseVertexInd","toUseVertex","currentVirtualVertex","availableDist","neededDist","save","fillStyle","restore","update","newControlPointList","every","move","z","toDraw","toMove_1","newCurveV","newCurveObj","val","shortest","pX","pY","pZ","minVertex","dMin","Infinity","nowMin"],"sourceRoot":""}
1
+ {"version":3,"file":"p5.bezier.min.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAoB,WAAID,IAExBD,EAAiB,WAAIC,GACtB,CATD,CASGK,MAAM,IACT,mBCTA,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,gCCA3E,IACII,EAAc,CACrB,EAAG,GACH,EAAG,IACH,EAAG,KACH,EAAG,KACH,EAAG,MAEHC,EAAwB,CAAC,GACzBC,EAAwB,CAAC,EAO7B,SAASC,EAAGC,GACR,OAAOH,EAAsBG,EACjC,CAUO,SAASC,EAAqBC,EAAGF,GACpC,OAAU,IAANA,GAAWA,IAAME,EACV,EACJJ,EAAsBI,GAAGF,EACpC,EArBA,SAAkCE,GAE9B,IADA,IACSF,EADKH,EAAsBM,OACdH,GAAKE,EAAGF,IAC1BH,EAAsBG,GAAKA,EAAIH,EAAsBG,EAAI,EACjE,CAmBAI,CAAyBC,KAdzB,SAA4CC,GACxC,IAAK,IAAIJ,EAAI,EAAGA,GAAKI,EAAIJ,IAAK,CAC1BJ,EAAsBI,GAAK,CAAC,EAC5B,IAAK,IAA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IAAN1B,IAAgBA,EAAI,WACT,IAAXsD,IAAqBA,GAAS,GACxB,OAANtD,GAAiC,IAAnBxH,KAAK+F,UACnB,MAAM,IAAIkB,MAAM,yDAEpB,IAAI8D,EAAS,CAACzD,EAAGC,GACP,OAANC,GACAuD,EAAOrC,KAAKlB,GAChB,IAAIwD,EAAYhL,KAAKwI,WAAWzD,KAAI,SAAUQ,GAAK,OAAOA,EAAErD,OAAS,IACjE+I,EAAc,IAAI3C,EAAYtI,KAAKyI,cAAezI,KAAK4H,UAAW5H,KAAKmI,UAAWnI,KAAKmD,EAAG6H,GAI9F,OAHAC,EAAYzC,WAAayC,EAAYzC,WAAWzD,KAAI,SAAUQ,GAAK,OAAOA,EAAER,KAAI,SAAUmG,EAAKhK,GAAK,OAAOgK,EAAMH,EAAO7J,EAAI,GAAI,IAC5H4J,GACAG,EAAYtD,KAAKuB,GACd+B,CACX,EACA3C,EAAY3H,UAAUwK,SAAW,SAAUC,EAAIC,EAAIC,GAC/C,IAAIjC,EAAQrJ,UACD,IAAPsL,IAAiBA,EAAK,GAC1B,IAAIC,EAAY,CAAC,EAAG,EAAG,GACnBC,EAAOC,OAAOC,kBAQlB,OAPA1L,KAAKwI,WAAWzD,KAAI,SAAUQ,GAC1B,IAAIoG,EAAStC,EAAMN,YAAYxD,EAAG,CAAC6F,EAAIC,EAAIC,IACvCE,EAAOG,IACPH,EAAOG,EACPJ,EAAY,EAAc,GAAIhG,GAAG,GAEzC,IACOgG,CACX,EACOjD,CACX,CA7IgC,GA8IhC,QAlJA,SAAoBlF,GAChB,OAAO,IAAImD,EAASnD,EACxB,sBN7FA","sources":["webpack://initBezier/webpack/universalModuleDefinition","webpack://initBezier/webpack/bootstrap","webpack://initBezier/webpack/runtime/define property getters","webpack://initBezier/webpack/runtime/hasOwnProperty shorthand","webpack://initBezier/./src/coefficients.ts","webpack://initBezier/./src/utils.ts","webpack://initBezier/./src/p5.bezier.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"initBezier\"] = factory();\n\telse\n\t\troot[\"initBezier\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","export var MAX_DEGREE = 160;\nexport var _smoothness = {\n 1: 0.1,\n 2: 0.02,\n 3: 0.001,\n 4: 0.0005,\n 5: 0.0002,\n};\nvar _calculatedFactorials = [1];\nvar _binomialCoefficients = {};\n/* -------------------------------------------------------------------------- */\nfunction _helper_ensureFactorials(n) {\n var prevLen = _calculatedFactorials.length;\n for (var i = prevLen; i <= n; i++)\n _calculatedFactorials[i] = i * _calculatedFactorials[i - 1];\n}\nfunction _f(i) {\n return _calculatedFactorials[i];\n}\n/* -------------------------------------------------------------------------- */\nfunction _helper_ensureBinomialCoefficients(_n) {\n for (var n = 2; n <= _n; n++) {\n _binomialCoefficients[n] = {};\n for (var i = 1; i < n; i++) {\n _binomialCoefficients[n][i] = _f(n) / (_f(i) * _f(n - i));\n }\n }\n}\nexport function _binomialCoefficient(n, i) {\n if (i === 0 || i === n)\n return 1;\n return _binomialCoefficients[n][i];\n}\n/* -------------------------------------------------------------------------- */\n_helper_ensureFactorials(MAX_DEGREE + 1);\n_helper_ensureBinomialCoefficients(MAX_DEGREE + 1);\n","var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nimport { MAX_DEGREE } from './coefficients';\nexport function _getDimension(\n// biome-ignore lint/suspicious/noExplicitAny: p5 typing\ncontext, isP3D) {\n return context.constructor.name === 'WebGLRenderingContext' || isP3D ? 3 : 2;\n}\nexport function _getCanvasUtils(b) {\n if (b.useP5) {\n b.beginPath = b.canvas.beginShape;\n b.moveTo = b.canvas.vertex;\n b.lineTo = b.canvas.vertex;\n b.closePath = b.canvas.endShape;\n }\n else {\n if (b.ctx instanceof WebGLRenderingContext) {\n b.beginPath = function () { };\n b.moveTo = function (x, y, z) {\n if (z === void 0) { z = 0; }\n return b.ctx.vertexAttrib3f(0, x, y, z);\n };\n b.lineTo = function (x, y, z) {\n if (z === void 0) { z = 0; }\n return b.ctx.vertexAttrib3f(0, x, y, z);\n };\n b.closePath = function () { };\n }\n else {\n b.beginPath = b.ctx.beginPath.bind(b.ctx);\n b.moveTo = b.ctx.moveTo.bind(b.ctx);\n b.lineTo = b.ctx.lineTo.bind(b.ctx);\n b.closePath = b.ctx.closePath.bind(b.ctx);\n }\n }\n}\nexport function _dist() {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n var len = args.length;\n if (len === 4) {\n var dx = args[0] - args[2];\n var dy = args[1] - args[3];\n return Math.sqrt(dx * dx + dy * dy);\n }\n if (len === 6) {\n var dx = args[0] - args[3];\n var dy = args[1] - args[4];\n var dz = args[2] - args[5];\n return Math.sqrt(dx * dx + dy * dy + dz * dz);\n }\n return 0;\n}\nexport function _setStyles(b) {\n if (b.canvas._doFill)\n b.ctx.fill();\n if (b.canvas._doStroke)\n b.ctx.stroke();\n}\n/* -------------------------------------------------------------------------- */\nvar SeedRandom = /** @class */ (function () {\n function SeedRandom(seed) {\n this.m = Math.pow(2, 31) - 1;\n this.a = 1103515245;\n this.c = 12345;\n this.state = seed;\n }\n SeedRandom.prototype.r = function () {\n this.state = (this.a * this.state + this.c) % this.m;\n return this.state / this.m;\n };\n SeedRandom.prototype.next = function (min, max) {\n return Math.floor(this.r() * (max - min + 1)) + min;\n };\n return SeedRandom;\n}());\nvar seed = 1234;\nexport function _concentrate(pointList, close) {\n if (close === void 0) { close = false; }\n var save = close ? 3 : 0;\n var limit = MAX_DEGREE - save;\n if (pointList.length <= limit)\n return _copy(pointList);\n var excessPoints = pointList.length - limit;\n var rng = new SeedRandom(seed);\n var rmIndex = new Set();\n __spreadArray([], new Array(excessPoints), true).map(function (_, ind) {\n var r = rng.next(5 + ind, limit - 5 + ind);\n while (rmIndex.has(r)) {\n r = rng.next(5 + ind, limit - 5 + ind);\n }\n rmIndex.add(r);\n });\n return _copy(pointList.filter(function (_, index) { return !rmIndex.has(index); }));\n}\nfunction _copy(arr) {\n return arr.map(function (v) { return v.slice(); });\n}\nexport function _getCloseCurvePoints(pointList) {\n var len = pointList.length;\n if (len === 0)\n return [];\n var first = pointList[0];\n var last = pointList[len - 1];\n if (len === 1)\n return _copy([first]);\n var second = pointList[1];\n var secondLast = pointList[len - 2];\n return _copy([\n [2 * last[0] - secondLast[0], 2 * last[1] - secondLast[1]],\n [2 * first[0] - second[0], 2 * first[1] - second[1]],\n first,\n ]);\n}\nexport function _interpolateVertex(v1, v2, t) {\n var len1 = v1.length;\n var len2 = v2.length;\n if (len1 === 2 && len2 === 2) {\n return [v1[0] + (v2[0] - v1[0]) * t, v1[1] + (v2[1] - v1[1]) * t];\n }\n if (len1 === 3 && len2 === 3) {\n return [\n v1[0] + (v2[0] - v1[0]) * t,\n v1[1] + (v2[1] - v1[1]) * t,\n v1[2] + (v2[2] - v1[2]) * t,\n ];\n }\n return v2;\n}\n","/*\np5.bezier library by Peiling Jiang\n2020\n\nupdated Aug 2024\n*/\nvar __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\nimport packageJson from '../package.json';\nimport { _binomialCoefficient, _smoothness, } from './coefficients';\nimport { _concentrate, _dist, _getCanvasUtils, _getCloseCurvePoints, _getDimension, _interpolateVertex, _setStyles, } from './utils';\nwindow.console.log(\"[p5.bezier] \".concat(packageJson.version));\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n// helpers\nfunction _bezierVertex(pointList, n, t, dimension) {\n var vertex = new Array(dimension).fill(0);\n var oneMinusT = 1 - t;\n for (var i = 0; i <= n; i++) {\n var coefficient = _binomialCoefficient(n, i) * Math.pow(oneMinusT, (n - i)) * Math.pow(t, i);\n for (var d = 0; d < dimension; d++)\n vertex[d] += coefficient * pointList[i][d];\n }\n return vertex;\n}\nfunction _drawBezierCurve(bezierCanvas, pointList, smoothness) {\n var n = pointList.length - 1;\n var increment = _smoothness[smoothness];\n for (var t = 0; t <= 1; t += increment) {\n var v = _bezierVertex(pointList, n, t, bezierCanvas.dimension);\n bezierCanvas.lineTo.apply(bezierCanvas, v);\n }\n}\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\n/* -------------------------------------------------------------------------- */\nvar P5Bezier = /** @class */ (function () {\n // biome-ignore lint/suspicious/noExplicitAny: p5 typing\n function P5Bezier(canvas) {\n this.b = {\n canvas: null,\n ctx: null,\n dimension: 2,\n useP5: true,\n beginPath: function () { },\n moveTo: function () { },\n lineTo: function () { },\n closePath: function () { },\n };\n this.b.canvas = canvas;\n this.b.ctx = this.b.canvas.drawingContext;\n if (typeof p5 !== 'undefined' && canvas instanceof p5.Graphics) {\n this.b.useP5 = true;\n this.b.dimension = _getDimension(this.b.ctx, false);\n }\n else if ((typeof p5 !== 'undefined' && canvas instanceof p5.Renderer) ||\n canvas.drawingContext) {\n this.b.useP5 = false;\n if (typeof p5 === 'undefined' ||\n (typeof p5 !== 'undefined' && !(canvas instanceof p5.Renderer)))\n window.console.warn('[p5.bezier] Support beyond p5.js is not tested');\n this.b.dimension = _getDimension(this.b.ctx, canvas.isP3D);\n }\n else\n throw new Error('[p5.bezier] Canvas is not supported');\n _getCanvasUtils(this.b);\n }\n P5Bezier.prototype.draw = function (pointList, closeType, smoothness) {\n var _a, _b;\n if (closeType === void 0) { closeType = 'OPEN'; }\n if (smoothness === void 0) { smoothness = 3; }\n var _pL = closeType === 'CLOSE'\n ? __spreadArray(__spreadArray([], _concentrate(pointList, true), true), _getCloseCurvePoints(pointList), true) : _concentrate(pointList);\n this.b.beginPath();\n (_a = this.b).moveTo.apply(_a, _pL[0]);\n _drawBezierCurve(this.b, _pL, smoothness);\n (_b = this.b).lineTo.apply(_b, _pL[_pL.length - 1]);\n if (this.b.useP5)\n this.b.closePath(closeType);\n else if (closeType === 'CLOSE')\n this.b.closePath();\n _setStyles(this.b);\n return _pL;\n };\n P5Bezier.prototype.new = function (pointList, closeType, smoothness) {\n if (closeType === void 0) { closeType = 'OPEN'; }\n if (smoothness === void 0) { smoothness = 3; }\n var increment = _smoothness[smoothness];\n return new BezierCurve(pointList, closeType, increment, this.b);\n };\n return P5Bezier;\n}());\n// biome-ignore lint/suspicious/noExplicitAny: p5 typing\nfunction initBezier(canvas) {\n return new P5Bezier(canvas);\n}\n/* -------------------------------------------------------------------------- */\nvar BezierCurve = /** @class */ (function () {\n function BezierCurve(points, closeType, increment, bezierCanvas, vertexList) {\n var _a;\n if (vertexList === void 0) { vertexList = null; }\n this.controlPoints = _concentrate(points, closeType === 'CLOSE');\n if (closeType === 'CLOSE') {\n (_a = this.controlPoints).push.apply(_a, _getCloseCurvePoints(this.controlPoints));\n this.closeType = 'CLOSE';\n }\n else\n this.closeType = 'OPEN';\n this.dimension = bezierCanvas.dimension;\n this.increment = increment;\n this.vertexList = [];\n this.p = this.controlPoints.length; // has p points for (p - 1) degree curves\n this.n = this.p - 1; // degree\n this.b = bezierCanvas;\n if (vertexList === null)\n this._buildVertexList();\n else\n this.vertexList = __spreadArray([], vertexList, true);\n }\n BezierCurve.prototype._buildVertexList = function () {\n this.vertexList = [];\n for (var t = 0; t <= 1; t += this.increment) {\n var v = _bezierVertex(this.controlPoints, this.n, t, this.dimension);\n this.vertexList.push(v);\n }\n this._addVertex(this.controlPoints[this.controlPoints.length - 1]);\n this.dimension = this.vertexList[0].length;\n return this.vertexList;\n };\n BezierCurve.prototype._addVertex = function (vArray) {\n var _a;\n (_a = this.b).lineTo.apply(_a, vArray);\n };\n BezierCurve.prototype._distVertex = function (vArray1, vArray2) {\n return this.dimension === 3 && vArray1.length === 3 && vArray2.length === 3\n ? _dist(vArray1[0], vArray1[1], vArray1[2], vArray2[0], vArray2[1], vArray2[2])\n : this.dimension === 2\n ? _dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1])\n : 0;\n };\n BezierCurve.prototype.draw = function (dash) {\n if (!dash) {\n this._solidCurve();\n }\n else {\n this._dashedCurve(dash);\n }\n };\n BezierCurve.prototype._solidCurve = function () {\n var _this = this;\n this.b.beginPath();\n this.vertexList.map(function (v) { return _this._addVertex(v); });\n if (this.closeType === 'CLOSE')\n this.b.closePath();\n if (this.b.useP5)\n this.b.closePath(this.closeType);\n else if (this.closeType === 'CLOSE')\n this.b.closePath();\n _setStyles(this.b);\n };\n BezierCurve.prototype._dashedCurve = function (dash) {\n var _a, _b, _c, _d, _e;\n if (this.increment > 0.001) {\n this.increment = 0.001;\n window.console.warn('[p5.bezier] Smoothness set to 3 for a dashed curve');\n }\n var _f = dash.map(Math.abs), solidPart = _f[0], gapPart = _f[1];\n var solid = true;\n var lastVertex = this.vertexList[0];\n var toUseVertexInd = 1;\n var currentVirtualVertex = lastVertex;\n var availableDist = 0;\n var neededDist = solidPart;\n this.b.ctx.save();\n this.b.ctx.fillStyle = 'rgba(0, 0, 0, 0)';\n this.b.beginPath();\n (_a = this.b).moveTo.apply(_a, lastVertex);\n while (toUseVertexInd < this.vertexList.length) {\n var toUseVertex = this.vertexList[toUseVertexInd];\n availableDist = this._distVertex(lastVertex, toUseVertex);\n while (availableDist >= neededDist) {\n currentVirtualVertex = _interpolateVertex(currentVirtualVertex, toUseVertex, neededDist / availableDist);\n solid\n ? (_b = this.b).lineTo.apply(_b, currentVirtualVertex) : (_c = this.b).moveTo.apply(_c, currentVirtualVertex);\n availableDist -= neededDist;\n solid = !solid;\n neededDist = solid ? solidPart : gapPart;\n }\n solid ? (_d = this.b).lineTo.apply(_d, toUseVertex) : (_e = this.b).moveTo.apply(_e, toUseVertex);\n neededDist -= this._distVertex(currentVirtualVertex, toUseVertex);\n lastVertex = toUseVertex;\n currentVirtualVertex = lastVertex;\n toUseVertexInd++;\n }\n _setStyles(this.b);\n this.b.ctx.restore();\n };\n BezierCurve.prototype.update = function (newControlPointList) {\n if (newControlPointList.length !== this.controlPoints.length) {\n throw new Error('[p5.bezier] The number of control points changed');\n }\n if (this.controlPoints.every(function (v, i) { return v === newControlPointList[i]; })) {\n return;\n }\n this.controlPoints = newControlPointList;\n this._buildVertexList();\n };\n BezierCurve.prototype.move = function (x, y, z, toDraw, dash) {\n if (z === void 0) { z = null; }\n if (toDraw === void 0) { toDraw = true; }\n if (z === null && this.dimension === 3) {\n throw new Error('[p5.bezier] X, Y, and Z are needed to move a 3D curve');\n }\n var toMove = [x, y];\n if (z !== null)\n toMove.push(z);\n var newCurveV = this.vertexList.map(function (v) { return v.slice(); });\n var newCurveObj = new BezierCurve(this.controlPoints, this.closeType, this.increment, this.b, newCurveV);\n newCurveObj.vertexList = newCurveObj.vertexList.map(function (v) { return v.map(function (val, i) { return val + toMove[i]; }); });\n if (toDraw)\n newCurveObj.draw(dash);\n return newCurveObj;\n };\n BezierCurve.prototype.shortest = function (pX, pY, pZ) {\n var _this = this;\n if (pZ === void 0) { pZ = 0; }\n var minVertex = [0, 0, 0];\n var dMin = Number.POSITIVE_INFINITY;\n this.vertexList.map(function (v) {\n var nowMin = _this._distVertex(v, [pX, pY, pZ]);\n if (dMin > nowMin) {\n dMin = nowMin;\n minVertex = __spreadArray([], v, true);\n }\n });\n return minVertex;\n };\n return BezierCurve;\n}());\nexport default initBezier;\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","_smoothness","_calculatedFactorials","_binomialCoefficients","_f","i","_binomialCoefficient","n","length","_helper_ensureFactorials","MAX_DEGREE","_n","_helper_ensureBinomialCoefficients","__spreadArray","to","from","pack","arguments","ar","l","Array","slice","concat","_getDimension","context","isP3D","constructor","name","_dist","args","_i","len","dx","dy","Math","sqrt","dz","_setStyles","b","canvas","_doFill","ctx","fill","_doStroke","stroke","SeedRandom","seed","m","pow","a","c","state","r","next","min","max","floor","_concentrate","pointList","close","limit","_copy","excessPoints","rng","rmIndex","Set","map","_","ind","has","add","filter","index","arr","v","_getCloseCurvePoints","first","last","second","secondLast","_bezierVertex","t","dimension","vertex","oneMinusT","coefficient","d","window","console","log","P5Bezier","useP5","beginPath","moveTo","lineTo","closePath","drawingContext","p5","Graphics","Renderer","Error","warn","beginShape","endShape","WebGLRenderingContext","x","y","z","vertexAttrib3f","bind","draw","closeType","smoothness","_a","_b","_pL","apply","bezierCanvas","increment","_drawBezierCurve","new","BezierCurve","points","vertexList","controlPoints","push","p","_buildVertexList","_addVertex","vArray","_distVertex","vArray1","vArray2","dash","_dashedCurve","_solidCurve","_this","_c","_d","_e","v1","v2","len1","len2","abs","solidPart","gapPart","solid","lastVertex","toUseVertexInd","currentVirtualVertex","availableDist","neededDist","save","fillStyle","toUseVertex","restore","update","newControlPointList","every","move","toDraw","toMove","newCurveV","newCurveObj","val","shortest","pX","pY","pZ","minVertex","dMin","Number","POSITIVE_INFINITY","nowMin"],"sourceRoot":""}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export type CloseType = 'OPEN' | 'CLOSE';
2
+ export type Dimension = 2 | 3;
3
+ export type Point = [number, number] | [number, number, number];
4
+ export type PointList = Point[];
5
+ export type Vertex = [number, number] | [number, number, number];
6
+ export type VertexList = Vertex[];
7
+ export type BezierCanvas = {
8
+ canvas: any;
9
+ ctx: any;
10
+ dimension: Dimension;
11
+ useP5: boolean;
12
+ beginPath: () => void;
13
+ moveTo: (...args: Vertex) => void;
14
+ lineTo: (...args: Vertex) => void;
15
+ closePath: (closeType?: CloseType) => void;
16
+ };
17
+ export declare function _getDimension(context: any, isP3D: boolean): Dimension;
18
+ export declare function _getCanvasUtils(b: BezierCanvas): void;
19
+ export declare function _dist(...args: number[]): number;
20
+ export declare function _setStyles(b: BezierCanvas): void;
21
+ export declare function _concentrate(pointList: PointList, close?: boolean): PointList;
22
+ export declare function _getCloseCurvePoints(pointList: PointList): PointList;
23
+ export declare function _interpolateVertex(v1: Vertex, v2: Vertex, t: number): Vertex;
package/package.json CHANGED
@@ -1,45 +1,43 @@
1
1
  {
2
- "name": "p5bezier",
3
- "version": "0.6.0",
4
- "description": "Bezier curves for canvas graphics on the web, built to work with p5.js.",
5
- "main": "lib/p5.bezier.min.js",
6
- "keywords": [
7
- "p5.js",
8
- "Bezier",
9
- "Computer Graphics"
10
- ],
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/peilingjiang/p5.bezier.git"
14
- },
15
- "author": "Peiling Jiang",
16
- "license": "MIT",
17
- "bugs": {
18
- "url": "https://github.com/peilingjiang/p5.bezier/issues"
19
- },
20
- "homepage": "https://github.com/peilingjiang/p5.bezier#readme",
21
- "devDependencies": {
22
- "eslint": "^8.56.0",
23
- "husky": "^8.0.3",
24
- "lint-staged": "^15.2.0",
25
- "prettier": "^3.1.1",
26
- "terser-webpack-plugin": "^5.3.9",
27
- "ts-loader": "^9.5.1",
28
- "typescript": "^5.3.3",
29
- "webpack": "^5.89.0",
30
- "webpack-cli": "^5.1.4"
31
- },
32
- "scripts": {
33
- "format": "prettier --write \"**/*.{js,json,md,html,css}\"",
34
- "start": "webpack --env=development",
35
- "build": "webpack --env=production",
36
- "prepare": "husky install"
37
- },
38
- "lint-staged": {
39
- "*.js": "eslint --cache --fix",
40
- "*.{js,json,md,html,css}": "prettier --write"
41
- },
42
- "files": [
43
- "lib"
44
- ]
2
+ "name": "p5bezier",
3
+ "version": "0.7.0",
4
+ "author": "Peiling Jiang",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/peilingjiang/p5.bezier.git"
8
+ },
9
+ "main": "lib/p5.bezier.min.js",
10
+ "devDependencies": {
11
+ "@biomejs/biome": "^1.8.3",
12
+ "@types/p5": "^1.7.6",
13
+ "husky": "^9.1.5",
14
+ "lint-staged": "^15.2.9",
15
+ "prettier": "^3.3.3",
16
+ "terser-webpack-plugin": "^5.3.10",
17
+ "ts-loader": "^9.5.1",
18
+ "typescript": "^5.5.4",
19
+ "webpack": "^5.93.0",
20
+ "webpack-cli": "^5.1.4"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/peilingjiang/p5.bezier/issues"
24
+ },
25
+ "description": "Bezier curves for canvas graphics on the web, built to work with p5.js",
26
+ "files": ["lib"],
27
+ "homepage": "https://github.com/peilingjiang/p5.bezier#readme",
28
+ "keywords": ["p5.js", "Bezier", "Computer Graphics"],
29
+ "license": "MIT",
30
+ "lint-staged": {
31
+ "*.{ts,json}": "biome check --write --no-errors-on-unmatched",
32
+ "*.{css,md,html}": "prettier --write"
33
+ },
34
+ "scripts": {
35
+ "format": "biome format --write . && prettier --write \"**/*.{css,md,html}\"",
36
+ "lint": "biome check --write .",
37
+ "start": "webpack --env=development",
38
+ "build": "webpack --env=production",
39
+ "prepare": "husky",
40
+ "netlify": "cp -r ./lib ./examples/"
41
+ },
42
+ "types": "lib/p5.bezier.d.ts"
45
43
  }