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

67 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-06-12 23:05:45 -04:00
/**
* @typedef {Object} Vector3 A representation of a position in 3D space
2024-06-13 01:08:44 -04:00
* @property {Float32} f32 x coordinate
* @property {Float32} f32 y coordinate
* @property {Float32} f32 z coordinate
2024-06-12 23:05:45 -04:00
*/
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
* Constructs a new Vector3
*
* @param {{x: Float32, y: Float32, z: Float32, }} init The arguments to construct the object.
2024-06-13 01:08:44 -04:00
* @param {Uint8Array} ptr The pointer to the C struct.
*/
constructor(init = {}, ptr = undefined) {
this._size = 12;
2024-06-13 01:08:44 -04:00
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