javascript(ultra32): added basic functions
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
5b7701af95
commit
edd15321fa
|
@ -1,2 +1,25 @@
|
|||
# ultra32
|
||||
# Ultra32
|
||||
A vector package using the fast float32array
|
||||
|
||||
|
||||
# Get started:
|
||||
|
||||
To get started, install ultra32:
|
||||
```
|
||||
npm install ultra32 --save
|
||||
```
|
||||
|
||||
A ultra32 vector is just a Float32Array.
|
||||
|
||||
```
|
||||
const vec = new Float32Array([0,0]);
|
||||
```
|
||||
|
||||
You can perform multiple operations:
|
||||
```
|
||||
add(vec,new Float32Array([1,2]));
|
||||
mul(vec,3);
|
||||
mirror(vec);
|
||||
|
||||
console.log(vec); //Float32Array [ -3, -6 ]
|
||||
```
|
||||
|
|
37
javascript/ultra32/app.js
Normal file
37
javascript/ultra32/app.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function add(vector, other) {
|
||||
for (let i = 0; i < vector.length; i++) {
|
||||
vector[i] = vector[i] + other[i];
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
exports.add = add;
|
||||
function sub(vector, other) {
|
||||
for (let i = 0; i < vector.length; i++) {
|
||||
vector[i] = vector[i] - other[i];
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
exports.sub = sub;
|
||||
function div(vector, scalar) {
|
||||
for (let i = 0; i < vector.length; i++) {
|
||||
vector[i] /= scalar;
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
exports.div = div;
|
||||
function mul(vector, scalar) {
|
||||
for (let i = 0; i < vector.length; i++) {
|
||||
vector[i] *= scalar;
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
exports.mul = mul;
|
||||
function mirror(vector) {
|
||||
for (let i = 0; i < vector.length; i++) {
|
||||
vector[i] = -vector[i];
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
exports.mirror = mirror;
|
5
javascript/ultra32/package-lock.json
generated
Normal file
5
javascript/ultra32/package-lock.json
generated
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "ultra32",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1
|
||||
}
|
22
javascript/ultra32/package.json
Normal file
22
javascript/ultra32/package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "ultra32",
|
||||
"version": "1.0.0",
|
||||
"description": "A vector package using the fast float32array",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/Mateiadrielrafael/ultra32"
|
||||
},
|
||||
"keywords": [
|
||||
"vector",
|
||||
"float32array",
|
||||
"webgl"
|
||||
],
|
||||
"author": "Matei Adriel",
|
||||
"license": "ISC",
|
||||
"dependencies": {},
|
||||
"devDependencies": {}
|
||||
}
|
Loading…
Reference in a new issue