Package Exports
- cubic2quad
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cubic2quad) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cubic2quad
Aproximates cubic Bezier curves with quadratic ones.
This package was done to create TTF fonts (those support quadratic curves only). Generated curves have the same tangents angles at the ends. That's important to keep result visually smooth.
Algorithm
Logic is similar to one from FontForge.
Steps:
- Split quadratic curve into k segments (from 2 at start, to 8 max).
- Approximate each segment with tangents intersection approach (see picture in article).
- Measure approximation error and increase splits count if needed (and max not reached).
- set 10 points on each interval & calculate minimal distance to created quadratic curve.
Usage
var cubic2quad = require('cubic2quad');
// Input: (px1, py1, cx1, cy1, cx2, cy2, px2, py2, precision)
var quads = cubic2quad(0, 0, 10, 9, 20, 11, 30, 0, 0.1);
It converts given quadratic curve to a number of quadratic ones. Result is:
[ P1x, P1y, C1x, C1y, P2x, P2y, C2x, C2y, ..., Cnx, Cny, P{n+1}x, P{n+1}y ]
where Pi are base points and Ci are control points.