Socket
Socket
Sign inDemoInstall

cubic2quad

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cubic2quad

Approximate cubic Bezier curve with a number of quadratic ones


Version published
Weekly downloads
204K
decreased by-6.65%
Maintainers
1
Install size
21.9 kB
Created
Weekly downloads
 

Readme

Source

cubic2quad

CI NPM version Coverage Status

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:

  1. Split quadratic curve into k segments (from 2 at start, to 8 max).
  2. Approximate each segment with tangents intersection approach (see picture in article).
  3. 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.

Authors

License

MIT

Keywords

FAQs

Last updated on 20 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc