toosoon-utils
Version:
Utility functions & classes
64 lines (63 loc) • 1.67 kB
JavaScript
import { quadraticBezier } from '../../geometry';
import Curve from './Curve';
/**
* Utility class for manipulating Quadratic Bézier curves
*
* @exports
* @class QuadraticBezierCurve
* @extends Curve
*/
export default class QuadraticBezierCurve extends Curve {
type = 'QuadraticBezierCurve';
/**
* X-axis coordinate of the start point
*/
x1;
/**
* Y-axis coordinate of the start point
*/
y1;
/**
* X-axis coordinate of the control point
*/
cpx;
/**
* Y-axis coordinate of the control point
*/
cpy;
/**
* X-axis coordinate of the end point
*/
x2;
/**
* Y-axis coordinate of the end point
*/
y2;
/**
* @param {number} x1 X-axis coordinate of the start point
* @param {number} y1 Y-axis coordinate of the start point
* @param {number} cpx X-axis coordinate of the control point
* @param {number} cpy Y-axis coordinate of the control point
* @param {number} x2 X-axis coordinate of the end point
* @param {number} y2 Y-axis coordinate of the end point
*/
constructor(x1, y1, cpx, cpy, x2, y2) {
super();
this.x1 = x1;
this.y1 = y1;
this.cpx = cpx;
this.cpy = cpy;
this.x2 = x2;
this.y2 = y2;
}
/**
* Interpolate a point on the Quadratic Bézier curve
*
* @param {number} t Normalized time value to interpolate
* @returns {Point} Interpolated coordinates on the curve
*/
getPoint(t) {
const point = quadraticBezier(t, this.x1, this.y1, this.cpx, this.cpy, this.x2, this.y2);
return point;
}
}