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

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-06-12 23:05:45 -04:00
/**
* @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
2024-06-12 23:05:45 -04:00
* @return {Float32} gets the value of x
*/
get x() {
return this._data.getFloat32(0, true);
}
2024-06-12 23:05:45 -04:00
/**
* x coordinate
* @param {Float32} sets the value of x
*/
set x(v) {
return this._data.setFloat32(0, v, true);
}
/**
* y coordinate
2024-06-12 23:05:45 -04:00
* @return {Float32} gets the value of y
*/
get y() {
return this._data.getFloat32(4, true);
}
2024-06-12 23:05:45 -04:00
/**
* y coordinate
* @param {Float32} sets the value of y
*/
set y(v) {
return this._data.setFloat32(4, v, true);
}
/**
* z coordinate
2024-06-12 23:05:45 -04:00
* @return {Float32} gets the value of z
*/
get z() {
return this._data.getFloat32(8, true);
}
2024-06-12 23:05:45 -04:00
/**
* z coordinate
* @param {Float32} sets the value of z
*/
set z(v) {
return this._data.setFloat32(8, v, true);
}
/**
2024-06-12 23:05:45 -04:00
* Get the struct representation of the object
* @return {Uint8Array} u8 array of the C struct.
*/
get bytes() {
return new Uint8Array(this._ptr);
}
/**
2024-06-12 23:05:45 -04:00
* Constructs a new Vector3
*
* @param {{x: Float32, y: Float32, z: Float32, }} init The arguments to construct the object.
* @param {ArrayBuffer} ptr The pointer to the C struct.
*/
constructor(init = {}, ptr = undefined) {
this._size = 12;
2024-06-12 23:05:45 -04:00
this._ptr = ptr?.buffer || new ArrayBuffer(this._size);
this._data = new DataView(this._ptr);
for (const key of Object.keys(init)) {
this[key] = init[key];
}
}
}
export default Vector3