Skip to content

Commit

Permalink
Add vitest library and port over applicable tests from gl-matrix next…
Browse files Browse the repository at this point in the history
…. See FIXME on Quat.toMatrix4.
  • Loading branch information
brcolow committed Dec 28, 2024
1 parent a012893 commit 62a1b2a
Show file tree
Hide file tree
Showing 7 changed files with 3,082 additions and 15 deletions.
67 changes: 54 additions & 13 deletions math.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class Vector3 extends Float32Array {
}
}

static create() {
return new Vector3()
}

equals(b) {
return Vector3.equals(this, this, b)
}
Expand Down Expand Up @@ -173,6 +177,21 @@ class Mat4 extends Float32Array {
case 16:
super(values)
break
case 2:
super(values[0], values[1], 16)
break
case 1:
const v = values[0]
if (typeof v === 'number') {
super([
v, v, v, v,
v, v, v, v,
v, v, v, v,
v, v, v, v])
} else {
super(v, 0, 16)
}
break
default:
super(IDENTITY_4X4)
break
Expand All @@ -191,18 +210,24 @@ class Mat4 extends Float32Array {
static scale(out, a, v) {
const x = v[0]
const y = v[1]
const z = v[2]

out[0] = x * a[0]
out[1] = x * a[1]
out[2] = x * a[2]

out[3] = y * a[3]
out[4] = y * a[4]
out[5] = y * a[5]

out[6] = a[6]
out[7] = a[7]
out[8] = a[8]
out[0] = a[0] * x
out[1] = a[1] * x
out[2] = a[2] * x
out[3] = a[3] * x
out[4] = a[4] * y
out[5] = a[5] * y
out[6] = a[6] * y
out[7] = a[7] * y
out[8] = a[8] * z
out[9] = a[9] * z
out[10] = a[10] * z
out[11] = a[11] * z
out[12] = a[12]
out[13] = a[13]
out[14] = a[14]
out[15] = a[15]
return out
}

Expand Down Expand Up @@ -564,8 +589,23 @@ class Quat extends Float32Array {
return new Quat()
}

static identity() {
return new Quat(1, 0, 0, 0)
static identity(out) {
if (out === undefined) {
return new Quat(0, 0, 0, 1)
}
out[0] = 0
out[1] = 0
out[2] = 0
out[3] = 1
return out
}

identity() {
this[0] = 0
this[1] = 0
this[2] = 0
this[3] = 1
return this
}

multiply(b) {
Expand Down Expand Up @@ -595,6 +635,7 @@ class Quat extends Float32Array {
out[1] = a[1] * il
out[2] = a[2] * il
out[3] = a[3] * il
return out
}

toMatrix4() {
Expand Down
Loading

0 comments on commit 62a1b2a

Please sign in to comment.