@openhps/core
Version:
Open Hybrid Positioning System - Core component
95 lines (89 loc) • 2.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.QuadraticBezierCurve3 = void 0;
var _Curve = require("../core/Curve.js");
var _Interpolations = require("../core/Interpolations.js");
var _Vector = require("../../math/Vector3.js");
/**
* A curve representing a 3D Quadratic Bezier curve.
*
* @augments Curve
*/
class QuadraticBezierCurve3 extends _Curve.Curve {
/**
* Constructs a new Quadratic Bezier curve.
*
* @param {Vector3} [v0] - The start point.
* @param {Vector3} [v1] - The control point.
* @param {Vector3} [v2] - The end point.
*/
constructor(v0 = new _Vector.Vector3(), v1 = new _Vector.Vector3(), v2 = new _Vector.Vector3()) {
super();
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isQuadraticBezierCurve3 = true;
this.type = 'QuadraticBezierCurve3';
/**
* The start point.
*
* @type {Vector3}
*/
this.v0 = v0;
/**
* The control point.
*
* @type {Vector3}
*/
this.v1 = v1;
/**
* The end point.
*
* @type {Vector3}
*/
this.v2 = v2;
}
/**
* Returns a point on the curve.
*
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
* @param {Vector3} [optionalTarget] - The optional target vector the result is written to.
* @return {Vector3} The position on the curve.
*/
getPoint(t, optionalTarget = new _Vector.Vector3()) {
const point = optionalTarget;
const v0 = this.v0,
v1 = this.v1,
v2 = this.v2;
point.set((0, _Interpolations.QuadraticBezier)(t, v0.x, v1.x, v2.x), (0, _Interpolations.QuadraticBezier)(t, v0.y, v1.y, v2.y), (0, _Interpolations.QuadraticBezier)(t, v0.z, v1.z, v2.z));
return point;
}
copy(source) {
super.copy(source);
this.v0.copy(source.v0);
this.v1.copy(source.v1);
this.v2.copy(source.v2);
return this;
}
toJSON() {
const data = super.toJSON();
data.v0 = this.v0.toArray();
data.v1 = this.v1.toArray();
data.v2 = this.v2.toArray();
return data;
}
fromJSON(json) {
super.fromJSON(json);
this.v0.fromArray(json.v0);
this.v1.fromArray(json.v1);
this.v2.fromArray(json.v2);
return this;
}
}
exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;