{"_id":"@bunny-editor/smooth-fit-curve","name":"@bunny-editor/smooth-fit-curve","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bunny-editor/smooth-fit-curve","version":"1.0.0","description":"Fit cubic Bezier curves to freehand points using Schneider's algorithm","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc"},"keywords":["bezier","curve-fitting","freehand","drawing","svg","pen-tool","schneider","typescript"],"author":{"name":"Pritam"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Bunny-Editor/smooth-fit-curve.git"},"devDependencies":{"typescript":"^5.5.0"},"_id":"@bunny-editor/smooth-fit-curve@1.0.0","bugs":{"url":"https://github.com/Bunny-Editor/smooth-fit-curve/issues"},"homepage":"https://github.com/Bunny-Editor/smooth-fit-curve#readme","_nodeVersion":"22.20.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-tJPYJcFFfs2JyNBpyDiaq4cQooun8UkFCxbhU5hhrjk9VH5786VA36W/mc5YCykgZ9IjKzv0SEmnYeo0sqUwwQ==","shasum":"7e764c69a8e68df15211e9eb53e79b834d8012f4","tarball":"https://registry.npmjs.org/@bunny-editor/smooth-fit-curve/-/smooth-fit-curve-1.0.0.tgz","fileCount":6,"unpackedSize":17613,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCID+Y/2A/QZyJKEERlx9inJ/VvDZiBKFheqgsywi+NpajAiAh9ZGmnALnTuaYePjzjADrFjSgqT4N/wiYZBMIeijaJg=="}]},"_npmUser":{"name":"theonepritam","email":"theonepritam@gmail.com"},"directories":{},"maintainers":[{"name":"theonepritam","email":"theonepritam@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/smooth-fit-curve_1.0.0_1775071706456_0.6337636547872323"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-01T19:28:26.350Z","1.0.0":"2026-04-01T19:28:26.600Z","modified":"2026-04-01T19:28:26.802Z"},"maintainers":[{"name":"theonepritam","email":"theonepritam@gmail.com"}],"description":"Fit cubic Bezier curves to freehand points using Schneider's algorithm","homepage":"https://github.com/Bunny-Editor/smooth-fit-curve#readme","keywords":["bezier","curve-fitting","freehand","drawing","svg","pen-tool","schneider","typescript"],"repository":{"type":"git","url":"git+https://github.com/Bunny-Editor/smooth-fit-curve.git"},"author":{"name":"Pritam"},"bugs":{"url":"https://github.com/Bunny-Editor/smooth-fit-curve/issues"},"license":"MIT","readme":"# @bunny-editor/smooth-fit-curve\r\n\r\nTurn freehand drawn points into smooth cubic Bezier curves.\r\n\r\nThe kind of thing you need when building a pen/pencil tool. Based on Schneider's curve fitting from Graphics Gems (1990). No dependencies.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @bunny-editor/smooth-fit-curve\r\n```\r\n\r\n## Basic usage\r\n\r\n```ts\r\nimport { fitCurve } from '@bunny-editor/smooth-fit-curve';\r\n\r\n// raw points from mouse/pen input\r\nconst points: [number, number][] = [\r\n  [0, 0], [10, 5], [20, 20], [30, 15], [40, 30],\r\n  [50, 25], [60, 40], [70, 35], [80, 50],\r\n];\r\n\r\n// lower maxError = more accurate, higher = smoother\r\nconst curves = fitCurve(points, 4);\r\n\r\n// each curve: [startPoint, controlPoint1, controlPoint2, endPoint]\r\n```\r\n\r\n## Get an SVG path\r\n\r\n```ts\r\nimport { fitCurve, bezierCurvesToSvgPath } from '@bunny-editor/smooth-fit-curve';\r\n\r\nconst d = bezierCurvesToSvgPath(fitCurve(points, 4));\r\n// \"M 0 0 C 5.2 1.3, 9.8 4.1, 10 5 C ...\"\r\n```\r\n\r\n## Normalize for element positioning\r\n\r\nShifts the path to start near (0,0) and gives you the offset + bounding box — handy when you're storing it as a canvas element:\r\n\r\n```ts\r\nimport { fitCurve, normalizeFittedCurves } from '@bunny-editor/smooth-fit-curve';\r\n\r\nconst { path, offsetX, offsetY, width, height } = normalizeFittedCurves(fitCurve(points, 4));\r\n```\r\n\r\n## Smoothing slider\r\n\r\nIf you want to expose a 1–100 slider to your users:\r\n\r\n```ts\r\nimport { smoothingToError, fitCurve } from '@bunny-editor/smooth-fit-curve';\r\n\r\nconst maxError = smoothingToError(50); // ~8\r\nconst curves = fitCurve(points, maxError);\r\n```\r\n\r\n1 = keeps all the wobbles, 50 = balanced, 100 = very smooth with few curves.\r\n\r\n## API\r\n\r\n| Function | What it does |\r\n|----------|-------------|\r\n| `fitCurve(points, maxError)` | Fit bezier curves to `[x,y][]` points. Returns `BezierCurve[]`. |\r\n| `bezierCurvesToSvgPath(curves)` | Convert to SVG path `d` string. |\r\n| `bezierCurvesBounds(curves)` | Bounding box: `{ minX, minY, maxX, maxY, width, height }`. |\r\n| `normalizeFittedCurves(curves)` | Shift to origin + get offset/dimensions. |\r\n| `smoothingToError(1–100)` | Map slider value to `maxError`. |\r\n\r\n`BezierCurve` is `[[x,y], [x,y], [x,y], [x,y]]` — start, cp1, cp2, end.\r\n\r\n## How it works\r\n\r\nTakes your raw points, assigns parameter values based on distance along the polyline (chord-length parameterization), then finds the best-fit cubic Bezier using least-squares. If the fit isn't good enough, it refines the parameters with Newton-Raphson iteration. If it's still off, it splits at the worst point and fits both halves recursively.\r\n\r\nThe result is the minimum number of cubic Bezier segments needed to approximate your freehand stroke within the given error tolerance.\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md","_rev":"1-b02da77c6389a688f275002120974769"}