p5bezier 0.3.2 → 0.3.3
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/lib/p5.bezier.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see p5.bezier.min.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.p5bezier=t():e.p5bezier=t()}(
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.p5bezier=t():e.p5bezier=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initBezier:()=>f,newBezier:()=>d,newBezierObj:()=>u});const r=[.2,.1,.05,.04,.02,.01,.008,.002,.001,5e-4,1e-4];let i,o,n,s,h,l,a,p,c;function f(e,t=!1){if(i=e,o=i.drawingContext,p5&&e instanceof p5.Graphics)h=!0,n="WebGLRenderingContext"===o.constructor.name?3:2,l=i.beginShape,a=i.vertex,p=i.vertex,c=i.endShape;else{if(!(p5&&e instanceof p5.Renderer||e.drawingContext))throw new Error("[p5.bezier] Canvas is not supported.");p5&&(!p5||e instanceof p5.Renderer)?n="WebGLRenderingContext"===o.constructor.name?3:2:(window.console.warn("[p5.bezier] Support for non-p5 canvas is not tested."),n=e.isP3D?3:2),h=!1,n="WebGLRenderingContext"===o.constructor.name?3:2,l=o.beginPath.bind(o),a=o.moveTo.bind(o),p=o.lineTo.bind(o),c=o.closePath.bind(o)}s=t}function d(e,t="OPEN",i=6){if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezier() function expects an array, got ${typeof e}.`);const o=r[i];if(0===n);else{if(s)for(let t of e)if(!Array.isArray(e)||t.length!==n)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");"CLOSE"===t&&e.push(e[0]);let r=e.length-1;if(l(),a(...e[0]),2===n){let t,i,n,s;for(n=0;n<=1;n+=o){for(t=0,i=0,s=0;s<=r;s++)t+=w(r)/(w(s)*w(r-s))*Math.pow(1-n,r-s)*Math.pow(n,s)*e[s][0],i+=w(r)/(w(s)*w(r-s))*Math.pow(1-n,r-s)*Math.pow(n,s)*e[s][1];p(t,i)}p(...e.slice(-1)[0])}else if(3===n){let t,i,n,s=[0,0,0];for(t=0;t<=1;t+=o){for(s=[0,0,0],i=0;i<=r;i++)for(n=0;n<3;n++)s[n]+=w(r)/(w(i)*w(r-i))*Math.pow(1-t,r-i)*Math.pow(t,i)*e[i][n];p(...s)}p(...e.slice(-1)[0])}if(h)c(t);else if("CLOSE"===t)c();else if(s&&"OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");x()}}function u(e,t="OPEN",i=6){const o=r[i];if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezierObj() function expects an array, got ${typeof e}.`);if(s)for(let t of e)if(!Array.isArray(e)||t.length!==n)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");return new b(e,t,o,n)}function w(e){return e>1?e*w(e-1):1}function y(){return 4===arguments.length?Math.hypot(arguments[0]-arguments[2],arguments[1]-arguments[3]):6===arguments.length?Math.hypot(arguments[0]-arguments[3],arguments[1]-arguments[4],arguments[2]-arguments[5]):0}function x(){i._doFill&&o.fill(),i._doStroke&&o.stroke()}class b{constructor(e,t,r,i,o=null){if(s&&2!==i&&3!==i)throw new Error(`Dimension error. The bezier curve is ${i}-dimensional and doesn't belong to our world.`);if(this.controlPoints=e,"CLOSE"===t)this.controlPoints.push(e[0]),this.closeType="CLOSE";else{if("OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");this.closeType="OPEN"}this.dimension=i,this.increment=r,this.vertexList=[],this.vertexListLen=0,this.p=this.controlPoints.length,this.n=this.p-1,null===o?this._buildVertexList():(this.vertexList=o,this.vertexListLen=this.vertexList.length)}_buildVertexList(){if(this.vertexList=[],2===this.dimension){let e,t,r,i;for(r=0;r<=1;r+=this.increment){for(e=0,t=0,i=0;i<=this.n;i++)e+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][0],t+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][1];this.vertexList.push([e,t])}}else if(3===this.dimension){let e,t,r,i=[0,0,0];for(e=0;e<=1;e+=this.increment){for(i[0]=0,i[1]=0,i[2]=0,t=0;t<=this.n;t++)for(r=0;r<3;r++)i[r]+=w(this.n)/(w(t)*w(this.n-t))*Math.pow(1-e,this.n-t)*Math.pow(e,t)*this.controlPoints[t][r];this.vertexList.push(i)}}return this._addVertex(this.controlPoints.slice(-1)[0]),this.dimension=this.vertexList[0].length,this.vertexListLen=this.vertexList.length,this.vertexList}_addVertex(e){if(2!==this.dimension&&3!==this.dimension)throw new Error("Vertices can only be in 2D or 3D space.");p(...e)}_distVertex(e,t){return 2===this.dimension?y(e[0],e[1],t[0],t[1]):3===this.dimension?y(e[0],e[1],e[2],t[0],t[1],t[2]):void 0}draw(e){if(e){if(!(Array.isArray(e)&&2===e.length&&this.increment<=.008))throw this.increment>.008?new Error("Fidelity is too low for a dash line. It should be at least 6."):new Error("Your dash array input is not valid. Make sure it's an array of two numbers.");{let t=Math.abs(e[0]),r=t+Math.abs(e[1]),i=0,n=0,s=this.vertexList[0],h=!0;o.save(),o.fillStyle="rgba(0, 0, 0, 0)",l(),a(...this.vertexList[0]);for(let e=1;e<this.vertexListLen;e++)i+=this._distVertex(s,this.vertexList[e]),n=i%r,n<=t&&h?this._addVertex(this.vertexList[e]):n>t&&n<=r&&h?h=!1:n<=t&&!h&&(a(...this.vertexList[e]),h=!0),s=this.vertexList[e];x(),o.restore()}}else{l();for(let e of this.vertexList)this._addVertex(e);"CLOSE"===this.closeType&&o.closePath(),h?c(this.closeType):"CLOSE"===this.closeType&&c(),x()}}update(e){if(e.length!==this.controlPoints.length)throw new Error("The number of points changed. (Keep the length of the point array the same.)");L(this.controlPoints,e)||(this.controlPoints=e,this._buildVertexList())}move(e,t,r=null,i=!0,o=0){if(null===r&&3===this.dimension)throw new Error("To move a 3D curve, please specify (x, y, z).");{let n=[e,t];null!==r&&n.push(r);let s=[];for(let e=0;e<this.vertexListLen;e++)s.push(this.vertexList[e].slice());let h=new b(this.controlPoints,this.closeType,this.increment,this.dimension,s);for(let e=0;e<h.vertexListLen;e++)for(let t=0;t<h.dimension;t++)h.vertexList[e][t]+=n[t];return i&&h.draw(o),h}}shortest(e,t,r=0){let i,o=-1,n=0;for(let s of this.vertexList)-1===o?(o=this._distVertex(s,[e,t,r]),i=s):(n=this._distVertex(s,[e,t,r]),o>n&&(o=n,i=s));return i}}const L=(e,t)=>e.length===t.length&&e.every(((e,r)=>e===t[r]));return t})()));
|
|
3
3
|
//# sourceMappingURL=p5.bezier.min.js.map
|
package/lib/p5.bezier.min.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,QAAkB,SAAID,IAEtBD,EAAe,SAAIC,GACpB,CATD,CASGK,MAAM,IACT,mBCTA,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EA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c,KAAKC,cACLD,KAAKnC,UACLmC,KAAKG,UACLH,KAAKE,UACL+B,GAGF,IAAK,IAAIxD,EAAI,EAAGA,EAAIyD,EAAY7B,cAAe5B,IAC7C,IAAK,IAAI0D,EAAI,EAAGA,EAAID,EAAYhC,UAAWiC,IACzCD,EAAY9B,WAAW3B,GAAG0D,IAAMH,EAAOG,GAM3C,OAHIJ,GACFG,EAAYrB,KAAKC,GAEZoB,CACT,CACF,CAEAE,SAASC,EAAIC,EAAIC,EAAK,GAIpB,IAEIC,EAFAC,GAAQ,EACVC,EAAS,EAEX,IAAK,IAAIlB,KAAKxB,KAAKI,YACH,IAAVqC,GACFA,EAAOzC,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IACpCC,EAAYhB,IAEZkB,EAAS1C,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IAClCE,EAAOC,IACTD,EAAOC,EACPF,EAAYhB,IAIlB,OAAOgB,CACT,EAMF,MAAMZ,EAAc,CAACzC,EAAGwD,IACtBxD,EAAEhB,SAAWwE,EAAExE,QAAUgB,EAAEyD,OAAM,CAACpB,EAAG/C,IAAM+C,IAAMmB,EAAElE,eLpbrD","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.js"],"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})(self, () => {\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*/\n\nconst p5bezierAccuracyListAll = [\n 0.2, 0.1, 0.05, 0.04, 0.02, 0.01, 0.008, 0.002, 0.001, 0.0005, 0.0001,\n]\n\nlet _canvas,\n _ctx,\n _dimension,\n _strict,\n _useP5,\n _beginPath,\n _moveTo,\n _lineTo,\n _closePath\n\nexport function initBezier(canvas, strictMode = false) {\n _canvas = canvas\n _ctx = _canvas.drawingContext\n\n // eslint-disable-next-line no-undef\n if (p5 && canvas instanceof p5.Graphics) {\n // p5 graphics\n _useP5 = true\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _canvas.beginShape\n _moveTo = _canvas.vertex\n _lineTo = _canvas.vertex\n _closePath = _canvas.endShape\n // eslint-disable-next-line no-undef\n } else if ((p5 && canvas instanceof p5.Renderer) || canvas.drawingContext) {\n // p5 canvas or other canvas\n // eslint-disable-next-line no-undef\n if (!p5 || (p5 && !(canvas instanceof p5.Renderer))) {\n window.console.warn(\n '[p5.bezier] Support for non-p5 canvas is not tested.'\n )\n _dimension = canvas.isP3D ? 3 : 2\n } else {\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n }\n _useP5 = false\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _ctx.beginPath.bind(_ctx)\n _moveTo = _ctx.moveTo.bind(_ctx)\n _lineTo = _ctx.lineTo.bind(_ctx)\n _closePath = _ctx.closePath.bind(_ctx)\n } else {\n throw new Error('[p5.bezier] Canvas is not supported.')\n }\n\n _strict = strictMode // Always check and throw errors or not\n}\n\nexport function newBezier(pointList, closeType = 'OPEN', accuracy = 6) {\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezier() function expects an array, got ${typeof pointList}.`\n )\n\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_dimension !== 0) {\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // Add the first point as the last point to close the curve\n if (closeType === 'CLOSE') pointList.push(pointList[0])\n let p = pointList.length // pointList has p points for (p - 1) degree curves\n let n = p - 1\n\n _beginPath()\n _moveTo(...pointList[0])\n // Are we drawing 2D or 3D curves\n if (_dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += tIncrement) {\n x = 0\n y = 0\n for (i = 0; i <= n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][0]\n y +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][1]\n }\n _lineTo(x, y)\n }\n _lineTo(...pointList.slice(-1)[0])\n } else if (_dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += tIncrement) {\n xyz = [0, 0, 0]\n for (i = 0; i <= n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][d]\n }\n }\n _lineTo(...xyz)\n }\n _lineTo(...pointList.slice(-1)[0])\n }\n\n if (_useP5) _closePath(closeType)\n else if (closeType === 'CLOSE') _closePath()\n else if (_strict && closeType !== 'OPEN')\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n\n _helper_style()\n\n return\n }\n}\n\nexport function newBezierObj(pointList, closeType = 'OPEN', accuracy = 6) {\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezierObj() function expects an array, got ${typeof pointList}.`\n )\n\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // All checks done\n let bObj = new BezierCurve(pointList, closeType, tIncrement, _dimension)\n return bObj\n}\n\nfunction _helper_factorial(a) {\n // Factorial function for binomial coefficient calculation\n return a > 1 ? a * _helper_factorial(a - 1) : 1\n}\n\nfunction _helper_dist() {\n if (arguments.length === 4)\n return Math.hypot(arguments[0] - arguments[2], arguments[1] - arguments[3])\n else if (arguments.length === 6)\n return Math.hypot(\n arguments[0] - arguments[3],\n arguments[1] - arguments[4],\n arguments[2] - arguments[5]\n )\n return 0\n}\n\nfunction _helper_style() {\n if (_canvas._doFill) _ctx.fill()\n if (_canvas._doStroke) _ctx.stroke()\n}\n\nclass BezierCurve {\n // Take pointList, closeType, tIncrement, bezierDimension into constructor\n constructor(pL, closeT, tI, bD, vL = null) {\n if (_strict && bD !== 2 && bD !== 3)\n throw new Error(\n `Dimension error. The bezier curve is ${bD}-dimensional and doesn't belong to our world.`\n )\n\n this.controlPoints = pL\n\n if (closeT === 'CLOSE') {\n this.controlPoints.push(pL[0])\n this.closeType = 'CLOSE'\n } else if (closeT === 'OPEN') {\n this.closeType = 'OPEN'\n } else {\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n }\n\n this.dimension = bD\n this.increment = tI\n this.vertexList = []\n this.vertexListLen = 0\n this.p = this.controlPoints.length // Has p points for (p - 1) degree curves\n this.n = this.p - 1 // Degree\n // Calculate thr vertex\n if (vL === null) {\n this._buildVertexList()\n } else {\n this.vertexList = vL\n this.vertexListLen = this.vertexList.length\n }\n }\n\n _buildVertexList() {\n /*\n Return vertexList\n */\n this.vertexList = []\n if (this.dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += this.increment) {\n x = 0\n y = 0\n for (i = 0; i <= this.n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][0]\n y +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][1]\n }\n this.vertexList.push([x, y])\n }\n } else if (this.dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += this.increment) {\n xyz[0] = 0\n xyz[1] = 0\n xyz[2] = 0\n for (i = 0; i <= this.n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][d]\n }\n }\n this.vertexList.push(xyz)\n }\n }\n // Ending fix\n this._addVertex(this.controlPoints.slice(-1)[0])\n\n this.dimension = this.vertexList[0].length // Update dimension\n this.vertexListLen = this.vertexList.length // Update vertexListLen\n return this.vertexList\n }\n\n _addVertex(vArray) {\n // vArray is an array of [x, y] position or [x, y, z] position\n if (this.dimension === 2 || this.dimension === 3) _lineTo(...vArray)\n else throw new Error('Vertices can only be in 2D or 3D space.')\n }\n\n _distVertex(vArray1, vArray2) {\n // Calculate the distance between\n // vertex_array_1 and vertex_array_2\n if (this.dimension === 2) {\n return _helper_dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1])\n } else if (this.dimension === 3) {\n return _helper_dist(\n vArray1[0],\n vArray1[1],\n vArray1[2],\n vArray2[0],\n vArray2[1],\n vArray2[2]\n )\n }\n }\n\n draw(dash) {\n if (!dash) {\n _beginPath()\n for (let v of this.vertexList) {\n this._addVertex(v)\n }\n\n if (this.closeType === 'CLOSE') _ctx.closePath()\n\n if (_useP5) _closePath(this.closeType)\n else if (this.closeType === 'CLOSE') _closePath()\n\n _helper_style()\n } else if (\n Array.isArray(dash) &&\n dash.length === 2 &&\n this.increment <= 0.008\n ) {\n // Draw a dash curve\n let solidPart = Math.abs(dash[0]) // Length of one solid part\n let onePart = solidPart + Math.abs(dash[1]),\n nowLen = 0,\n modOnePart = 0\n let lastVertex = this.vertexList[0]\n let solid = true // true draw, false break\n\n _ctx.save() // push\n _ctx.fillStyle = 'rgba(0, 0, 0, 0)' // TODO: Enable fill\n _beginPath()\n _moveTo(...this.vertexList[0])\n for (let v = 1; v < this.vertexListLen; v++) {\n nowLen += this._distVertex(lastVertex, this.vertexList[v])\n modOnePart = nowLen % onePart\n if (modOnePart <= solidPart && solid) {\n this._addVertex(this.vertexList[v])\n } else if (modOnePart > solidPart && modOnePart <= onePart && solid) {\n // endShape()\n solid = false\n } else if (modOnePart <= solidPart && !solid) {\n _moveTo(...this.vertexList[v])\n solid = true\n }\n lastVertex = this.vertexList[v]\n }\n // if (solid) {\n // // Shape didn't end\n // endShape()\n // }\n _helper_style()\n _ctx.restore()\n } else if (this.increment > 0.008)\n throw new Error(\n 'Fidelity is too low for a dash line. It should be at least 6.'\n )\n else\n throw new Error(\n \"Your dash array input is not valid. Make sure it's an array of two numbers.\"\n )\n }\n\n update(newControlList) {\n /*\n Update the vertexList when control points change\n */\n if (newControlList.length !== this.controlPoints.length) {\n throw new Error(\n 'The number of points changed. (Keep the length of the point array the same.)'\n )\n } else if (equalArrays(this.controlPoints, newControlList)) {\n // Do we really need to update? No.\n // return ;\n } else {\n this.controlPoints = newControlList\n this._buildVertexList()\n }\n }\n\n move(x, y, z = null, toDraw = true, dash = 0) {\n /*\n Move the curve to another place\n Return a new object\n */\n if (z === null && this.dimension === 3) {\n // A 3D curve treated as 2D error\n throw new Error('To move a 3D curve, please specify (x, y, z).')\n } else {\n let toMove = [x, y]\n if (z !== null) toMove.push(z)\n // Copy to a new object\n let newCurveV = []\n for (let i = 0; i < this.vertexListLen; i++)\n newCurveV.push(this.vertexList[i].slice())\n let newCurveObj = new BezierCurve(\n this.controlPoints,\n this.closeType,\n this.increment,\n this.dimension,\n newCurveV\n )\n // Move\n for (let i = 0; i < newCurveObj.vertexListLen; i++) {\n for (let j = 0; j < newCurveObj.dimension; j++) {\n newCurveObj.vertexList[i][j] += toMove[j]\n }\n }\n if (toDraw) {\n newCurveObj.draw(dash)\n }\n return newCurveObj\n }\n }\n\n shortest(pX, pY, pZ = 0) {\n // Return the point on curve that is closest to the point outside\n // Always return array length of 3\n // Last position (z) be 0 for all 2D calculation\n let dMin = -1,\n nowMin = 0\n let minVertex\n for (let v of this.vertexList) {\n if (dMin === -1) {\n dMin = this._distVertex(v, [pX, pY, pZ])\n minVertex = v\n } else {\n nowMin = this._distVertex(v, [pX, pY, pZ])\n if (dMin > nowMin) {\n dMin = nowMin\n minVertex = v\n }\n }\n }\n return minVertex // An array of vertex position\n }\n}\n\n/* --------------------------------- HELPERS -------------------------------- */\n\n// https://www.30secondsofcode.org/blog/s/javascript-array-comparison\nconst equalArrays = (a, b) =>\n a.length === b.length && a.every((v, i) => v === b[i])\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","p5bezierAccuracyListAll","_canvas","_ctx","_dimension","_strict","_useP5","_beginPath","_moveTo","_lineTo","_closePath","initBezier","canvas","strictMode","drawingContext","p5","Graphics","constructor","name","beginShape","vertex","endShape","Renderer","Error","window","console","warn","isP3D","beginPath","bind","moveTo","lineTo","closePath","newBezier","pointList","closeType","accuracy","Array","isArray","tIncrement","point","length","push","n","x","y","t","i","_helper_factorial","Math","pow","slice","d","xyz","_helper_style","newBezierObj","BezierCurve","a","_helper_dist","arguments","hypot","_doFill","fill","_doStroke","stroke","pL","closeT","tI","bD","vL","this","controlPoints","dimension","increment","vertexList","vertexListLen","p","_buildVertexList","_addVertex","vArray","_distVertex","vArray1","vArray2","draw","dash","solidPart","abs","onePart","nowLen","modOnePart","lastVertex","solid","save","fillStyle","v","restore","update","newControlList","equalArrays","move","z","toDraw","toMove","newCurveV","newCurveObj","j","shortest","pX","pY","pZ","minVertex","dMin","nowMin","b","every"],"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,QAAkB,SAAID,IAEtBD,EAAe,SAAIC,GACpB,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,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,4ECA9D,MAAMC,EAA0B,CAC9B,G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oB,CACT,CACF,CAEAE,SAASC,EAAIC,EAAIC,EAAK,GAIpB,IAEIC,EAFAC,GAAQ,EACVC,EAAS,EAEX,IAAK,IAAIlB,KAAK7G,KAAKyF,YACH,IAAVqC,GACFA,EAAO9H,KAAK+F,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IACpCC,EAAYhB,IAEZkB,EAAS/H,KAAK+F,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IAClCE,EAAOC,IACTD,EAAOC,EACPF,EAAYhB,IAIlB,OAAOgB,CACT,EAMF,MAAMZ,EAAc,CAACxC,EAAGuD,IACtBvD,EAAEhB,SAAWuE,EAAEvE,QAAUgB,EAAEwD,OAAM,CAACpB,EAAG9C,IAAM8C,IAAMmB,EAAEjE,eLpbrD","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.js"],"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*/\n\nconst p5bezierAccuracyListAll = [\n 0.2, 0.1, 0.05, 0.04, 0.02, 0.01, 0.008, 0.002, 0.001, 0.0005, 0.0001,\n]\n\nlet _canvas,\n _ctx,\n _dimension,\n _strict,\n _useP5,\n _beginPath,\n _moveTo,\n _lineTo,\n _closePath\n\nexport function initBezier(canvas, strictMode = false) {\n _canvas = canvas\n _ctx = _canvas.drawingContext\n\n // eslint-disable-next-line no-undef\n if (p5 && canvas instanceof p5.Graphics) {\n // p5 graphics\n _useP5 = true\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _canvas.beginShape\n _moveTo = _canvas.vertex\n _lineTo = _canvas.vertex\n _closePath = _canvas.endShape\n // eslint-disable-next-line no-undef\n } else if ((p5 && canvas instanceof p5.Renderer) || canvas.drawingContext) {\n // p5 canvas or other canvas\n // eslint-disable-next-line no-undef\n if (!p5 || (p5 && !(canvas instanceof p5.Renderer))) {\n window.console.warn(\n '[p5.bezier] Support for non-p5 canvas is not tested.'\n )\n _dimension = canvas.isP3D ? 3 : 2\n } else {\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n }\n _useP5 = false\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _ctx.beginPath.bind(_ctx)\n _moveTo = _ctx.moveTo.bind(_ctx)\n _lineTo = _ctx.lineTo.bind(_ctx)\n _closePath = _ctx.closePath.bind(_ctx)\n } else {\n throw new Error('[p5.bezier] Canvas is not supported.')\n }\n\n _strict = strictMode // Always check and throw errors or not\n}\n\nexport function newBezier(pointList, closeType = 'OPEN', accuracy = 6) {\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezier() function expects an array, got ${typeof pointList}.`\n )\n\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_dimension !== 0) {\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // Add the first point as the last point to close the curve\n if (closeType === 'CLOSE') pointList.push(pointList[0])\n let p = pointList.length // pointList has p points for (p - 1) degree curves\n let n = p - 1\n\n _beginPath()\n _moveTo(...pointList[0])\n // Are we drawing 2D or 3D curves\n if (_dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += tIncrement) {\n x = 0\n y = 0\n for (i = 0; i <= n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][0]\n y +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][1]\n }\n _lineTo(x, y)\n }\n _lineTo(...pointList.slice(-1)[0])\n } else if (_dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += tIncrement) {\n xyz = [0, 0, 0]\n for (i = 0; i <= n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][d]\n }\n }\n _lineTo(...xyz)\n }\n _lineTo(...pointList.slice(-1)[0])\n }\n\n if (_useP5) _closePath(closeType)\n else if (closeType === 'CLOSE') _closePath()\n else if (_strict && closeType !== 'OPEN')\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n\n _helper_style()\n\n return\n }\n}\n\nexport function newBezierObj(pointList, closeType = 'OPEN', accuracy = 6) {\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezierObj() function expects an array, got ${typeof pointList}.`\n )\n\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // All checks done\n let bObj = new BezierCurve(pointList, closeType, tIncrement, _dimension)\n return bObj\n}\n\nfunction _helper_factorial(a) {\n // Factorial function for binomial coefficient calculation\n return a > 1 ? a * _helper_factorial(a - 1) : 1\n}\n\nfunction _helper_dist() {\n if (arguments.length === 4)\n return Math.hypot(arguments[0] - arguments[2], arguments[1] - arguments[3])\n else if (arguments.length === 6)\n return Math.hypot(\n arguments[0] - arguments[3],\n arguments[1] - arguments[4],\n arguments[2] - arguments[5]\n )\n return 0\n}\n\nfunction _helper_style() {\n if (_canvas._doFill) _ctx.fill()\n if (_canvas._doStroke) _ctx.stroke()\n}\n\nclass BezierCurve {\n // Take pointList, closeType, tIncrement, bezierDimension into constructor\n constructor(pL, closeT, tI, bD, vL = null) {\n if (_strict && bD !== 2 && bD !== 3)\n throw new Error(\n `Dimension error. The bezier curve is ${bD}-dimensional and doesn't belong to our world.`\n )\n\n this.controlPoints = pL\n\n if (closeT === 'CLOSE') {\n this.controlPoints.push(pL[0])\n this.closeType = 'CLOSE'\n } else if (closeT === 'OPEN') {\n this.closeType = 'OPEN'\n } else {\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n }\n\n this.dimension = bD\n this.increment = tI\n this.vertexList = []\n this.vertexListLen = 0\n this.p = this.controlPoints.length // Has p points for (p - 1) degree curves\n this.n = this.p - 1 // Degree\n // Calculate thr vertex\n if (vL === null) {\n this._buildVertexList()\n } else {\n this.vertexList = vL\n this.vertexListLen = this.vertexList.length\n }\n }\n\n _buildVertexList() {\n /*\n Return vertexList\n */\n this.vertexList = []\n if (this.dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += this.increment) {\n x = 0\n y = 0\n for (i = 0; i <= this.n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][0]\n y +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][1]\n }\n this.vertexList.push([x, y])\n }\n } else if (this.dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += this.increment) {\n xyz[0] = 0\n xyz[1] = 0\n xyz[2] = 0\n for (i = 0; i <= this.n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][d]\n }\n }\n this.vertexList.push(xyz)\n }\n }\n // Ending fix\n this._addVertex(this.controlPoints.slice(-1)[0])\n\n this.dimension = this.vertexList[0].length // Update dimension\n this.vertexListLen = this.vertexList.length // Update vertexListLen\n return this.vertexList\n }\n\n _addVertex(vArray) {\n // vArray is an array of [x, y] position or [x, y, z] position\n if (this.dimension === 2 || this.dimension === 3) _lineTo(...vArray)\n else throw new Error('Vertices can only be in 2D or 3D space.')\n }\n\n _distVertex(vArray1, vArray2) {\n // Calculate the distance between\n // vertex_array_1 and vertex_array_2\n if (this.dimension === 2) {\n return _helper_dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1])\n } else if (this.dimension === 3) {\n return _helper_dist(\n vArray1[0],\n vArray1[1],\n vArray1[2],\n vArray2[0],\n vArray2[1],\n vArray2[2]\n )\n }\n }\n\n draw(dash) {\n if (!dash) {\n _beginPath()\n for (let v of this.vertexList) {\n this._addVertex(v)\n }\n\n if (this.closeType === 'CLOSE') _ctx.closePath()\n\n if (_useP5) _closePath(this.closeType)\n else if (this.closeType === 'CLOSE') _closePath()\n\n _helper_style()\n } else if (\n Array.isArray(dash) &&\n dash.length === 2 &&\n this.increment <= 0.008\n ) {\n // Draw a dash curve\n let solidPart = Math.abs(dash[0]) // Length of one solid part\n let onePart = solidPart + Math.abs(dash[1]),\n nowLen = 0,\n modOnePart = 0\n let lastVertex = this.vertexList[0]\n let solid = true // true draw, false break\n\n _ctx.save() // push\n _ctx.fillStyle = 'rgba(0, 0, 0, 0)' // TODO: Enable fill\n _beginPath()\n _moveTo(...this.vertexList[0])\n for (let v = 1; v < this.vertexListLen; v++) {\n nowLen += this._distVertex(lastVertex, this.vertexList[v])\n modOnePart = nowLen % onePart\n if (modOnePart <= solidPart && solid) {\n this._addVertex(this.vertexList[v])\n } else if (modOnePart > solidPart && modOnePart <= onePart && solid) {\n // endShape()\n solid = false\n } else if (modOnePart <= solidPart && !solid) {\n _moveTo(...this.vertexList[v])\n solid = true\n }\n lastVertex = this.vertexList[v]\n }\n // if (solid) {\n // // Shape didn't end\n // endShape()\n // }\n _helper_style()\n _ctx.restore()\n } else if (this.increment > 0.008)\n throw new Error(\n 'Fidelity is too low for a dash line. It should be at least 6.'\n )\n else\n throw new Error(\n \"Your dash array input is not valid. Make sure it's an array of two numbers.\"\n )\n }\n\n update(newControlList) {\n /*\n Update the vertexList when control points change\n */\n if (newControlList.length !== this.controlPoints.length) {\n throw new Error(\n 'The number of points changed. (Keep the length of the point array the same.)'\n )\n } else if (equalArrays(this.controlPoints, newControlList)) {\n // Do we really need to update? No.\n // return ;\n } else {\n this.controlPoints = newControlList\n this._buildVertexList()\n }\n }\n\n move(x, y, z = null, toDraw = true, dash = 0) {\n /*\n Move the curve to another place\n Return a new object\n */\n if (z === null && this.dimension === 3) {\n // A 3D curve treated as 2D error\n throw new Error('To move a 3D curve, please specify (x, y, z).')\n } else {\n let toMove = [x, y]\n if (z !== null) toMove.push(z)\n // Copy to a new object\n let newCurveV = []\n for (let i = 0; i < this.vertexListLen; i++)\n newCurveV.push(this.vertexList[i].slice())\n let newCurveObj = new BezierCurve(\n this.controlPoints,\n this.closeType,\n this.increment,\n this.dimension,\n newCurveV\n )\n // Move\n for (let i = 0; i < newCurveObj.vertexListLen; i++) {\n for (let j = 0; j < newCurveObj.dimension; j++) {\n newCurveObj.vertexList[i][j] += toMove[j]\n }\n }\n if (toDraw) {\n newCurveObj.draw(dash)\n }\n return newCurveObj\n }\n }\n\n shortest(pX, pY, pZ = 0) {\n // Return the point on curve that is closest to the point outside\n // Always return array length of 3\n // Last position (z) be 0 for all 2D calculation\n let dMin = -1,\n nowMin = 0\n let minVertex\n for (let v of this.vertexList) {\n if (dMin === -1) {\n dMin = this._distVertex(v, [pX, pY, pZ])\n minVertex = v\n } else {\n nowMin = this._distVertex(v, [pX, pY, pZ])\n if (dMin > nowMin) {\n dMin = nowMin\n minVertex = v\n }\n }\n }\n return minVertex // An array of vertex position\n }\n}\n\n/* --------------------------------- HELPERS -------------------------------- */\n\n// https://www.30secondsofcode.org/blog/s/javascript-array-comparison\nconst equalArrays = (a, b) =>\n a.length === b.length && a.every((v, i) => v === b[i])\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","p5bezierAccuracyListAll","_canvas","_ctx","_dimension","_strict","_useP5","_beginPath","_moveTo","_lineTo","_closePath","initBezier","canvas","strictMode","drawingContext","p5","Graphics","constructor","name","beginShape","vertex","endShape","Renderer","Error","window","console","warn","isP3D","beginPath","bind","moveTo","lineTo","closePath","newBezier","pointList","closeType","accuracy","Array","isArray","tIncrement","point","length","push","n","x","y","t","i","_helper_factorial","Math","pow","slice","d","xyz","_helper_style","newBezierObj","BezierCurve","a","_helper_dist","arguments","hypot","_doFill","fill","_doStroke","stroke","pL","closeT","tI","bD","vL","controlPoints","dimension","increment","vertexList","vertexListLen","p","_buildVertexList","_addVertex","vArray","_distVertex","vArray1","vArray2","draw","dash","solidPart","abs","onePart","nowLen","modOnePart","lastVertex","solid","save","fillStyle","v","restore","update","newControlList","equalArrays","move","z","toDraw","toMove","newCurveV","newCurveObj","j","shortest","pX","pY","pZ","minVertex","dMin","nowMin","b","every"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "p5bezier",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Bezier library for canvas-based graphics on the web, built to work with p5.js.",
|
|
5
5
|
"main": "lib/p5.bezier.min.js",
|
|
6
6
|
"keywords": [
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/peilingjiang/p5.bezier#readme",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"eslint": "^8.
|
|
23
|
-
"husky": "^8.0.
|
|
24
|
-
"lint-staged": "^13.0
|
|
25
|
-
"prettier": "^2.
|
|
26
|
-
"terser-webpack-plugin": "^5.3.
|
|
27
|
-
"webpack": "^5.
|
|
28
|
-
"webpack-cli": "^
|
|
22
|
+
"eslint": "^8.33.0",
|
|
23
|
+
"husky": "^8.0.3",
|
|
24
|
+
"lint-staged": "^13.1.0",
|
|
25
|
+
"prettier": "^2.8.3",
|
|
26
|
+
"terser-webpack-plugin": "^5.3.6",
|
|
27
|
+
"webpack": "^5.75.0",
|
|
28
|
+
"webpack-cli": "^5.0.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"format": "prettier --write \"**/*.{js,json,md,html,css}\"",
|