diff options
| author | gingerBill <bill@gingerbill.org> | 2023-05-22 12:05:56 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-05-22 12:05:56 +0100 |
| commit | 74ce99e0d758753f255c36d1df564e88347dd712 (patch) | |
| tree | 74e37d243fc1b045eeb2bfa21a049881b83dc0fa /core/math/linalg/specific.odin | |
| parent | 89a233ccd2d4b41c18662d2652f3200507e489e2 (diff) | |
Add `@(require_results)` `core:math/linalg` procedures
Diffstat (limited to 'core/math/linalg/specific.odin')
| -rw-r--r-- | core/math/linalg/specific.odin | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/core/math/linalg/specific.odin b/core/math/linalg/specific.odin index c4ecb194f..e4ebe76da 100644 --- a/core/math/linalg/specific.odin +++ b/core/math/linalg/specific.odin @@ -130,10 +130,12 @@ VECTOR3F64_Y_AXIS :: Vector3f64{0, 1, 0} VECTOR3F64_Z_AXIS :: Vector3f64{0, 0, 1} +@(require_results) vector2_orthogonal :: proc(v: $V/[2]$E) -> V where !IS_ARRAY(E), IS_FLOAT(E) { return {-v.y, v.x} } +@(require_results) vector3_orthogonal :: proc(v: $V/[3]$E) -> V where !IS_ARRAY(E), IS_FLOAT(E) { x := abs(v.x) y := abs(v.y) @@ -160,6 +162,7 @@ orthogonal :: proc{vector2_orthogonal, vector3_orthogonal} +@(require_results) vector4_srgb_to_linear_f16 :: proc(col: Vector4f16) -> Vector4f16 { r := math.pow(col.x, 2.2) g := math.pow(col.y, 2.2) @@ -167,6 +170,7 @@ vector4_srgb_to_linear_f16 :: proc(col: Vector4f16) -> Vector4f16 { a := col.w return {r, g, b, a} } +@(require_results) vector4_srgb_to_linear_f32 :: proc(col: Vector4f32) -> Vector4f32 { r := math.pow(col.x, 2.2) g := math.pow(col.y, 2.2) @@ -174,6 +178,7 @@ vector4_srgb_to_linear_f32 :: proc(col: Vector4f32) -> Vector4f32 { a := col.w return {r, g, b, a} } +@(require_results) vector4_srgb_to_linear_f64 :: proc(col: Vector4f64) -> Vector4f64 { r := math.pow(col.x, 2.2) g := math.pow(col.y, 2.2) @@ -188,6 +193,7 @@ vector4_srgb_to_linear :: proc{ } +@(require_results) vector4_linear_to_srgb_f16 :: proc(col: Vector4f16) -> Vector4f16 { a :: 2.51 b :: 0.03 @@ -209,6 +215,7 @@ vector4_linear_to_srgb_f16 :: proc(col: Vector4f16) -> Vector4f16 { return {x, y, z, col.w} } +@(require_results) vector4_linear_to_srgb_f32 :: proc(col: Vector4f32) -> Vector4f32 { a :: 2.51 b :: 0.03 @@ -230,6 +237,7 @@ vector4_linear_to_srgb_f32 :: proc(col: Vector4f32) -> Vector4f32 { return {x, y, z, col.w} } +@(require_results) vector4_linear_to_srgb_f64 :: proc(col: Vector4f64) -> Vector4f64 { a :: 2.51 b :: 0.03 @@ -258,7 +266,9 @@ vector4_linear_to_srgb :: proc{ } +@(require_results) vector4_hsl_to_rgb_f16 :: proc(h, s, l: f16, a: f16 = 1) -> Vector4f16 { + @(require_results) hue_to_rgb :: proc(p, q, t: f16) -> f16 { t := t if t < 0 { t += 1 } @@ -285,7 +295,9 @@ vector4_hsl_to_rgb_f16 :: proc(h, s, l: f16, a: f16 = 1) -> Vector4f16 { } return {r, g, b, a} } +@(require_results) vector4_hsl_to_rgb_f32 :: proc(h, s, l: f32, a: f32 = 1) -> Vector4f32 { + @(require_results) hue_to_rgb :: proc(p, q, t: f32) -> f32 { t := t if t < 0 { t += 1 } @@ -312,7 +324,9 @@ vector4_hsl_to_rgb_f32 :: proc(h, s, l: f32, a: f32 = 1) -> Vector4f32 { } return {r, g, b, a} } +@(require_results) vector4_hsl_to_rgb_f64 :: proc(h, s, l: f64, a: f64 = 1) -> Vector4f64 { + @(require_results) hue_to_rgb :: proc(p, q, t: f64) -> f64 { t := t if t < 0 { t += 1 } @@ -346,6 +360,7 @@ vector4_hsl_to_rgb :: proc{ } +@(require_results) vector4_rgb_to_hsl_f16 :: proc(col: Vector4f16) -> Vector4f16 { r := col.x g := col.y @@ -375,6 +390,7 @@ vector4_rgb_to_hsl_f16 :: proc(col: Vector4f16) -> Vector4f16 { return {h, s, l, a} } +@(require_results) vector4_rgb_to_hsl_f32 :: proc(col: Vector4f32) -> Vector4f32 { r := col.x g := col.y @@ -404,6 +420,7 @@ vector4_rgb_to_hsl_f32 :: proc(col: Vector4f32) -> Vector4f32 { return {h, s, l, a} } +@(require_results) vector4_rgb_to_hsl_f64 :: proc(col: Vector4f64) -> Vector4f64 { r := col.x g := col.y @@ -441,6 +458,7 @@ vector4_rgb_to_hsl :: proc{ +@(require_results) quaternion_angle_axis_f16 :: proc(angle_radians: f16, axis: Vector3f16) -> (q: Quaternionf16) { t := angle_radians*0.5 v := normalize(axis) * math.sin(t) @@ -450,6 +468,7 @@ quaternion_angle_axis_f16 :: proc(angle_radians: f16, axis: Vector3f16) -> (q: Q q.w = math.cos(t) return } +@(require_results) quaternion_angle_axis_f32 :: proc(angle_radians: f32, axis: Vector3f32) -> (q: Quaternionf32) { t := angle_radians*0.5 v := normalize(axis) * math.sin(t) @@ -459,6 +478,7 @@ quaternion_angle_axis_f32 :: proc(angle_radians: f32, axis: Vector3f32) -> (q: Q q.w = math.cos(t) return } +@(require_results) quaternion_angle_axis_f64 :: proc(angle_radians: f64, axis: Vector3f64) -> (q: Quaternionf64) { t := angle_radians*0.5 v := normalize(axis) * math.sin(t) @@ -474,6 +494,7 @@ quaternion_angle_axis :: proc{ quaternion_angle_axis_f64, } +@(require_results) angle_from_quaternion_f16 :: proc(q: Quaternionf16) -> f16 { if abs(q.w) > math.SQRT_THREE*0.5 { return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 @@ -481,6 +502,7 @@ angle_from_quaternion_f16 :: proc(q: Quaternionf16) -> f16 { return math.acos(q.w) * 2 } +@(require_results) angle_from_quaternion_f32 :: proc(q: Quaternionf32) -> f32 { if abs(q.w) > math.SQRT_THREE*0.5 { return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 @@ -488,6 +510,7 @@ angle_from_quaternion_f32 :: proc(q: Quaternionf32) -> f32 { return math.acos(q.w) * 2 } +@(require_results) angle_from_quaternion_f64 :: proc(q: Quaternionf64) -> f64 { if abs(q.w) > math.SQRT_THREE*0.5 { return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 @@ -501,6 +524,7 @@ angle_from_quaternion :: proc{ angle_from_quaternion_f64, } +@(require_results) axis_from_quaternion_f16 :: proc(q: Quaternionf16) -> Vector3f16 { t1 := 1 - q.w*q.w if t1 < 0 { @@ -509,6 +533,7 @@ axis_from_quaternion_f16 :: proc(q: Quaternionf16) -> Vector3f16 { t2 := 1.0 / math.sqrt(t1) return {q.x*t2, q.y*t2, q.z*t2} } +@(require_results) axis_from_quaternion_f32 :: proc(q: Quaternionf32) -> Vector3f32 { t1 := 1 - q.w*q.w if t1 < 0 { @@ -517,6 +542,7 @@ axis_from_quaternion_f32 :: proc(q: Quaternionf32) -> Vector3f32 { t2 := 1.0 / math.sqrt(t1) return {q.x*t2, q.y*t2, q.z*t2} } +@(require_results) axis_from_quaternion_f64 :: proc(q: Quaternionf64) -> Vector3f64 { t1 := 1 - q.w*q.w if t1 < 0 { @@ -532,16 +558,19 @@ axis_from_quaternion :: proc{ } +@(require_results) angle_axis_from_quaternion_f16 :: proc(q: Quaternionf16) -> (angle: f16, axis: Vector3f16) { angle = angle_from_quaternion(q) axis = axis_from_quaternion(q) return } +@(require_results) angle_axis_from_quaternion_f32 :: proc(q: Quaternionf32) -> (angle: f32, axis: Vector3f32) { angle = angle_from_quaternion(q) axis = axis_from_quaternion(q) return } +@(require_results) angle_axis_from_quaternion_f64 :: proc(q: Quaternionf64) -> (angle: f64, axis: Vector3f64) { angle = angle_from_quaternion(q) axis = axis_from_quaternion(q) @@ -554,6 +583,7 @@ angle_axis_from_quaternion :: proc { } +@(require_results) quaternion_from_forward_and_up_f16 :: proc(forward, up: Vector3f16) -> Quaternionf16 { f := normalize(forward) s := normalize(cross(f, up)) @@ -597,6 +627,7 @@ quaternion_from_forward_and_up_f16 :: proc(forward, up: Vector3f16) -> Quaternio return normalize(q) } +@(require_results) quaternion_from_forward_and_up_f32 :: proc(forward, up: Vector3f32) -> Quaternionf32 { f := normalize(forward) s := normalize(cross(f, up)) @@ -640,6 +671,7 @@ quaternion_from_forward_and_up_f32 :: proc(forward, up: Vector3f32) -> Quaternio return normalize(q) } +@(require_results) quaternion_from_forward_and_up_f64 :: proc(forward, up: Vector3f64) -> Quaternionf64 { f := normalize(forward) s := normalize(cross(f, up)) @@ -689,12 +721,15 @@ quaternion_from_forward_and_up :: proc{ quaternion_from_forward_and_up_f64, } +@(require_results) quaternion_look_at_f16 :: proc(eye, centre: Vector3f16, up: Vector3f16) -> Quaternionf16 { return quaternion_from_matrix3(matrix3_look_at(eye, centre, up)) } +@(require_results) quaternion_look_at_f32 :: proc(eye, centre: Vector3f32, up: Vector3f32) -> Quaternionf32 { return quaternion_from_matrix3(matrix3_look_at(eye, centre, up)) } +@(require_results) quaternion_look_at_f64 :: proc(eye, centre: Vector3f64, up: Vector3f64) -> Quaternionf64 { return quaternion_from_matrix3(matrix3_look_at(eye, centre, up)) } @@ -706,6 +741,7 @@ quaternion_look_at :: proc{ +@(require_results) quaternion_nlerp_f16 :: proc(a, b: Quaternionf16, t: f16) -> (c: Quaternionf16) { c.x = a.x + (b.x-a.x)*t c.y = a.y + (b.y-a.y)*t @@ -713,6 +749,7 @@ quaternion_nlerp_f16 :: proc(a, b: Quaternionf16, t: f16) -> (c: Quaternionf16) c.w = a.w + (b.w-a.w)*t return normalize(c) } +@(require_results) quaternion_nlerp_f32 :: proc(a, b: Quaternionf32, t: f32) -> (c: Quaternionf32) { c.x = a.x + (b.x-a.x)*t c.y = a.y + (b.y-a.y)*t @@ -720,6 +757,7 @@ quaternion_nlerp_f32 :: proc(a, b: Quaternionf32, t: f32) -> (c: Quaternionf32) c.w = a.w + (b.w-a.w)*t return normalize(c) } +@(require_results) quaternion_nlerp_f64 :: proc(a, b: Quaternionf64, t: f64) -> (c: Quaternionf64) { c.x = a.x + (b.x-a.x)*t c.y = a.y + (b.y-a.y)*t @@ -734,6 +772,7 @@ quaternion_nlerp :: proc{ } +@(require_results) quaternion_slerp_f16 :: proc(x, y: Quaternionf16, t: f16) -> (q: Quaternionf16) { a, b := x, y cos_angle := dot(a, b) @@ -761,6 +800,7 @@ quaternion_slerp_f16 :: proc(x, y: Quaternionf16, t: f16) -> (q: Quaternionf16) q.w = factor_a * a.w + factor_b * b.w return } +@(require_results) quaternion_slerp_f32 :: proc(x, y: Quaternionf32, t: f32) -> (q: Quaternionf32) { a, b := x, y cos_angle := dot(a, b) @@ -788,6 +828,7 @@ quaternion_slerp_f32 :: proc(x, y: Quaternionf32, t: f32) -> (q: Quaternionf32) q.w = factor_a * a.w + factor_b * b.w return } +@(require_results) quaternion_slerp_f64 :: proc(x, y: Quaternionf64, t: f64) -> (q: Quaternionf64) { a, b := x, y cos_angle := dot(a, b) @@ -822,14 +863,17 @@ quaternion_slerp :: proc{ } +@(require_results) quaternion_squad_f16 :: proc(q1, q2, s1, s2: Quaternionf16, h: f16) -> Quaternionf16 { slerp :: quaternion_slerp return slerp(slerp(q1, q2, h), slerp(s1, s2, h), 2 * (1 - h) * h) } +@(require_results) quaternion_squad_f32 :: proc(q1, q2, s1, s2: Quaternionf32, h: f32) -> Quaternionf32 { slerp :: quaternion_slerp return slerp(slerp(q1, q2, h), slerp(s1, s2, h), 2 * (1 - h) * h) } +@(require_results) quaternion_squad_f64 :: proc(q1, q2, s1, s2: Quaternionf64, h: f64) -> Quaternionf64 { slerp :: quaternion_slerp return slerp(slerp(q1, q2, h), slerp(s1, s2, h), 2 * (1 - h) * h) @@ -841,6 +885,7 @@ quaternion_squad :: proc{ } +@(require_results) quaternion_from_matrix4_f16 :: proc(m: Matrix4f16) -> (q: Quaternionf16) { m3: Matrix3f16 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] @@ -848,6 +893,7 @@ quaternion_from_matrix4_f16 :: proc(m: Matrix4f16) -> (q: Quaternionf16) { m3[0, 2], m3[1, 2], m3[2, 2] = m[0, 2], m[1, 2], m[2, 2] return quaternion_from_matrix3(m3) } +@(require_results) quaternion_from_matrix4_f32 :: proc(m: Matrix4f32) -> (q: Quaternionf32) { m3: Matrix3f32 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] @@ -855,6 +901,7 @@ quaternion_from_matrix4_f32 :: proc(m: Matrix4f32) -> (q: Quaternionf32) { m3[0, 2], m3[1, 2], m3[2, 2] = m[0, 2], m[1, 2], m[2, 2] return quaternion_from_matrix3(m3) } +@(require_results) quaternion_from_matrix4_f64 :: proc(m: Matrix4f64) -> (q: Quaternionf64) { m3: Matrix3f64 = --- m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0] @@ -869,6 +916,7 @@ quaternion_from_matrix4 :: proc{ } +@(require_results) quaternion_from_matrix3_f16 :: proc(m: Matrix3f16) -> (q: Quaternionf16) { 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] @@ -918,6 +966,7 @@ quaternion_from_matrix3_f16 :: proc(m: Matrix3f16) -> (q: Quaternionf16) { } return } +@(require_results) quaternion_from_matrix3_f32 :: proc(m: Matrix3f32) -> (q: Quaternionf32) { 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] @@ -967,6 +1016,7 @@ quaternion_from_matrix3_f32 :: proc(m: Matrix3f32) -> (q: Quaternionf32) { } return } +@(require_results) quaternion_from_matrix3_f64 :: proc(m: Matrix3f64) -> (q: Quaternionf64) { 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] @@ -1023,6 +1073,7 @@ quaternion_from_matrix3 :: proc{ } +@(require_results) quaternion_between_two_vector3_f16 :: proc(from, to: Vector3f16) -> (q: Quaternionf16) { x := normalize(from) y := normalize(to) @@ -1044,6 +1095,7 @@ quaternion_between_two_vector3_f16 :: proc(from, to: Vector3f16) -> (q: Quaterni q.z = v.z return normalize(q) } +@(require_results) quaternion_between_two_vector3_f32 :: proc(from, to: Vector3f32) -> (q: Quaternionf32) { x := normalize(from) y := normalize(to) @@ -1065,6 +1117,7 @@ quaternion_between_two_vector3_f32 :: proc(from, to: Vector3f32) -> (q: Quaterni q.z = v.z return normalize(q) } +@(require_results) quaternion_between_two_vector3_f64 :: proc(from, to: Vector3f64) -> (q: Quaternionf64) { x := normalize(from) y := normalize(to) @@ -1093,6 +1146,7 @@ quaternion_between_two_vector3 :: proc{ } +@(require_results) matrix2_inverse_transpose_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1102,6 +1156,7 @@ matrix2_inverse_transpose_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { c[1, 1] = +m[0, 0] * id return c } +@(require_results) matrix2_inverse_transpose_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1111,6 +1166,7 @@ matrix2_inverse_transpose_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { c[1, 1] = +m[0, 0] * id return c } +@(require_results) matrix2_inverse_transpose_f64 :: proc(m: Matrix2f64) -> (c: Matrix2f64) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1127,12 +1183,15 @@ matrix2_inverse_transpose :: proc{ } +@(require_results) matrix2_determinant_f16 :: proc(m: Matrix2f16) -> f16 { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } +@(require_results) matrix2_determinant_f32 :: proc(m: Matrix2f32) -> f32 { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } +@(require_results) matrix2_determinant_f64 :: proc(m: Matrix2f64) -> f64 { return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] } @@ -1143,6 +1202,7 @@ matrix2_determinant :: proc{ } +@(require_results) matrix2_inverse_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1152,6 +1212,7 @@ matrix2_inverse_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { c[1, 1] = +m[0, 0] * id return c } +@(require_results) matrix2_inverse_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1161,6 +1222,7 @@ matrix2_inverse_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { c[1, 1] = +m[0, 0] * id return c } +@(require_results) matrix2_inverse_f64 :: proc(m: Matrix2f64) -> (c: Matrix2f64) { d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0] id := 1.0/d @@ -1177,6 +1239,7 @@ matrix2_inverse :: proc{ } +@(require_results) matrix2_adjoint_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] @@ -1184,6 +1247,7 @@ matrix2_adjoint_f16 :: proc(m: Matrix2f16) -> (c: Matrix2f16) { c[1, 1] = +m[0, 0] return c } +@(require_results) matrix2_adjoint_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] @@ -1191,6 +1255,7 @@ matrix2_adjoint_f32 :: proc(m: Matrix2f32) -> (c: Matrix2f32) { c[1, 1] = +m[0, 0] return c } +@(require_results) matrix2_adjoint_f64 :: proc(m: Matrix2f64) -> (c: Matrix2f64) { c[0, 0] = +m[1, 1] c[1, 0] = -m[0, 1] @@ -1205,6 +1270,7 @@ matrix2_adjoint :: proc{ } +@(require_results) matrix3_from_quaternion_f16 :: proc(q: Quaternionf16) -> (m: Matrix3f16) { qxx := q.x * q.x qyy := q.y * q.y @@ -1229,6 +1295,7 @@ matrix3_from_quaternion_f16 :: proc(q: Quaternionf16) -> (m: Matrix3f16) { m[2, 2] = 1 - 2 * (qxx + qyy) return m } +@(require_results) matrix3_from_quaternion_f32 :: proc(q: Quaternionf32) -> (m: Matrix3f32) { qxx := q.x * q.x qyy := q.y * q.y @@ -1253,6 +1320,7 @@ matrix3_from_quaternion_f32 :: proc(q: Quaternionf32) -> (m: Matrix3f32) { m[2, 2] = 1 - 2 * (qxx + qyy) return m } +@(require_results) matrix3_from_quaternion_f64 :: proc(q: Quaternionf64) -> (m: Matrix3f64) { qxx := q.x * q.x qyy := q.y * q.y @@ -1284,12 +1352,15 @@ matrix3_from_quaternion :: proc{ } +@(require_results) matrix3_inverse_f16 :: proc(m: Matrix3f16) -> Matrix3f16 { return transpose(matrix3_inverse_transpose(m)) } +@(require_results) matrix3_inverse_f32 :: proc(m: Matrix3f32) -> Matrix3f32 { return transpose(matrix3_inverse_transpose(m)) } +@(require_results) matrix3_inverse_f64 :: proc(m: Matrix3f64) -> Matrix3f64 { return transpose(matrix3_inverse_transpose(m)) } @@ -1300,18 +1371,21 @@ matrix3_inverse :: proc{ } +@(require_results) matrix3_determinant_f16 :: proc(m: Matrix3f16) -> f16 { 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(m: Matrix3f32) -> f32 { 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(m: Matrix3f64) -> f64 { 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]) @@ -1325,6 +1399,7 @@ matrix3_determinant :: proc{ } +@(require_results) matrix3_adjoint_f16 :: proc(m: Matrix3f16) -> (adjoint: Matrix3f16) { 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]) @@ -1337,6 +1412,7 @@ matrix3_adjoint_f16 :: proc(m: Matrix3f16) -> (adjoint: Matrix3f16) { adjoint[2, 2] = +(m[0, 0] * m[1, 1] - m[1, 0] * m[0, 1]) return adjoint } +@(require_results) matrix3_adjoint_f32 :: proc(m: Matrix3f32) -> (adjoint: Matrix3f32) { 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]) @@ -1349,6 +1425,7 @@ matrix3_adjoint_f32 :: proc(m: Matrix3f32) -> (adjoint: Matrix3f32) { adjoint[2, 2] = +(m[0, 0] * m[1, 1] - m[1, 0] * m[0, 1]) return adjoint } +@(require_results) matrix3_adjoint_f64 :: proc(m: Matrix3f64) -> (adjoint: Matrix3f64) { 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]) @@ -1369,12 +1446,15 @@ matrix3_adjoint :: proc{ +@(require_results) matrix3_inverse_transpose_f16 :: proc(m: Matrix3f16) -> (inverse_transpose: Matrix3f16) { return builtin.inverse_transpose(m) } +@(require_results) matrix3_inverse_transpose_f32 :: proc(m: Matrix3f32) -> (inverse_transpose: Matrix3f32) { return builtin.inverse_transpose(m) } +@(require_results) matrix3_inverse_transpose_f64 :: proc(m: Matrix3f64) -> (inverse_transpose: Matrix3f64) { return builtin.inverse_transpose(m) } @@ -1385,18 +1465,21 @@ matrix3_inverse_transpose :: proc{ } +@(require_results) matrix3_scale_f16 :: proc(s: Vector3f16) -> (m: Matrix3f16) { m[0, 0] = s[0] m[1, 1] = s[1] m[2, 2] = s[2] return m } +@(require_results) matrix3_scale_f32 :: proc(s: Vector3f32) -> (m: Matrix3f32) { m[0, 0] = s[0] m[1, 1] = s[1] m[2, 2] = s[2] return m } +@(require_results) matrix3_scale_f64 :: proc(s: Vector3f64) -> (m: Matrix3f64) { m[0, 0] = s[0] m[1, 1] = s[1] @@ -1410,6 +1493,7 @@ matrix3_scale :: proc{ } +@(require_results) matrix3_rotate_f16 :: proc(angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f16) { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1431,6 +1515,7 @@ matrix3_rotate_f16 :: proc(angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f1 return rot } +@(require_results) matrix3_rotate_f32 :: proc(angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f32) { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1452,6 +1537,7 @@ matrix3_rotate_f32 :: proc(angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f3 return rot } +@(require_results) matrix3_rotate_f64 :: proc(angle_radians: f64, v: Vector3f64) -> (rot: Matrix3f64) { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1480,6 +1566,7 @@ matrix3_rotate :: proc{ } +@(require_results) matrix3_look_at_f16 :: proc(eye, centre, up: Vector3f16) -> Matrix3f16 { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -1490,6 +1577,7 @@ matrix3_look_at_f16 :: proc(eye, centre, up: Vector3f16) -> Matrix3f16 { -f.x, -f.y, -f.z, } } +@(require_results) matrix3_look_at_f32 :: proc(eye, centre, up: Vector3f32) -> Matrix3f32 { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -1500,6 +1588,7 @@ matrix3_look_at_f32 :: proc(eye, centre, up: Vector3f32) -> Matrix3f32 { -f.x, -f.y, -f.z, } } +@(require_results) matrix3_look_at_f64 :: proc(eye, centre, up: Vector3f64) -> Matrix3f64 { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -1517,6 +1606,7 @@ matrix3_look_at :: proc{ } +@(require_results) matrix4_from_quaternion_f16 :: proc(q: Quaternionf16) -> (m: Matrix4f16) { qxx := q.x * q.x qyy := q.y * q.y @@ -1544,6 +1634,7 @@ matrix4_from_quaternion_f16 :: proc(q: Quaternionf16) -> (m: Matrix4f16) { return m } +@(require_results) matrix4_from_quaternion_f32 :: proc(q: Quaternionf32) -> (m: Matrix4f32) { qxx := q.x * q.x qyy := q.y * q.y @@ -1571,6 +1662,7 @@ matrix4_from_quaternion_f32 :: proc(q: Quaternionf32) -> (m: Matrix4f32) { return m } +@(require_results) matrix4_from_quaternion_f64 :: proc(q: Quaternionf64) -> (m: Matrix4f64) { qxx := q.x * q.x qyy := q.y * q.y @@ -1605,18 +1697,21 @@ matrix4_from_quaternion :: proc{ } +@(require_results) matrix4_from_trs_f16 :: proc(t: Vector3f16, r: Quaternionf16, s: Vector3f16) -> Matrix4f16 { translation := matrix4_translate(t) rotation := matrix4_from_quaternion(r) scale := matrix4_scale(s) return mul(translation, mul(rotation, scale)) } +@(require_results) matrix4_from_trs_f32 :: proc(t: Vector3f32, r: Quaternionf32, s: Vector3f32) -> Matrix4f32 { translation := matrix4_translate(t) rotation := matrix4_from_quaternion(r) scale := matrix4_scale(s) return mul(translation, mul(rotation, scale)) } +@(require_results) matrix4_from_trs_f64 :: proc(t: Vector3f64, r: Quaternionf64, s: Vector3f64) -> Matrix4f64 { translation := matrix4_translate(t) rotation := matrix4_from_quaternion(r) @@ -1631,12 +1726,15 @@ matrix4_from_trs :: proc{ +@(require_results) matrix4_inverse_f16 :: proc(m: Matrix4f16) -> Matrix4f16 { return transpose(matrix4_inverse_transpose(m)) } +@(require_results) matrix4_inverse_f32 :: proc(m: Matrix4f32) -> Matrix4f32 { return transpose(matrix4_inverse_transpose(m)) } +@(require_results) matrix4_inverse_f64 :: proc(m: Matrix4f64) -> Matrix4f64 { return transpose(matrix4_inverse_transpose(m)) } @@ -1647,6 +1745,7 @@ matrix4_inverse :: proc{ } +@(require_results) matrix4_minor_f16 :: proc(m: Matrix4f16, c, r: int) -> f16 { cut_down: Matrix3f16 for i in 0..<3 { @@ -1658,6 +1757,7 @@ matrix4_minor_f16 :: proc(m: Matrix4f16, c, r: int) -> f16 { } return matrix3_determinant(cut_down) } +@(require_results) matrix4_minor_f32 :: proc(m: Matrix4f32, c, r: int) -> f32 { cut_down: Matrix3f32 for i in 0..<3 { @@ -1669,6 +1769,7 @@ matrix4_minor_f32 :: proc(m: Matrix4f32, c, r: int) -> f32 { } return matrix3_determinant(cut_down) } +@(require_results) matrix4_minor_f64 :: proc(m: Matrix4f64, c, r: int) -> f64 { cut_down: Matrix3f64 for i in 0..<3 { @@ -1687,18 +1788,21 @@ matrix4_minor :: proc{ } +@(require_results) matrix4_cofactor_f16 :: proc(m: Matrix4f16, c, r: int) -> f16 { sign, minor: f16 sign = 1 if (c + r) % 2 == 0 else -1 minor = matrix4_minor(m, c, r) return sign * minor } +@(require_results) matrix4_cofactor_f32 :: proc(m: Matrix4f32, c, r: int) -> f32 { sign, minor: f32 sign = 1 if (c + r) % 2 == 0 else -1 minor = matrix4_minor(m, c, r) return sign * minor } +@(require_results) matrix4_cofactor_f64 :: proc(m: Matrix4f64, c, r: int) -> f64 { sign, minor: f64 sign = 1 if (c + r) % 2 == 0 else -1 @@ -1712,6 +1816,7 @@ matrix4_cofactor :: proc{ } +@(require_results) matrix4_adjoint_f16 :: proc(m: Matrix4f16) -> (adjoint: Matrix4f16) { for i in 0..<4 { for j in 0..<4 { @@ -1720,6 +1825,7 @@ matrix4_adjoint_f16 :: proc(m: Matrix4f16) -> (adjoint: Matrix4f16) { } return } +@(require_results) matrix4_adjoint_f32 :: proc(m: Matrix4f32) -> (adjoint: Matrix4f32) { for i in 0..<4 { for j in 0..<4 { @@ -1728,6 +1834,7 @@ matrix4_adjoint_f32 :: proc(m: Matrix4f32) -> (adjoint: Matrix4f32) { } return } +@(require_results) matrix4_adjoint_f64 :: proc(m: Matrix4f64) -> (adjoint: Matrix4f64) { for i in 0..<4 { for j in 0..<4 { @@ -1743,6 +1850,7 @@ matrix4_adjoint :: proc{ } +@(require_results) matrix4_determinant_f16 :: proc(m: Matrix4f16) -> (determinant: f16) { adjoint := matrix4_adjoint(m) for i in 0..<4 { @@ -1750,6 +1858,7 @@ matrix4_determinant_f16 :: proc(m: Matrix4f16) -> (determinant: f16) { } return } +@(require_results) matrix4_determinant_f32 :: proc(m: Matrix4f32) -> (determinant: f32) { adjoint := matrix4_adjoint(m) for i in 0..<4 { @@ -1757,6 +1866,7 @@ matrix4_determinant_f32 :: proc(m: Matrix4f32) -> (determinant: f32) { } return } +@(require_results) matrix4_determinant_f64 :: proc(m: Matrix4f64) -> (determinant: f64) { adjoint := matrix4_adjoint(m) for i in 0..<4 { @@ -1771,6 +1881,7 @@ matrix4_determinant :: proc{ } +@(require_results) matrix4_inverse_transpose_f16 :: proc(m: Matrix4f16) -> (inverse_transpose: Matrix4f16) { adjoint := matrix4_adjoint(m) determinant: f16 = 0 @@ -1785,6 +1896,7 @@ matrix4_inverse_transpose_f16 :: proc(m: Matrix4f16) -> (inverse_transpose: Matr } return } +@(require_results) matrix4_inverse_transpose_f32 :: proc(m: Matrix4f32) -> (inverse_transpose: Matrix4f32) { adjoint := matrix4_adjoint(m) determinant: f32 = 0 @@ -1799,6 +1911,7 @@ matrix4_inverse_transpose_f32 :: proc(m: Matrix4f32) -> (inverse_transpose: Matr } return } +@(require_results) matrix4_inverse_transpose_f64 :: proc(m: Matrix4f64) -> (inverse_transpose: Matrix4f64) { adjoint := matrix4_adjoint(m) determinant: f64 = 0 @@ -1820,6 +1933,7 @@ matrix4_inverse_transpose :: proc{ } +@(require_results) matrix4_translate_f16 :: proc(v: Vector3f16) -> Matrix4f16 { m := MATRIX4F16_IDENTITY m[3][0] = v[0] @@ -1827,6 +1941,7 @@ matrix4_translate_f16 :: proc(v: Vector3f16) -> Matrix4f16 { m[3][2] = v[2] return m } +@(require_results) matrix4_translate_f32 :: proc(v: Vector3f32) -> Matrix4f32 { m := MATRIX4F32_IDENTITY m[3][0] = v[0] @@ -1834,6 +1949,7 @@ matrix4_translate_f32 :: proc(v: Vector3f32) -> Matrix4f32 { m[3][2] = v[2] return m } +@(require_results) matrix4_translate_f64 :: proc(v: Vector3f64) -> Matrix4f64 { m := MATRIX4F64_IDENTITY m[3][0] = v[0] @@ -1848,6 +1964,7 @@ matrix4_translate :: proc{ } +@(require_results) matrix4_rotate_f16 :: proc(angle_radians: f16, v: Vector3f16) -> Matrix4f16 { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1874,6 +1991,7 @@ matrix4_rotate_f16 :: proc(angle_radians: f16, v: Vector3f16) -> Matrix4f16 { return rot } +@(require_results) matrix4_rotate_f32 :: proc(angle_radians: f32, v: Vector3f32) -> Matrix4f32 { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1900,6 +2018,7 @@ matrix4_rotate_f32 :: proc(angle_radians: f32, v: Vector3f32) -> Matrix4f32 { return rot } +@(require_results) matrix4_rotate_f64 :: proc(angle_radians: f64, v: Vector3f64) -> Matrix4f64 { c := math.cos(angle_radians) s := math.sin(angle_radians) @@ -1933,6 +2052,7 @@ matrix4_rotate :: proc{ } +@(require_results) matrix4_scale_f16 :: proc(v: Vector3f16) -> (m: Matrix4f16) { m[0][0] = v[0] m[1][1] = v[1] @@ -1940,6 +2060,7 @@ matrix4_scale_f16 :: proc(v: Vector3f16) -> (m: Matrix4f16) { m[3][3] = 1 return } +@(require_results) matrix4_scale_f32 :: proc(v: Vector3f32) -> (m: Matrix4f32) { m[0][0] = v[0] m[1][1] = v[1] @@ -1947,6 +2068,7 @@ matrix4_scale_f32 :: proc(v: Vector3f32) -> (m: Matrix4f32) { m[3][3] = 1 return } +@(require_results) matrix4_scale_f64 :: proc(v: Vector3f64) -> (m: Matrix4f64) { m[0][0] = v[0] m[1][1] = v[1] @@ -1961,6 +2083,7 @@ matrix4_scale :: proc{ } +@(require_results) matrix4_look_at_f16 :: proc(eye, centre, up: Vector3f16, flip_z_axis := true) -> (m: Matrix4f16) { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -1975,6 +2098,7 @@ matrix4_look_at_f16 :: proc(eye, centre, up: Vector3f16, flip_z_axis := true) -> 0, 0, 0, 1, } } +@(require_results) matrix4_look_at_f32 :: proc(eye, centre, up: Vector3f32, flip_z_axis := true) -> (m: Matrix4f32) { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -1989,6 +2113,7 @@ matrix4_look_at_f32 :: proc(eye, centre, up: Vector3f32, flip_z_axis := true) -> 0, 0, 0, 1, } } +@(require_results) matrix4_look_at_f64 :: proc(eye, centre, up: Vector3f64, flip_z_axis := true) -> (m: Matrix4f64) { f := normalize(centre - eye) s := normalize(cross(f, up)) @@ -2010,6 +2135,7 @@ matrix4_look_at :: proc{ } +@(require_results) matrix4_look_at_from_fru_f16 :: proc(eye, f, r, u: Vector3f16, flip_z_axis := true) -> (m: Matrix4f16) { f, s, u := f, r, u f = normalize(f) @@ -2024,6 +2150,7 @@ matrix4_look_at_from_fru_f16 :: proc(eye, f, r, u: Vector3f16, flip_z_axis := tr 0, 0, 0, 1, } } +@(require_results) matrix4_look_at_from_fru_f32 :: proc(eye, f, r, u: Vector3f32, flip_z_axis := true) -> (m: Matrix4f32) { f, s, u := f, r, u f = normalize(f) @@ -2038,6 +2165,7 @@ matrix4_look_at_from_fru_f32 :: proc(eye, f, r, u: Vector3f32, flip_z_axis := tr 0, 0, 0, 1, } } +@(require_results) matrix4_look_at_from_fru_f64 :: proc(eye, f, r, u: Vector3f64, flip_z_axis := true) -> (m: Matrix4f64) { f, s, u := f, r, u f = normalize(f) @@ -2059,6 +2187,7 @@ matrix4_look_at_from_fru :: proc{ } +@(require_results) matrix4_perspective_f16 :: proc(fovy, aspect, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2073,6 +2202,7 @@ matrix4_perspective_f16 :: proc(fovy, aspect, near, far: f16, flip_z_axis := tru return } +@(require_results) matrix4_perspective_f32 :: proc(fovy, aspect, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2087,6 +2217,7 @@ matrix4_perspective_f32 :: proc(fovy, aspect, near, far: f32, flip_z_axis := tru return } +@(require_results) matrix4_perspective_f64 :: proc(fovy, aspect, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2109,6 +2240,7 @@ matrix4_perspective :: proc{ +@(require_results) matrix_ortho3d_f16 :: proc(left, right, bottom, top, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) { m[0, 0] = +2 / (right - left) m[1, 1] = +2 / (top - bottom) @@ -2124,6 +2256,7 @@ matrix_ortho3d_f16 :: proc(left, right, bottom, top, near, far: f16, flip_z_axis return } +@(require_results) matrix_ortho3d_f32 :: proc(left, right, bottom, top, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) { m[0, 0] = +2 / (right - left) m[1, 1] = +2 / (top - bottom) @@ -2139,6 +2272,7 @@ matrix_ortho3d_f32 :: proc(left, right, bottom, top, near, far: f32, flip_z_axis return } +@(require_results) matrix_ortho3d_f64 :: proc(left, right, bottom, top, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) { m[0, 0] = +2 / (right - left) m[1, 1] = +2 / (top - bottom) @@ -2162,6 +2296,7 @@ matrix_ortho3d :: proc{ +@(require_results) matrix4_infinite_perspective_f16 :: proc(fovy, aspect, near: f16, flip_z_axis := true) -> (m: Matrix4f16) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2176,6 +2311,7 @@ matrix4_infinite_perspective_f16 :: proc(fovy, aspect, near: f16, flip_z_axis := return } +@(require_results) matrix4_infinite_perspective_f32 :: proc(fovy, aspect, near: f32, flip_z_axis := true) -> (m: Matrix4f32) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2190,6 +2326,7 @@ matrix4_infinite_perspective_f32 :: proc(fovy, aspect, near: f32, flip_z_axis := return } +@(require_results) matrix4_infinite_perspective_f64 :: proc(fovy, aspect, near: f64, flip_z_axis := true) -> (m: Matrix4f64) { tan_half_fovy := math.tan(0.5 * fovy) m[0, 0] = 1 / (aspect*tan_half_fovy) @@ -2212,16 +2349,19 @@ matrix4_infinite_perspective :: proc{ +@(require_results) matrix2_from_scalar_f16 :: proc(f: f16) -> (m: Matrix2f16) { m[0, 0], m[1, 0] = f, 0 m[0, 1], m[1, 1] = 0, f return } +@(require_results) matrix2_from_scalar_f32 :: proc(f: f32) -> (m: Matrix2f32) { m[0, 0], m[1, 0] = f, 0 m[0, 1], m[1, 1] = 0, f return } +@(require_results) matrix2_from_scalar_f64 :: proc(f: f64) -> (m: Matrix2f64) { m[0, 0], m[1, 0] = f, 0 m[0, 1], m[1, 1] = 0, f @@ -2234,18 +2374,21 @@ matrix2_from_scalar :: proc{ } +@(require_results) matrix3_from_scalar_f16 :: proc(f: f16) -> (m: Matrix3f16) { m[0, 0], m[1, 0], m[2, 0] = f, 0, 0 m[0, 1], m[1, 1], m[2, 1] = 0, f, 0 m[0, 2], m[1, 2], m[2, 2] = 0, 0, f return } +@(require_results) matrix3_from_scalar_f32 :: proc(f: f32) -> (m: Matrix3f32) { m[0, 0], m[1, 0], m[2, 0] = f, 0, 0 m[0, 1], m[1, 1], m[2, 1] = 0, f, 0 m[0, 2], m[1, 2], m[2, 2] = 0, 0, f return } +@(require_results) matrix3_from_scalar_f64 :: proc(f: f64) -> (m: Matrix3f64) { m[0, 0], m[1, 0], m[2, 0] = f, 0, 0 m[0, 1], m[1, 1], m[2, 1] = 0, f, 0 @@ -2259,6 +2402,7 @@ matrix3_from_scalar :: proc{ } +@(require_results) matrix4_from_scalar_f16 :: proc(f: f16) -> (m: Matrix4f16) { m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0 m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0 @@ -2266,6 +2410,7 @@ matrix4_from_scalar_f16 :: proc(f: f16) -> (m: Matrix4f16) { m[0, 3], m[1, 3], m[2, 3], m[3, 3] = 0, 0, 0, f return } +@(require_results) matrix4_from_scalar_f32 :: proc(f: f32) -> (m: Matrix4f32) { m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0 m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0 @@ -2273,6 +2418,7 @@ matrix4_from_scalar_f32 :: proc(f: f32) -> (m: Matrix4f32) { m[0, 3], m[1, 3], m[2, 3], m[3, 3] = 0, 0, 0, f return } +@(require_results) matrix4_from_scalar_f64 :: proc(f: f64) -> (m: Matrix4f64) { m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0 m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0 @@ -2287,16 +2433,19 @@ matrix4_from_scalar :: proc{ } +@(require_results) matrix2_from_matrix3_f16 :: proc(m: Matrix3f16) -> (r: Matrix2f16) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] return } +@(require_results) matrix2_from_matrix3_f32 :: proc(m: Matrix3f32) -> (r: Matrix2f32) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] return } +@(require_results) matrix2_from_matrix3_f64 :: proc(m: Matrix3f64) -> (r: Matrix2f64) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] @@ -2309,16 +2458,19 @@ matrix2_from_matrix3 :: proc{ } +@(require_results) matrix2_from_matrix4_f16 :: proc(m: Matrix4f16) -> (r: Matrix2f16) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] return } +@(require_results) matrix2_from_matrix4_f32 :: proc(m: Matrix4f32) -> (r: Matrix2f32) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] return } +@(require_results) matrix2_from_matrix4_f64 :: proc(m: Matrix4f64) -> (r: Matrix2f64) { r[0, 0], r[1, 0] = m[0, 0], m[1, 0] r[0, 1], r[1, 1] = m[0, 1], m[1, 1] @@ -2331,18 +2483,21 @@ matrix2_from_matrix4 :: proc{ } +@(require_results) matrix3_from_matrix2_f16 :: proc(m: Matrix2f16) -> (r: Matrix3f16) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0 r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0 r[0, 2], r[1, 2], r[2, 2] = 0, 0, 1 return } +@(require_results) matrix3_from_matrix2_f32 :: proc(m: Matrix2f32) -> (r: Matrix3f32) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0 r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0 r[0, 2], r[1, 2], r[2, 2] = 0, 0, 1 return } +@(require_results) matrix3_from_matrix2_f64 :: proc(m: Matrix2f64) -> (r: Matrix3f64) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0 r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0 @@ -2356,18 +2511,21 @@ matrix3_from_matrix2 :: proc{ } +@(require_results) matrix3_from_matrix4_f16 :: proc(m: Matrix4f16) -> (r: Matrix3f16) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0] r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1] r[0, 2], r[1, 2], r[2, 2] = m[0, 2], m[1, 2], m[2, 2] return } +@(require_results) matrix3_from_matrix4_f32 :: proc(m: Matrix4f32) -> (r: Matrix3f32) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0] r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1] r[0, 2], r[1, 2], r[2, 2] = m[0, 2], m[1, 2], m[2, 2] return } +@(require_results) matrix3_from_matrix4_f64 :: proc(m: Matrix4f64) -> (r: Matrix3f64) { r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0] r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1] @@ -2381,6 +2539,7 @@ matrix3_from_matrix4 :: proc{ } +@(require_results) matrix4_from_matrix2_f16 :: proc(m: Matrix2f16) -> (r: Matrix4f16) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0 @@ -2388,6 +2547,7 @@ matrix4_from_matrix2_f16 :: proc(m: Matrix2f16) -> (r: Matrix4f16) { r[0, 3], r[1, 3], r[2, 3], r[3, 3] = 0, 0, 0, 1 return } +@(require_results) matrix4_from_matrix2_f32 :: proc(m: Matrix2f32) -> (r: Matrix4f32) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0 @@ -2395,6 +2555,7 @@ matrix4_from_matrix2_f32 :: proc(m: Matrix2f32) -> (r: Matrix4f32) { r[0, 3], r[1, 3], r[2, 3], r[3, 3] = 0, 0, 0, 1 return } +@(require_results) matrix4_from_matrix2_f64 :: proc(m: Matrix2f64) -> (r: Matrix4f64) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0 @@ -2409,6 +2570,7 @@ matrix4_from_matrix2 :: proc{ } +@(require_results) matrix4_from_matrix3_f16 :: proc(m: Matrix3f16) -> (r: Matrix4f16) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0 @@ -2416,6 +2578,7 @@ matrix4_from_matrix3_f16 :: proc(m: Matrix3f16) -> (r: Matrix4f16) { r[0, 3], r[1, 3], r[2, 3], r[3, 3] = 0, 0, 0, 1 return } +@(require_results) matrix4_from_matrix3_f32 :: proc(m: Matrix3f32) -> (r: Matrix4f32) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0 @@ -2423,6 +2586,7 @@ matrix4_from_matrix3_f32 :: proc(m: Matrix3f32) -> (r: Matrix4f32) { r[0, 3], r[1, 3], r[2, 3], r[3, 3] = 0, 0, 0, 1 return } +@(require_results) matrix4_from_matrix3_f64 :: proc(m: Matrix3f64) -> (r: Matrix4f64) { r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0 r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0 @@ -2437,14 +2601,17 @@ matrix4_from_matrix3 :: proc{ } +@(require_results) quaternion_from_scalar_f16 :: proc(f: f16) -> (q: Quaternionf16) { q.w = f return } +@(require_results) quaternion_from_scalar_f32 :: proc(f: f32) -> (q: Quaternionf32) { q.w = f return } +@(require_results) quaternion_from_scalar_f64 :: proc(f: f64) -> (q: Quaternionf64) { q.w = f return @@ -2505,6 +2672,7 @@ to_quaternion :: proc{ +@(require_results) matrix2_orthonormalize_f16 :: proc(m: Matrix2f16) -> (r: Matrix2f16) { r[0] = normalize(m[0]) @@ -2514,6 +2682,7 @@ matrix2_orthonormalize_f16 :: proc(m: Matrix2f16) -> (r: Matrix2f16) { return } +@(require_results) matrix2_orthonormalize_f32 :: proc(m: Matrix2f32) -> (r: Matrix2f32) { r[0] = normalize(m[0]) @@ -2523,6 +2692,7 @@ matrix2_orthonormalize_f32 :: proc(m: Matrix2f32) -> (r: Matrix2f32) { return } +@(require_results) matrix2_orthonormalize_f64 :: proc(m: Matrix2f64) -> (r: Matrix2f64) { r[0] = normalize(m[0]) @@ -2539,6 +2709,7 @@ matrix2_orthonormalize :: proc{ } +@(require_results) matrix3_orthonormalize_f16 :: proc(m: Matrix3f16) -> (r: Matrix3f16) { r[0] = normalize(m[0]) @@ -2553,6 +2724,7 @@ matrix3_orthonormalize_f16 :: proc(m: Matrix3f16) -> (r: Matrix3f16) { return } +@(require_results) matrix3_orthonormalize_f32 :: proc(m: Matrix3f32) -> (r: Matrix3f32) { r[0] = normalize(m[0]) @@ -2567,6 +2739,7 @@ matrix3_orthonormalize_f32 :: proc(m: Matrix3f32) -> (r: Matrix3f32) { return } +@(require_results) matrix3_orthonormalize_f64 :: proc(m: Matrix3f64) -> (r: Matrix3f64) { r[0] = normalize(m[0]) @@ -2588,12 +2761,15 @@ matrix3_orthonormalize :: proc{ } +@(require_results) vector3_orthonormalize_f16 :: proc(x, y: Vector3f16) -> (z: Vector3f16) { return normalize(x - y * dot(y, x)) } +@(require_results) vector3_orthonormalize_f32 :: proc(x, y: Vector3f32) -> (z: Vector3f32) { return normalize(x - y * dot(y, x)) } +@(require_results) vector3_orthonormalize_f64 :: proc(x, y: Vector3f64) -> (z: Vector3f64) { return normalize(x - y * dot(y, x)) } @@ -2611,6 +2787,7 @@ orthonormalize :: proc{ } +@(require_results) matrix4_orientation_f16 :: proc(normal, up: Vector3f16) -> Matrix4f16 { if all(equal(normal, up)) { return MATRIX4F16_IDENTITY @@ -2621,6 +2798,7 @@ matrix4_orientation_f16 :: proc(normal, up: Vector3f16) -> Matrix4f16 { return matrix4_rotate(angle, rotation_axis) } +@(require_results) matrix4_orientation_f32 :: proc(normal, up: Vector3f32) -> Matrix4f32 { if all(equal(normal, up)) { return MATRIX4F32_IDENTITY @@ -2631,6 +2809,7 @@ matrix4_orientation_f32 :: proc(normal, up: Vector3f32) -> Matrix4f32 { return matrix4_rotate(angle, rotation_axis) } +@(require_results) matrix4_orientation_f64 :: proc(normal, up: Vector3f64) -> Matrix4f64 { if all(equal(normal, up)) { return MATRIX4F64_IDENTITY @@ -2648,6 +2827,7 @@ matrix4_orientation :: proc{ } +@(require_results) euclidean_from_polar_f16 :: proc(polar: Vector2f16) -> Vector3f16 { latitude, longitude := polar.x, polar.y cx, sx := math.cos(latitude), math.sin(latitude) @@ -2659,6 +2839,7 @@ euclidean_from_polar_f16 :: proc(polar: Vector2f16) -> Vector3f16 { cx*cy, } } +@(require_results) euclidean_from_polar_f32 :: proc(polar: Vector2f32) -> Vector3f32 { latitude, longitude := polar.x, polar.y cx, sx := math.cos(latitude), math.sin(latitude) @@ -2670,6 +2851,7 @@ euclidean_from_polar_f32 :: proc(polar: Vector2f32) -> Vector3f32 { cx*cy, } } +@(require_results) euclidean_from_polar_f64 :: proc(polar: Vector2f64) -> Vector3f64 { latitude, longitude := polar.x, polar.y cx, sx := math.cos(latitude), math.sin(latitude) @@ -2688,6 +2870,7 @@ euclidean_from_polar :: proc{ } +@(require_results) polar_from_euclidean_f16 :: proc(euclidean: Vector3f16) -> Vector3f16 { n := length(euclidean) tmp := euclidean / n @@ -2700,6 +2883,7 @@ polar_from_euclidean_f16 :: proc(euclidean: Vector3f16) -> Vector3f16 { xz_dist, } } +@(require_results) polar_from_euclidean_f32 :: proc(euclidean: Vector3f32) -> Vector3f32 { n := length(euclidean) tmp := euclidean / n @@ -2712,6 +2896,7 @@ polar_from_euclidean_f32 :: proc(euclidean: Vector3f32) -> Vector3f32 { xz_dist, } } +@(require_results) polar_from_euclidean_f64 :: proc(euclidean: Vector3f64) -> Vector3f64 { n := length(euclidean) tmp := euclidean / n |