How to use cubic2quad - 1 common examples

To help you get started, we’ve selected a few cubic2quad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github foliojs / textkit / packages / core / src / geom / Path.js View on Github external
bezierToQuadratic() {
    if (!this._bezier) {
      return this;
    }

    const path = new Path();
    let x = 0;
    let y = 0;

    for (const c of this.commands) {
      if (c.command === 'bezierCurveTo') {
        const quads = cubic2quad(x, y, ...c.args, 0.1);

        for (let i = 2; i < quads.length; i += 4) {
          path.quadraticCurveTo(quads[i], quads[i + 1], quads[i + 2], quads[i + 3]);
        }
      } else {
        path[c.command](...c.args);
        x = c.args[c.args.length - 2] || 0;
        y = c.args[c.args.length - 1] || 0;
      }
    }

    return path;
  }

cubic2quad

Approximate cubic Bezier curve with a number of quadratic ones

MIT
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis

Popular cubic2quad functions