Skip to content

Commit 06334ff

Browse files
committed
feat: VectorN can be constructed from Float32Array, add Z arg for Matrix4.fromNonuniformScale
1 parent d9cfdc3 commit 06334ff

File tree

8 files changed

+43
-28
lines changed

8 files changed

+43
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "gmath"
33
license = "MIT"
44
version = "0.1.0"
55
authors = ["Elias Sjögreen"]
6-
edition = "2018"
6+
edition = "2021"
77

88
[lib]
99
crate-type = ["cdylib"]

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
max_width = 80
22
tab_spaces = 2
3-
edition = "2018"
3+
edition = "2021"

scripts/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encode } from "https://deno.land/std@0.97.0/encoding/base64.ts";
1+
import { encode } from "https://deno.land/std@0.125.0/encoding/base64.ts";
22
import { compress } from "https://deno.land/x/lz4@v0.1.2/mod.ts";
33

44
const name = "gmath";
@@ -12,7 +12,7 @@ const wasm = await Deno.readFile(
1212
);
1313
const encoded = encode(compress(wasm));
1414
const js = `// deno-fmt-ignore-file\n// deno-lint-ignore-file
15-
import { decode } from "https://deno.land/std@0.97.0/encoding/base64.ts";
15+
import { decode } from "https://deno.land/std@0.125.0/encoding/base64.ts";
1616
import { decompress } from "https://deno.land/x/lz4@v0.1.2/mod.ts";
1717
export const source = decompress(decode("${encoded}"));`;
1818

src/matrix4.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ export class Matrix4 {
248248
}
249249

250250
static fromScale(scale: number): Matrix4 {
251-
return this.fromNonuniformScale(scale, scale);
251+
return this.fromNonuniformScale(scale, scale, scale);
252252
}
253253

254-
static fromNonuniformScale(x: number, y: number): Matrix4 {
254+
static fromNonuniformScale(x: number, y: number, z: number): Matrix4 {
255255
// deno-fmt-ignore
256256
return Matrix4.from(
257257
x, 0, 0, 0,
258258
0, y, 0, 0,
259-
0, 0, 1, 0,
259+
0, 0, z, 0,
260260
0, 0, 0, 1,
261261
);
262262
}

src/vector2.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ export class Vector2 implements Point2 {
8585
constructor();
8686
constructor(x: number);
8787
constructor(x: number, y: number);
88-
constructor(x?: number, y?: number) {
88+
constructor(source: Float32Array);
89+
constructor(x?: number | Float32Array, y?: number) {
8990
if (x !== undefined) {
90-
this.x = x;
91-
92-
if (y !== undefined) {
93-
this.y = y;
91+
if (typeof x === "number") {
92+
this.x = x;
93+
94+
if (y !== undefined) {
95+
this.y = y;
96+
} else {
97+
this.y = x;
98+
}
9499
} else {
95-
this.y = x;
100+
this.#internal = x;
96101
}
97102
}
98103
}

src/vector3.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,21 @@ export class Vector3 implements Point3 {
115115
constructor();
116116
constructor(x: number);
117117
constructor(x: number, y: number, z: number);
118-
constructor(x?: number, y?: number, z?: number) {
118+
constructor(source: Float32Array);
119+
constructor(x?: number | Float32Array, y?: number, z?: number) {
119120
if (x !== undefined) {
120-
this.x = x;
121-
122-
if (y !== undefined && z !== undefined) {
123-
this.y = y;
124-
this.z = z;
121+
if (typeof x === "number") {
122+
this.x = x;
123+
124+
if (y !== undefined && z !== undefined) {
125+
this.y = y;
126+
this.z = z;
127+
} else {
128+
this.y = x;
129+
this.z = x;
130+
}
125131
} else {
126-
this.y = x;
127-
this.z = x;
132+
this.#internal = x;
128133
}
129134
}
130135
}

src/vector4.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ export class Vector4 implements Point4 {
9797
constructor();
9898
constructor(x: number);
9999
constructor(x: number, y: number, z: number, w: number);
100-
constructor(x?: number, y?: number, z?: number, w?: number) {
100+
constructor(source: Float32Array);
101+
constructor(x?: number | Float32Array, y?: number, z?: number, w?: number) {
101102
if (x !== undefined) {
102-
this.x = x;
103-
this.y = y ?? x;
104-
this.z = z ?? x;
105-
this.w = w ?? x;
103+
if (typeof x === "number") {
104+
this.x = x;
105+
this.y = y ?? x;
106+
this.z = z ?? x;
107+
this.w = w ?? x;
108+
} else {
109+
this.#internal = x;
110+
}
106111
}
107112
}
108113

wasm/wasm.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)