Coder Social home page Coder Social logo

cubic2quad's Introduction

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

cubic2quad's People

Contributors

be5invis avatar rlidwka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.