raylib-wasm-transpiler/tools/js-class-c-struct-transpiler/test/build/Vector3.js

67 lines
1.6 KiB
JavaScript

/**
* @typedef {Object} Vector3 A representation of a position in 3D space
* @property {Float32} f32 x coordinate
* @property {Float32} f32 y coordinate
* @property {Float32} f32 z coordinate
*/
class Vector3 {
/**
* x coordinate
* @return {Float32} gets the value of x
*/
get x() {
return this._data.getFloat32(0, true);
}
/**
* x coordinate
* @param {Float32} sets the value of x
*/
set x(v) {
return this._data.setFloat32(0, v, true);
}
/**
* y coordinate
* @return {Float32} gets the value of y
*/
get y() {
return this._data.getFloat32(4, true);
}
/**
* y coordinate
* @param {Float32} sets the value of y
*/
set y(v) {
return this._data.setFloat32(4, v, true);
}
/**
* z coordinate
* @return {Float32} gets the value of z
*/
get z() {
return this._data.getFloat32(8, true);
}
/**
* z coordinate
* @param {Float32} sets the value of z
*/
set z(v) {
return this._data.setFloat32(8, v, true);
}
/**
* Constructs a new Vector3
*
* @param {{x: Float32, y: Float32, z: Float32, }} init The arguments to construct the object.
* @param {Uint8Array} ptr The pointer to the C struct.
*/
constructor(init = {}, ptr = undefined) {
this._size = 12;
this._ptr = ptr || new Uint8Array(this._size);
this._data = new DataView(this._ptr.buffer);
for (const key of Object.keys(init)) {
this[key] = init[key];
}
}
}
export default Vector3