From 5dd2e38affc90b075a19777b044f98489235f24a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 12 Feb 2024 11:54:24 +0000 Subject: [PATCH] Change minor/adjoint to be `row, col` from `c, r` to be consistent with `[row, col]` syntax; Add `#no_bounds_check` were appropriate --- core/math/linalg/general.odin | 38 ++-- core/math/linalg/specific.odin | 306 ++++++++++++++++----------------- 2 files changed, 172 insertions(+), 172 deletions(-) diff --git a/core/math/linalg/general.odin b/core/math/linalg/general.odin index 4275dcb42..9d9309f12 100644 --- a/core/math/linalg/general.odin +++ b/core/math/linalg/general.odin @@ -296,7 +296,7 @@ angle_between :: proc{ // Splines @(require_results) -vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T { +vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T #no_bounds_check { cos_alpha := dot(x, y) alpha := math.acos(cos_alpha) sin_alpha := math.sin(alpha) @@ -308,7 +308,7 @@ vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T { } @(require_results) -catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T { +catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T #no_bounds_check { s2 := s*s s3 := s2*s @@ -321,7 +321,7 @@ catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T { } @(require_results) -hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T { +hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T #no_bounds_check { s2 := s*s s3 := s2*s @@ -334,7 +334,7 @@ hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T { } @(require_results) -cubic :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T { +cubic :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T #no_bounds_check { return ((v1 * s + v2) * s + v3) * s + v4 } @@ -415,12 +415,12 @@ inverse :: proc{ } @(require_results) -hermitian_adjoint :: proc "contextless" (m: $M/matrix[$N, N]$T) -> M where intrinsics.type_is_complex(T), N >= 1 { +hermitian_adjoint :: proc "contextless" (m: $M/matrix[$N, N]$T) -> M where intrinsics.type_is_complex(T), N >= 1 #no_bounds_check { return conj(transpose(m)) } @(require_results) -trace :: proc "contextless" (m: $M/matrix[$N, N]$T) -> (trace: T) { +trace :: proc "contextless" (m: $M/matrix[$N, N]$T) -> (trace: T) #no_bounds_check { for i in 0.. (trace: T) { } @(require_results) -matrix_minor :: proc "contextless" (m: $M/matrix[$N, N]$T, #any_int row, column: int) -> (minor: T) where N > 1 { +matrix_minor :: proc "contextless" (m: $M/matrix[$N, N]$T, #any_int row, column: int) -> (minor: T) where N > 1 #no_bounds_check { K :: int(N-1) cut_down: matrix[K, K]T for col_idx in 0.. (det: T) { +matrix1x1_determinant :: proc "contextless" (m: $M/matrix[1, 1]$T) -> (det: T) #no_bounds_check { return m[0, 0] } @(require_results) -matrix2x2_determinant :: proc "contextless" (m: $M/matrix[2, 2]$T) -> (det: T) { +matrix2x2_determinant :: proc "contextless" (m: $M/matrix[2, 2]$T) -> (det: T) #no_bounds_check { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } @(require_results) -matrix3x3_determinant :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (det: T) { +matrix3x3_determinant :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (det: T) #no_bounds_check { a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1]) b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0]) c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0]) return a + b + c } @(require_results) -matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) { +matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) #no_bounds_check { a := adjugate(m) #no_bounds_check for i in 0..<4 { det += m[0, i] * a[0, i] @@ -472,13 +472,13 @@ matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) { @(require_results) -matrix1x1_adjugate :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) { +matrix1x1_adjugate :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check { y = x return } @(require_results) -matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) { +matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check { y[0, 0] = +x[1, 1] y[0, 1] = -x[1, 0] y[1, 0] = -x[0, 1] @@ -487,7 +487,7 @@ matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) { } @(require_results) -matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) { +matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) #no_bounds_check { y[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2]) y[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2]) y[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1]) @@ -502,7 +502,7 @@ matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) { @(require_results) -matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) { +matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) #no_bounds_check { for i in 0..<4 { for j in 0..<4 { sign: T = 1 if (i + j) % 2 == 0 else -1 @@ -513,13 +513,13 @@ matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) { } @(require_results) -matrix1x1_inverse_transpose :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) { +matrix1x1_inverse_transpose :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check { y[0, 0] = 1/x[0, 0] return } @(require_results) -matrix2x2_inverse_transpose :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) { +matrix2x2_inverse_transpose :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check { d := x[0, 0]*x[1, 1] - x[0, 1]*x[1, 0] when intrinsics.type_is_integer(T) { y[0, 0] = +x[1, 1] / d @@ -582,13 +582,13 @@ matrix4x4_inverse_transpose :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: } @(require_results) -matrix1x1_inverse :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) { +matrix1x1_inverse :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check { y[0, 0] = 1/x[0, 0] return } @(require_results) -matrix2x2_inverse :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) { +matrix2x2_inverse :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check { d := x[0, 0]*x[1, 1] - x[0, 1]*x[1, 0] when intrinsics.type_is_integer(T) { y[0, 0] = +x[1, 1] / d diff --git a/core/math/linalg/specific.odin b/core/math/linalg/specific.odin index 4a0f5ee40..0f26055bf 100644 --- a/core/math/linalg/specific.odin +++ b/core/math/linalg/specific.odin @@ -584,7 +584,7 @@ angle_axis_from_quaternion :: proc { @(require_results) -quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f16) -> Quaternionf16 { +quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f16) -> Quaternionf16 #no_bounds_check { f := normalize(forward) s := normalize(cross(f, up)) u := cross(s, f) @@ -628,7 +628,7 @@ quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f1 return normalize(q) } @(require_results) -quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f32) -> Quaternionf32 { +quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f32) -> Quaternionf32 #no_bounds_check { f := normalize(forward) s := normalize(cross(f, up)) u := cross(s, f) @@ -672,7 +672,7 @@ quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f3 return normalize(q) } @(require_results) -quaternion_from_forward_and_up_f64 :: proc "contextless" (forward, up: Vector3f64) -> Quaternionf64 { +quaternion_from_forward_and_up_f64 :: proc "contextless" (forward, up: Vector3f64) -> Quaternionf64 #no_bounds_check { f := normalize(forward) s := normalize(cross(f, up)) u := cross(s, f) @@ -886,7 +886,7 @@ quaternion_squad :: proc{ @(require_results) -quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quaternionf16) { +quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quaternionf16) #no_bounds_check { m3: Matrix3f16 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1] @@ -894,7 +894,7 @@ quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quatern return quaternion_from_matrix3(m3) } @(require_results) -quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quaternionf32) { +quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quaternionf32) #no_bounds_check { m3: Matrix3f32 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1] @@ -902,7 +902,7 @@ quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quatern return quaternion_from_matrix3(m3) } @(require_results) -quaternion_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (q: Quaternionf64) { +quaternion_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (q: Quaternionf64) #no_bounds_check { m3: Matrix3f64 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1] @@ -917,7 +917,7 @@ quaternion_from_matrix4 :: proc{ @(require_results) -quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quaternionf16) { +quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quaternionf16) #no_bounds_check { four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2] four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2] four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1] @@ -967,7 +967,7 @@ quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quatern return } @(require_results) -quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quaternionf32) { +quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quaternionf32) #no_bounds_check { four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2] four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2] four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1] @@ -1017,7 +1017,7 @@ quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quatern return } @(require_results) -quaternion_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (q: Quaternionf64) { +quaternion_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (q: Quaternionf64) #no_bounds_check { four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2] four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2] four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1] @@ -1147,7 +1147,7 @@ quaternion_between_two_vector3 :: proc{ @(require_results) -matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) { +matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1157,7 +1157,7 @@ matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matri return c } @(require_results) -matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) { +matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1167,7 +1167,7 @@ matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matri return c } @(require_results) -matrix2_inverse_transpose_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) { +matrix2_inverse_transpose_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1184,15 +1184,15 @@ matrix2_inverse_transpose :: proc{ @(require_results) -matrix2_determinant_f16 :: proc "contextless" (m: Matrix2f16) -> f16 { +matrix2_determinant_f16 :: proc "contextless" (m: Matrix2f16) -> f16 #no_bounds_check { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } @(require_results) -matrix2_determinant_f32 :: proc "contextless" (m: Matrix2f32) -> f32 { +matrix2_determinant_f32 :: proc "contextless" (m: Matrix2f32) -> f32 #no_bounds_check { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } @(require_results) -matrix2_determinant_f64 :: proc "contextless" (m: Matrix2f64) -> f64 { +matrix2_determinant_f64 :: proc "contextless" (m: Matrix2f64) -> f64 #no_bounds_check { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } matrix2_determinant :: proc{ @@ -1203,7 +1203,7 @@ matrix2_determinant :: proc{ @(require_results) -matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) { +matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1213,7 +1213,7 @@ matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) { return c } @(require_results) -matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) { +matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1223,7 +1223,7 @@ matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) { return c } @(require_results) -matrix2_inverse_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) { +matrix2_inverse_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d c[0, 0] = +m[1, 1] * id @@ -1240,7 +1240,7 @@ matrix2_inverse :: proc{ @(require_results) -matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) { +matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] c[0, 1] = -m[1, 0] @@ -1248,7 +1248,7 @@ matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) { return c } @(require_results) -matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) { +matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] c[0, 1] = -m[1, 0] @@ -1256,7 +1256,7 @@ matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) { return c } @(require_results) -matrix2_adjoint_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) { +matrix2_adjoint_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] c[0, 1] = -m[1, 0] @@ -1308,7 +1308,7 @@ matrix2_rotate :: proc{ @(require_results) -matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) { +matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1333,7 +1333,7 @@ matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matr return m } @(require_results) -matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix3f32) { +matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix3f32) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1358,7 +1358,7 @@ matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matr return m } @(require_results) -matrix3_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix3f64) { +matrix3_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix3f64) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1409,21 +1409,21 @@ matrix3_inverse :: proc{ @(require_results) -matrix3_determinant_f16 :: proc "contextless" (m: Matrix3f16) -> f16 { +matrix3_determinant_f16 :: proc "contextless" (m: Matrix3f16) -> f16 #no_bounds_check { a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1]) b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0]) c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0]) return a + b + c } @(require_results) -matrix3_determinant_f32 :: proc "contextless" (m: Matrix3f32) -> f32 { +matrix3_determinant_f32 :: proc "contextless" (m: Matrix3f32) -> f32 #no_bounds_check { a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1]) b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0]) c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0]) return a + b + c } @(require_results) -matrix3_determinant_f64 :: proc "contextless" (m: Matrix3f64) -> f64 { +matrix3_determinant_f64 :: proc "contextless" (m: Matrix3f64) -> f64 #no_bounds_check { a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1]) b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0]) c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0]) @@ -1437,7 +1437,7 @@ matrix3_determinant :: proc{ @(require_results) -matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f16) { +matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f16) #no_bounds_check { adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2]) adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2]) adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1]) @@ -1450,7 +1450,7 @@ matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f1 return adjoint } @(require_results) -matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f32) { +matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f32) #no_bounds_check { adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2]) adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2]) adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1]) @@ -1463,7 +1463,7 @@ matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f3 return adjoint } @(require_results) -matrix3_adjoint_f64 :: proc "contextless" (m: Matrix3f64) -> (adjoint: Matrix3f64) { +matrix3_adjoint_f64 :: proc "contextless" (m: Matrix3f64) -> (adjoint: Matrix3f64) #no_bounds_check { adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2]) adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2]) adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1]) @@ -1503,21 +1503,21 @@ matrix3_inverse_transpose :: proc{ @(require_results) -matrix3_scale_f16 :: proc "contextless" (s: Vector3f16) -> (m: Matrix3f16) { +matrix3_scale_f16 :: proc "contextless" (s: Vector3f16) -> (m: Matrix3f16) #no_bounds_check { m[0, 0] = s[0] m[1, 1] = s[1] m[2, 2] = s[2] return m } @(require_results) -matrix3_scale_f32 :: proc "contextless" (s: Vector3f32) -> (m: Matrix3f32) { +matrix3_scale_f32 :: proc "contextless" (s: Vector3f32) -> (m: Matrix3f32) #no_bounds_check { m[0, 0] = s[0] m[1, 1] = s[1] m[2, 2] = s[2] return m } @(require_results) -matrix3_scale_f64 :: proc "contextless" (s: Vector3f64) -> (m: Matrix3f64) { +matrix3_scale_f64 :: proc "contextless" (s: Vector3f64) -> (m: Matrix3f64) #no_bounds_check { m[0, 0] = s[0] m[1, 1] = s[1] m[2, 2] = s[2] @@ -1531,7 +1531,7 @@ matrix3_scale :: proc{ @(require_results) -matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f16) { +matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f16) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1553,7 +1553,7 @@ matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> return rot } @(require_results) -matrix3_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f32) { +matrix3_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f32) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1575,7 +1575,7 @@ matrix3_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> return rot } @(require_results) -matrix3_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> (rot: Matrix3f64) { +matrix3_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> (rot: Matrix3f64) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1644,7 +1644,7 @@ matrix3_look_at :: proc{ @(require_results) -matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix4f16) { +matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix4f16) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1672,7 +1672,7 @@ matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matr return m } @(require_results) -matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix4f32) { +matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix4f32) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1700,7 +1700,7 @@ matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matr return m } @(require_results) -matrix4_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix4f64) { +matrix4_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix4f64) #no_bounds_check { qxx := q.x * q.x qyy := q.y * q.y qzz := q.z * q.z @@ -1783,37 +1783,37 @@ matrix4_inverse :: proc{ @(require_results) -matrix4_minor_f16 :: proc "contextless" (m: Matrix4f16, c, r: int) -> f16 { +matrix4_minor_f16 :: proc "contextless" (m: Matrix4f16, row, col: int) -> f16 #no_bounds_check { cut_down: Matrix3f16 - for i in 0..<3 { - col := i if i < c else i+1 - for j in 0..<3 { - row := j if j < r else j+1 - cut_down[i][j] = m[col][row] + for j in 0..<3 { + x := j if j < col else j+1 + for i in 0..<3 { + y := i if i < row else i+1 + cut_down[i, j] = m[x, y] } } return matrix3_determinant(cut_down) } @(require_results) -matrix4_minor_f32 :: proc "contextless" (m: Matrix4f32, c, r: int) -> f32 { +matrix4_minor_f32 :: proc "contextless" (m: Matrix4f32, row, col: int) -> f32 #no_bounds_check { cut_down: Matrix3f32 - for i in 0..<3 { - col := i if i < c else i+1 - for j in 0..<3 { - row := j if j < r else j+1 - cut_down[i][j] = m[col][row] + for j in 0..<3 { + x := j if j < col else j+1 + for i in 0..<3 { + y := i if i < row else i+1 + cut_down[i, j] = m[x, y] } } return matrix3_determinant(cut_down) } @(require_results) -matrix4_minor_f64 :: proc "contextless" (m: Matrix4f64, c, r: int) -> f64 { +matrix4_minor_f64 :: proc "contextless" (m: Matrix4f64, row, col: int) -> f64 #no_bounds_check { cut_down: Matrix3f64 - for i in 0..<3 { - col := i if i < c else i+1 - for j in 0..<3 { - row := j if j < r else j+1 - cut_down[i][j] = m[col][row] + for j in 0..<3 { + x := j if j < col else j+1 + for i in 0..<3 { + y := i if i < row else i+1 + cut_down[i, j] = m[x, y] } } return matrix3_determinant(cut_down) @@ -1826,24 +1826,24 @@ matrix4_minor :: proc{ @(require_results) -matrix4_cofactor_f16 :: proc "contextless" (m: Matrix4f16, c, r: int) -> f16 { +matrix4_cofactor_f16 :: proc "contextless" (m: Matrix4f16, row, col: int) -> f16 { sign, minor: f16 - sign = 1 if (c + r) % 2 == 0 else -1 - minor = matrix4_minor(m, c, r) + sign = 1 if (row + col) % 2 == 0 else -1 + minor = matrix4_minor(m, row, col) return sign * minor } @(require_results) -matrix4_cofactor_f32 :: proc "contextless" (m: Matrix4f32, c, r: int) -> f32 { +matrix4_cofactor_f32 :: proc "contextless" (m: Matrix4f32, row, col: int) -> f32 { sign, minor: f32 - sign = 1 if (c + r) % 2 == 0 else -1 - minor = matrix4_minor(m, c, r) + sign = 1 if (row + col) % 2 == 0 else -1 + minor = matrix4_minor(m, row, col) return sign * minor } @(require_results) -matrix4_cofactor_f64 :: proc "contextless" (m: Matrix4f64, c, r: int) -> f64 { +matrix4_cofactor_f64 :: proc "contextless" (m: Matrix4f64, row, col: int) -> f64 { sign, minor: f64 - sign = 1 if (c + r) % 2 == 0 else -1 - minor = matrix4_minor(m, c, r) + sign = 1 if (row + col) % 2 == 0 else -1 + minor = matrix4_minor(m, row, col) return sign * minor } matrix4_cofactor :: proc{ @@ -1854,28 +1854,28 @@ matrix4_cofactor :: proc{ @(require_results) -matrix4_adjoint_f16 :: proc "contextless" (m: Matrix4f16) -> (adjoint: Matrix4f16) { +matrix4_adjoint_f16 :: proc "contextless" (m: Matrix4f16) -> (adjoint: Matrix4f16) #no_bounds_check { for i in 0..<4 { for j in 0..<4 { - adjoint[i][j] = matrix4_cofactor(m, i, j) + adjoint[i, j] = matrix4_cofactor(m, i, j) } } return } @(require_results) -matrix4_adjoint_f32 :: proc "contextless" (m: Matrix4f32) -> (adjoint: Matrix4f32) { +matrix4_adjoint_f32 :: proc "contextless" (m: Matrix4f32) -> (adjoint: Matrix4f32) #no_bounds_check { for i in 0..<4 { for j in 0..<4 { - adjoint[i][j] = matrix4_cofactor(m, i, j) + adjoint[i, j] = matrix4_cofactor(m, i, j) } } return } @(require_results) -matrix4_adjoint_f64 :: proc "contextless" (m: Matrix4f64) -> (adjoint: Matrix4f64) { +matrix4_adjoint_f64 :: proc "contextless" (m: Matrix4f64) -> (adjoint: Matrix4f64) #no_bounds_check { for i in 0..<4 { for j in 0..<4 { - adjoint[i][j] = matrix4_cofactor(m, i, j) + adjoint[i, j] = matrix4_cofactor(m, i, j) } } return @@ -1888,26 +1888,26 @@ matrix4_adjoint :: proc{ @(require_results) -matrix4_determinant_f16 :: proc "contextless" (m: Matrix4f16) -> (determinant: f16) { +matrix4_determinant_f16 :: proc "contextless" (m: Matrix4f16) -> (determinant: f16) #no_bounds_check { adjoint := matrix4_adjoint(m) for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } return } @(require_results) -matrix4_determinant_f32 :: proc "contextless" (m: Matrix4f32) -> (determinant: f32) { +matrix4_determinant_f32 :: proc "contextless" (m: Matrix4f32) -> (determinant: f32) #no_bounds_check { adjoint := matrix4_adjoint(m) for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } return } @(require_results) -matrix4_determinant_f64 :: proc "contextless" (m: Matrix4f64) -> (determinant: f64) { +matrix4_determinant_f64 :: proc "contextless" (m: Matrix4f64) -> (determinant: f64) #no_bounds_check { adjoint := matrix4_adjoint(m) for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } return } @@ -1919,46 +1919,46 @@ matrix4_determinant :: proc{ @(require_results) -matrix4_inverse_transpose_f16 :: proc "contextless" (m: Matrix4f16) -> (inverse_transpose: Matrix4f16) { +matrix4_inverse_transpose_f16 :: proc "contextless" (m: Matrix4f16) -> (inverse_transpose: Matrix4f16) #no_bounds_check { adjoint := matrix4_adjoint(m) determinant: f16 = 0 for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } inv_determinant := 1.0 / determinant for i in 0..<4 { for j in 0..<4 { - inverse_transpose[i][j] = adjoint[i][j] * inv_determinant + inverse_transpose[i, j] = adjoint[i, j] * inv_determinant } } return } @(require_results) -matrix4_inverse_transpose_f32 :: proc "contextless" (m: Matrix4f32) -> (inverse_transpose: Matrix4f32) { +matrix4_inverse_transpose_f32 :: proc "contextless" (m: Matrix4f32) -> (inverse_transpose: Matrix4f32) #no_bounds_check { adjoint := matrix4_adjoint(m) determinant: f32 = 0 for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } inv_determinant := 1.0 / determinant for i in 0..<4 { for j in 0..<4 { - inverse_transpose[i][j] = adjoint[i][j] * inv_determinant + inverse_transpose[i, j] = adjoint[i, j] * inv_determinant } } return } @(require_results) -matrix4_inverse_transpose_f64 :: proc "contextless" (m: Matrix4f64) -> (inverse_transpose: Matrix4f64) { +matrix4_inverse_transpose_f64 :: proc "contextless" (m: Matrix4f64) -> (inverse_transpose: Matrix4f64) #no_bounds_check { adjoint := matrix4_adjoint(m) determinant: f64 = 0 for i in 0..<4 { - determinant += m[i][0] * adjoint[i][0] + determinant += m[0, i] * adjoint[0, i] } inv_determinant := 1.0 / determinant for i in 0..<4 { for j in 0..<4 { - inverse_transpose[i][j] = adjoint[i][j] * inv_determinant + inverse_transpose[i, j] = adjoint[i, j] * inv_determinant } } return @@ -1973,25 +1973,25 @@ matrix4_inverse_transpose :: proc{ @(require_results) matrix4_translate_f16 :: proc "contextless" (v: Vector3f16) -> Matrix4f16 { m := MATRIX4F16_IDENTITY - m[3][0] = v[0] - m[3][1] = v[1] - m[3][2] = v[2] + m[0, 3] = v[0] + m[1, 3] = v[1] + m[2, 3] = v[2] return m } @(require_results) matrix4_translate_f32 :: proc "contextless" (v: Vector3f32) -> Matrix4f32 { m := MATRIX4F32_IDENTITY - m[3][0] = v[0] - m[3][1] = v[1] - m[3][2] = v[2] + m[0, 3] = v[0] + m[1, 3] = v[1] + m[2, 3] = v[2] return m } @(require_results) matrix4_translate_f64 :: proc "contextless" (v: Vector3f64) -> Matrix4f64 { m := MATRIX4F64_IDENTITY - m[3][0] = v[0] - m[3][1] = v[1] - m[3][2] = v[2] + m[0, 3] = v[0] + m[1, 3] = v[1] + m[2, 3] = v[2] return m } matrix4_translate :: proc{ @@ -2002,85 +2002,85 @@ matrix4_translate :: proc{ @(require_results) -matrix4_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> Matrix4f16 { +matrix4_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> (rot: Matrix4f16) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) a := normalize(v) t := a * (1-c) - rot := MATRIX4F16_IDENTITY + rot = 1 - rot[0][0] = c + t[0]*a[0] - rot[0][1] = 0 + t[0]*a[1] + s*a[2] - rot[0][2] = 0 + t[0]*a[2] - s*a[1] - rot[0][3] = 0 + rot[0, 0] = c + t[0]*a[0] + rot[1, 0] = 0 + t[0]*a[1] + s*a[2] + rot[2, 0] = 0 + t[0]*a[2] - s*a[1] + rot[3, 0] = 0 - rot[1][0] = 0 + t[1]*a[0] - s*a[2] - rot[1][1] = c + t[1]*a[1] - rot[1][2] = 0 + t[1]*a[2] + s*a[0] - rot[1][3] = 0 + rot[0, 1] = 0 + t[1]*a[0] - s*a[2] + rot[1, 1] = c + t[1]*a[1] + rot[2, 1] = 0 + t[1]*a[2] + s*a[0] + rot[3, 1] = 0 - rot[2][0] = 0 + t[2]*a[0] + s*a[1] - rot[2][1] = 0 + t[2]*a[1] - s*a[0] - rot[2][2] = c + t[2]*a[2] - rot[2][3] = 0 + rot[0, 2] = 0 + t[2]*a[0] + s*a[1] + rot[1, 2] = 0 + t[2]*a[1] - s*a[0] + rot[2, 2] = c + t[2]*a[2] + rot[3, 2] = 0 - return rot + return } @(require_results) -matrix4_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> Matrix4f32 { +matrix4_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> (rot: Matrix4f32) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) a := normalize(v) t := a * (1-c) - rot := MATRIX4F32_IDENTITY + rot = 1 - rot[0][0] = c + t[0]*a[0] - rot[0][1] = 0 + t[0]*a[1] + s*a[2] - rot[0][2] = 0 + t[0]*a[2] - s*a[1] - rot[0][3] = 0 + rot[0, 0] = c + t[0]*a[0] + rot[1, 0] = 0 + t[0]*a[1] + s*a[2] + rot[2, 0] = 0 + t[0]*a[2] - s*a[1] + rot[3, 0] = 0 - rot[1][0] = 0 + t[1]*a[0] - s*a[2] - rot[1][1] = c + t[1]*a[1] - rot[1][2] = 0 + t[1]*a[2] + s*a[0] - rot[1][3] = 0 + rot[0, 1] = 0 + t[1]*a[0] - s*a[2] + rot[1, 1] = c + t[1]*a[1] + rot[2, 1] = 0 + t[1]*a[2] + s*a[0] + rot[3, 1] = 0 - rot[2][0] = 0 + t[2]*a[0] + s*a[1] - rot[2][1] = 0 + t[2]*a[1] - s*a[0] - rot[2][2] = c + t[2]*a[2] - rot[2][3] = 0 + rot[0, 2] = 0 + t[2]*a[0] + s*a[1] + rot[1, 2] = 0 + t[2]*a[1] - s*a[0] + rot[2, 2] = c + t[2]*a[2] + rot[3, 2] = 0 - return rot + return } @(require_results) -matrix4_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> Matrix4f64 { +matrix4_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> (rot: Matrix4f64) #no_bounds_check { c := math.cos(angle_radians) s := math.sin(angle_radians) a := normalize(v) t := a * (1-c) - rot := MATRIX4F64_IDENTITY + rot = 1 - rot[0][0] = c + t[0]*a[0] - rot[0][1] = 0 + t[0]*a[1] + s*a[2] - rot[0][2] = 0 + t[0]*a[2] - s*a[1] - rot[0][3] = 0 + rot[0, 0] = c + t[0]*a[0] + rot[1, 0] = 0 + t[0]*a[1] + s*a[2] + rot[2, 0] = 0 + t[0]*a[2] - s*a[1] + rot[3, 0] = 0 - rot[1][0] = 0 + t[1]*a[0] - s*a[2] - rot[1][1] = c + t[1]*a[1] - rot[1][2] = 0 + t[1]*a[2] + s*a[0] - rot[1][3] = 0 + rot[0, 1] = 0 + t[1]*a[0] - s*a[2] + rot[1, 1] = c + t[1]*a[1] + rot[2, 1] = 0 + t[1]*a[2] + s*a[0] + rot[3, 1] = 0 - rot[2][0] = 0 + t[2]*a[0] + s*a[1] - rot[2][1] = 0 + t[2]*a[1] - s*a[0] - rot[2][2] = c + t[2]*a[2] - rot[2][3] = 0 + rot[0, 2] = 0 + t[2]*a[0] + s*a[1] + rot[1, 2] = 0 + t[2]*a[1] - s*a[0] + rot[2, 2] = c + t[2]*a[2] + rot[3, 2] = 0 - return rot + return } matrix4_rotate :: proc{ matrix4_rotate_f16, @@ -2091,26 +2091,26 @@ matrix4_rotate :: proc{ @(require_results) matrix4_scale_f16 :: proc "contextless" (v: Vector3f16) -> (m: Matrix4f16) { - m[0][0] = v[0] - m[1][1] = v[1] - m[2][2] = v[2] - m[3][3] = 1 + m[0, 0] = v[0] + m[1, 1] = v[1] + m[2, 2] = v[2] + m[3, 3] = 1 return } @(require_results) matrix4_scale_f32 :: proc "contextless" (v: Vector3f32) -> (m: Matrix4f32) { - m[0][0] = v[0] - m[1][1] = v[1] - m[2][2] = v[2] - m[3][3] = 1 + m[0, 0] = v[0] + m[1, 1] = v[1] + m[2, 2] = v[2] + m[3, 3] = 1 return } @(require_results) matrix4_scale_f64 :: proc "contextless" (v: Vector3f64) -> (m: Matrix4f64) { - m[0][0] = v[0] - m[1][1] = v[1] - m[2][2] = v[2] - m[3][3] = 1 + m[0, 0] = v[0] + m[1, 1] = v[1] + m[2, 2] = v[2] + m[3, 3] = 1 return } matrix4_scale :: proc{