Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field declarations for all core classes #5033

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 23 additions & 26 deletions src/core/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,40 @@

/**
* Abstract base class that implements functionality for event handling.
*
* ```javascript
* var obj = new EventHandlerSubclass();
*
* // subscribe to an event
* obj.on('hello', function (str) {
* console.log('event hello is fired', str);
* });
*
* // fire event
* obj.fire('hello', 'world');
* ```
*/
class EventHandler {
/**
* Create a new EventHandler instance.
*
* @example
* var obj = new EventHandlerSubclass();
*
* // subscribe to an event
* obj.on('hello', function (str) {
* console.log('event hello is fired', str);
* });
*
* // fire event
* obj.fire('hello', 'world');
* @type {object}
* @private
*/
constructor() {
/**
* @type {object}
* @private
*/
this._callbacks = { };
/**
* @type {object}
* @private
*/
this._callbackActive = { };
}
_callbacks = {};

/**
* @type {object}
* @private
*/
_callbackActive = {};

/**
* Reinitialize the event handler.
*
* @private
*/
initEventHandler() {
this._callbacks = { };
this._callbackActive = { };
this._callbacks = {};
this._callbackActive = {};
}

/**
Expand Down
48 changes: 28 additions & 20 deletions src/core/math/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ import { math } from './math.js';
* Representation of an RGBA color.
*/
class Color {
/**
* The red component of the color.
*
* @type {number}
*/
r;

/**
* The green component of the color.
*
* @type {number}
*/
g;

/**
* The blue component of the color.
*
* @type {number}
*/
b;

/**
* The alpha component of the color.
*
* @type {number}
*/
a;

/**
* Create a new Color object.
*
Expand All @@ -16,29 +44,9 @@ class Color {
constructor(r = 0, g = 0, b = 0, a = 1) {
const length = r.length;
if (length === 3 || length === 4) {
/**
* The red component of the color.
*
* @type {number}
*/
this.r = r[0];
/**
* The green component of the color.
*
* @type {number}
*/
this.g = r[1];
/**
* The blue component of the color.
*
* @type {number}
*/
this.b = r[2];
/**
* The alpha component of the color.
*
* @type {number}
*/
this.a = r[3] !== undefined ? r[3] : 1;
} else {
this.r = r;
Expand Down
31 changes: 24 additions & 7 deletions src/core/math/curve-evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import { math } from './math.js';
* @ignore
*/
class CurveEvaluator {
/** @private */
_curve;

/** @private */
_left = -Infinity;

/** @private */
_right = Infinity;

/** @private */
_recip = 0;

/** @private */
_p0 = 0;

/** @private */
_p1 = 0;

/** @private */
_m0 = 0;

/** @private */
_m1 = 0;

/**
* Create a new CurveEvaluator instance.
*
Expand All @@ -15,13 +39,6 @@ class CurveEvaluator {
*/
constructor(curve, time = 0) {
this._curve = curve;
this._left = -Infinity;
this._right = Infinity;
this._recip = 0;
this._p0 = 0;
this._p1 = 0;
this._m0 = 0;
this._m1 = 0;
this._reset(time);
}

Expand Down
16 changes: 8 additions & 8 deletions src/core/math/curve-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { CurveEvaluator } from './curve-evaluator.js';
* A curve set is a collection of curves.
*/
class CurveSet {
curves = [];

/**
* @type {number}
* @private
*/
_type = CURVE_SMOOTHSTEP;

/**
* Creates a new CurveSet instance.
*
Expand All @@ -28,14 +36,6 @@ class CurveSet {
* ]);
*/
constructor() {
this.curves = [];

/**
* @type {number}
* @private
*/
this._type = CURVE_SMOOTHSTEP;

if (arguments.length > 1) {
for (let i = 0; i < arguments.length; i++) {
this.curves.push(new Curve(arguments[i]));
Expand Down
62 changes: 31 additions & 31 deletions src/core/math/curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@ import { CurveEvaluator } from './curve-evaluator.js';
* type that specifies an interpolation scheme for the keys.
*/
class Curve {
keys = [];

/**
* The curve interpolation scheme. Can be:
*
* - {@link CURVE_LINEAR}
* - {@link CURVE_SMOOTHSTEP}
* - {@link CURVE_SPLINE}
* - {@link CURVE_STEP}
*
* Defaults to {@link CURVE_SMOOTHSTEP}.
*
* @type {number}
*/
type = CURVE_SMOOTHSTEP;

/**
* Controls how {@link CURVE_SPLINE} tangents are calculated. Valid range is between 0 and 1
* where 0 results in a non-smooth curve (equivalent to linear interpolation) and 1 results in
* a very smooth curve. Use 0.5 for a Catmull-rom spline.
*
* @type {number}
*/
tension = 0.5;

/**
* @type {CurveEvaluator}
* @private
*/
_eval = new CurveEvaluator(this);

/**
* Creates a new Curve instance.
*
Expand All @@ -22,37 +53,6 @@ class Curve {
* ]);
*/
constructor(data) {
this.keys = [];

/**
* The curve interpolation scheme. Can be:
*
* - {@link CURVE_LINEAR}
* - {@link CURVE_SMOOTHSTEP}
* - {@link CURVE_SPLINE}
* - {@link CURVE_STEP}
*
* Defaults to {@link CURVE_SMOOTHSTEP}.
*
* @type {number}
*/
this.type = CURVE_SMOOTHSTEP;

/**
* Controls how {@link CURVE_SPLINE} tangents are calculated. Valid range is between 0 and
* 1 where 0 results in a non-smooth curve (equivalent to linear interpolation) and 1
* results in a very smooth curve. Use 0.5 for a Catmull-rom spline.
*
* @type {number}
*/
this.tension = 0.5;

/**
* @type {CurveEvaluator}
* @private
*/
this._eval = new CurveEvaluator(this);

if (data) {
for (let i = 0; i < data.length - 1; i += 2) {
this.keys.push([data[i], data[i + 1]]);
Expand Down
17 changes: 8 additions & 9 deletions src/core/math/mat3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import { Vec3 } from './vec3.js';
* A 3x3 matrix.
*/
class Mat3 {
/**
* Matrix elements in the form of a flat array.
*
* @type {Float32Array}
*/
data = new Float32Array(9);

/**
* Create a new Mat3 instance. It is initialized to the identity matrix.
*/
constructor() {
// Create an identity matrix. Note that a new Float32Array has all elements set
// to zero by default, so we only need to set the relevant elements to one.
const data = new Float32Array(9);
data[0] = data[4] = data[8] = 1;

/**
* Matrix elements in the form of a flat array.
*
* @type {Float32Array}
*/
this.data = data;
this.data[0] = this.data[4] = this.data[8] = 1;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/core/math/mat4.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ const scale = new Vec3();
* A 4x4 matrix.
*/
class Mat4 {
/**
* Matrix elements in the form of a flat array.
*
* @type {Float32Array}
*/
data = new Float32Array(16);

/**
* Create a new Mat4 instance. It is initialized to the identity matrix.
*/
constructor() {
// Create an identity matrix. Note that a new Float32Array has all elements set
// to zero by default, so we only need to set the relevant elements to one.
const data = new Float32Array(16);
data[0] = data[5] = data[10] = data[15] = 1;

/**
* Matrix elements in the form of a flat array.
*
* @type {Float32Array}
*/
this.data = data;
this.data[0] = this.data[5] = this.data[10] = this.data[15] = 1;
}

// Static function which evaluates perspective projection matrix half size at the near plane
Expand Down