aboutsummaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2024-09-24 02:32:06 -0700
committerColin Davidson <colrdavidson@gmail.com>2024-09-24 02:32:06 -0700
commitf3ab14b8ccb45d0fef8a96937635bdf0943ce7d6 (patch)
tree1309d7c797117463996a84522ef3d1c9713a286c /core/math
parent99938c7d4fb26d43a07dd4b8f4f00ab87e67e73f (diff)
parentf7d74ff3a8596efef67d151ffb758ed085e94be0 (diff)
Merge branch 'master' into macharena
Diffstat (limited to 'core/math')
-rw-r--r--core/math/big/common.odin2
-rw-r--r--core/math/big/tune.odin2
-rw-r--r--core/math/linalg/glsl/linalg_glsl.odin70
-rw-r--r--core/math/linalg/hlsl/linalg_hlsl.odin148
-rw-r--r--core/math/math.odin12
-rw-r--r--core/math/math_basic.odin2
-rw-r--r--core/math/math_basic_js.odin2
-rw-r--r--core/math/noise/internal.odin2
-rw-r--r--core/math/noise/opensimplex2.odin6
9 files changed, 126 insertions, 120 deletions
diff --git a/core/math/big/common.odin b/core/math/big/common.odin
index fabf39520..5428b00ee 100644
--- a/core/math/big/common.odin
+++ b/core/math/big/common.odin
@@ -195,7 +195,7 @@ Error_String :: #sparse[Error]string{
}
Primality_Flag :: enum u8 {
- Blum_Blum_Shub = 0, // Make prime congruent to 3 mod 4
+ Blum_Blum_Shub = 0, // Make prime congruent to 3 mod 4
Safe = 1, // Make sure (p-1)/2 is prime as well (implies .Blum_Blum_Shub)
Second_MSB_On = 3, // Make the 2nd highest bit one
}
diff --git a/core/math/big/tune.odin b/core/math/big/tune.odin
index 5938dafde..eab36b951 100644
--- a/core/math/big/tune.odin
+++ b/core/math/big/tune.odin
@@ -7,7 +7,7 @@
The code started out as an idiomatic source port of libTomMath, which is in the public domain, with thanks.
*/
-//+build ignore
+#+build ignore
package math_big
import "core:time"
diff --git a/core/math/linalg/glsl/linalg_glsl.odin b/core/math/linalg/glsl/linalg_glsl.odin
index 363a95887..5444f89e2 100644
--- a/core/math/linalg/glsl/linalg_glsl.odin
+++ b/core/math/linalg/glsl/linalg_glsl.odin
@@ -22,9 +22,9 @@ F32_EPSILON :: 1e-7
F64_EPSILON :: 1e-15
// Odin matrices are stored internally as Column-Major, which matches OpenGL/GLSL by default
-mat2 :: distinct matrix[2, 2]f32
-mat3 :: distinct matrix[3, 3]f32
-mat4 :: distinct matrix[4, 4]f32
+mat2 :: matrix[2, 2]f32
+mat3 :: matrix[3, 3]f32
+mat4 :: matrix[4, 4]f32
mat2x2 :: mat2
mat3x3 :: mat3
mat4x4 :: mat4
@@ -33,52 +33,52 @@ mat4x4 :: mat4
// but they match how GLSL and OpenGL defines them in name
// Odin: matrix[R, C]f32
// GLSL: matCxR
-mat3x2 :: distinct matrix[2, 3]f32
-mat4x2 :: distinct matrix[2, 4]f32
-mat2x3 :: distinct matrix[3, 2]f32
-mat4x3 :: distinct matrix[3, 4]f32
-mat2x4 :: distinct matrix[4, 2]f32
-mat3x4 :: distinct matrix[4, 3]f32
+mat3x2 :: matrix[2, 3]f32
+mat4x2 :: matrix[2, 4]f32
+mat2x3 :: matrix[3, 2]f32
+mat4x3 :: matrix[3, 4]f32
+mat2x4 :: matrix[4, 2]f32
+mat3x4 :: matrix[4, 3]f32
-vec2 :: distinct [2]f32
-vec3 :: distinct [3]f32
-vec4 :: distinct [4]f32
+vec2 :: [2]f32
+vec3 :: [3]f32
+vec4 :: [4]f32
-ivec2 :: distinct [2]i32
-ivec3 :: distinct [3]i32
-ivec4 :: distinct [4]i32
+ivec2 :: [2]i32
+ivec3 :: [3]i32
+ivec4 :: [4]i32
-uvec2 :: distinct [2]u32
-uvec3 :: distinct [3]u32
-uvec4 :: distinct [4]u32
+uvec2 :: [2]u32
+uvec3 :: [3]u32
+uvec4 :: [4]u32
-bvec2 :: distinct [2]bool
-bvec3 :: distinct [3]bool
-bvec4 :: distinct [4]bool
+bvec2 :: [2]bool
+bvec3 :: [3]bool
+bvec4 :: [4]bool
-quat :: distinct quaternion128
+quat :: quaternion128
// Double Precision (f64) Floating Point Types
-dmat2 :: distinct matrix[2, 2]f64
-dmat3 :: distinct matrix[3, 3]f64
-dmat4 :: distinct matrix[4, 4]f64
+dmat2 :: matrix[2, 2]f64
+dmat3 :: matrix[3, 3]f64
+dmat4 :: matrix[4, 4]f64
dmat2x2 :: dmat2
dmat3x3 :: dmat3
dmat4x4 :: dmat4
-dmat3x2 :: distinct matrix[2, 3]f64
-dmat4x2 :: distinct matrix[2, 4]f64
-dmat2x3 :: distinct matrix[3, 2]f64
-dmat4x3 :: distinct matrix[3, 4]f64
-dmat2x4 :: distinct matrix[4, 2]f64
-dmat3x4 :: distinct matrix[4, 3]f64
+dmat3x2 :: matrix[2, 3]f64
+dmat4x2 :: matrix[2, 4]f64
+dmat2x3 :: matrix[3, 2]f64
+dmat4x3 :: matrix[3, 4]f64
+dmat2x4 :: matrix[4, 2]f64
+dmat3x4 :: matrix[4, 3]f64
-dvec2 :: distinct [2]f64
-dvec3 :: distinct [3]f64
-dvec4 :: distinct [4]f64
+dvec2 :: [2]f64
+dvec3 :: [3]f64
+dvec4 :: [4]f64
-dquat :: distinct quaternion256
+dquat :: quaternion256
cos :: proc{
cos_f32,
diff --git a/core/math/linalg/hlsl/linalg_hlsl.odin b/core/math/linalg/hlsl/linalg_hlsl.odin
index f5e8bf147..a89fdddd3 100644
--- a/core/math/linalg/hlsl/linalg_hlsl.odin
+++ b/core/math/linalg/hlsl/linalg_hlsl.odin
@@ -21,89 +21,89 @@ LN10 :: 2.30258509299404568401799145468436421
FLOAT_EPSILON :: 1e-7
DOUBLE_EPSILON :: 1e-15
-// Aliases (not distinct) of types
+// Aliases (not distict) of types
float :: f32
double :: f64
int :: builtin.i32
uint :: builtin.u32
// Odin matrices are stored internally as Column-Major, which matches the internal layout of HLSL by default
-float1x1 :: distinct matrix[1, 1]float
-float2x2 :: distinct matrix[2, 2]float
-float3x3 :: distinct matrix[3, 3]float
-float4x4 :: distinct matrix[4, 4]float
-
-float1x2 :: distinct matrix[1, 2]float
-float1x3 :: distinct matrix[1, 3]float
-float1x4 :: distinct matrix[1, 4]float
-float2x1 :: distinct matrix[2, 1]float
-float2x3 :: distinct matrix[2, 3]float
-float2x4 :: distinct matrix[2, 4]float
-float3x1 :: distinct matrix[3, 1]float
-float3x2 :: distinct matrix[3, 2]float
-float3x4 :: distinct matrix[3, 4]float
-float4x1 :: distinct matrix[4, 1]float
-float4x2 :: distinct matrix[4, 2]float
-float4x3 :: distinct matrix[4, 3]float
-
-float2 :: distinct [2]float
-float3 :: distinct [3]float
-float4 :: distinct [4]float
-
-int2 :: distinct [2]int
-int3 :: distinct [3]int
-int4 :: distinct [4]int
-
-uint2 :: distinct [2]uint
-uint3 :: distinct [3]uint
-uint4 :: distinct [4]uint
-
-bool2 :: distinct [2]bool
-bool3 :: distinct [3]bool
-bool4 :: distinct [4]bool
+float1x1 :: matrix[1, 1]float
+float2x2 :: matrix[2, 2]float
+float3x3 :: matrix[3, 3]float
+float4x4 :: matrix[4, 4]float
+
+float1x2 :: matrix[1, 2]float
+float1x3 :: matrix[1, 3]float
+float1x4 :: matrix[1, 4]float
+float2x1 :: matrix[2, 1]float
+float2x3 :: matrix[2, 3]float
+float2x4 :: matrix[2, 4]float
+float3x1 :: matrix[3, 1]float
+float3x2 :: matrix[3, 2]float
+float3x4 :: matrix[3, 4]float
+float4x1 :: matrix[4, 1]float
+float4x2 :: matrix[4, 2]float
+float4x3 :: matrix[4, 3]float
+
+float2 :: [2]float
+float3 :: [3]float
+float4 :: [4]float
+
+int2 :: [2]int
+int3 :: [3]int
+int4 :: [4]int
+
+uint2 :: [2]uint
+uint3 :: [3]uint
+uint4 :: [4]uint
+
+bool2 :: [2]bool
+bool3 :: [3]bool
+bool4 :: [4]bool
// Double Precision (double) Floating Point Types
-double1x1 :: distinct matrix[1, 1]double
-double2x2 :: distinct matrix[2, 2]double
-double3x3 :: distinct matrix[3, 3]double
-double4x4 :: distinct matrix[4, 4]double
-
-double1x2 :: distinct matrix[1, 2]double
-double1x3 :: distinct matrix[1, 3]double
-double1x4 :: distinct matrix[1, 4]double
-double2x1 :: distinct matrix[2, 1]double
-double2x3 :: distinct matrix[2, 3]double
-double2x4 :: distinct matrix[2, 4]double
-double3x1 :: distinct matrix[3, 1]double
-double3x2 :: distinct matrix[3, 2]double
-double3x4 :: distinct matrix[3, 4]double
-double4x1 :: distinct matrix[4, 1]double
-double4x2 :: distinct matrix[4, 2]double
-double4x3 :: distinct matrix[4, 3]double
-
-double2 :: distinct [2]double
-double3 :: distinct [3]double
-double4 :: distinct [4]double
-
-
-int1x1 :: distinct matrix[1, 1]int
-int2x2 :: distinct matrix[2, 2]int
-int3x3 :: distinct matrix[3, 3]int
-int4x4 :: distinct matrix[4, 4]int
-
-int1x2 :: distinct matrix[1, 2]int
-int1x3 :: distinct matrix[1, 3]int
-int1x4 :: distinct matrix[1, 4]int
-int2x1 :: distinct matrix[2, 1]int
-int2x3 :: distinct matrix[2, 3]int
-int2x4 :: distinct matrix[2, 4]int
-int3x1 :: distinct matrix[3, 1]int
-int3x2 :: distinct matrix[3, 2]int
-int3x4 :: distinct matrix[3, 4]int
-int4x1 :: distinct matrix[4, 1]int
-int4x2 :: distinct matrix[4, 2]int
-int4x3 :: distinct matrix[4, 3]int
+double1x1 :: matrix[1, 1]double
+double2x2 :: matrix[2, 2]double
+double3x3 :: matrix[3, 3]double
+double4x4 :: matrix[4, 4]double
+
+double1x2 :: matrix[1, 2]double
+double1x3 :: matrix[1, 3]double
+double1x4 :: matrix[1, 4]double
+double2x1 :: matrix[2, 1]double
+double2x3 :: matrix[2, 3]double
+double2x4 :: matrix[2, 4]double
+double3x1 :: matrix[3, 1]double
+double3x2 :: matrix[3, 2]double
+double3x4 :: matrix[3, 4]double
+double4x1 :: matrix[4, 1]double
+double4x2 :: matrix[4, 2]double
+double4x3 :: matrix[4, 3]double
+
+double2 :: [2]double
+double3 :: [3]double
+double4 :: [4]double
+
+
+int1x1 :: matrix[1, 1]int
+int2x2 :: matrix[2, 2]int
+int3x3 :: matrix[3, 3]int
+int4x4 :: matrix[4, 4]int
+
+int1x2 :: matrix[1, 2]int
+int1x3 :: matrix[1, 3]int
+int1x4 :: matrix[1, 4]int
+int2x1 :: matrix[2, 1]int
+int2x3 :: matrix[2, 3]int
+int2x4 :: matrix[2, 4]int
+int3x1 :: matrix[3, 1]int
+int3x2 :: matrix[3, 2]int
+int3x4 :: matrix[3, 4]int
+int4x1 :: matrix[4, 1]int
+int4x2 :: matrix[4, 2]int
+int4x3 :: matrix[4, 3]int
cos :: proc{
cos_float,
diff --git a/core/math/math.odin b/core/math/math.odin
index 957e1672b..0e21afa67 100644
--- a/core/math/math.odin
+++ b/core/math/math.odin
@@ -406,6 +406,12 @@ remap :: proc "contextless" (old_value, old_min, old_max, new_min, new_max: $T)
}
@(require_results)
+remap_clamped :: proc "contextless" (old_value, old_min, old_max, new_min, new_max: $T) -> (x: T) where intrinsics.type_is_numeric(T), !intrinsics.type_is_array(T) {
+ remapped := #force_inline remap(old_value, old_min, old_max, new_min, new_max)
+ return clamp(remapped, new_min, new_max)
+}
+
+@(require_results)
wrap :: proc "contextless" (x, y: $T) -> T where intrinsics.type_is_numeric(T), !intrinsics.type_is_array(T) {
tmp := mod(x, y)
return y + tmp if tmp < 0 else tmp
@@ -438,11 +444,11 @@ bias :: proc "contextless" (t, b: $T) -> T where intrinsics.type_is_numeric(T) {
return t / (((1/b) - 2) * (1 - t) + 1)
}
@(require_results)
-gain :: proc "contextless" (t, g: $T) -> T where intrinsics.type_is_numeric(T) {
+gain :: proc "contextless" (t, g: $T) -> T where intrinsics.type_is_float(T) {
if t < 0.5 {
- return bias(t*2, g)*0.5
+ return bias(t*2, g) * 0.5
}
- return bias(t*2 - 1, 1 - g)*0.5 + 0.5
+ return bias(t*2 - 1, 1 - g) * 0.5 + 0.5
}
diff --git a/core/math/math_basic.odin b/core/math/math_basic.odin
index 041efd272..2584df71f 100644
--- a/core/math/math_basic.odin
+++ b/core/math/math_basic.odin
@@ -1,4 +1,4 @@
-//+build !js
+#+build !js
package math
import "base:intrinsics"
diff --git a/core/math/math_basic_js.odin b/core/math/math_basic_js.odin
index 5b9adabcd..2604ebc8b 100644
--- a/core/math/math_basic_js.odin
+++ b/core/math/math_basic_js.odin
@@ -1,4 +1,4 @@
-//+build js
+#+build js
package math
import "base:intrinsics"
diff --git a/core/math/noise/internal.odin b/core/math/noise/internal.odin
index bd97bd45c..f75c0ee87 100644
--- a/core/math/noise/internal.odin
+++ b/core/math/noise/internal.odin
@@ -4,7 +4,7 @@
Ported from https://github.com/KdotJPG/OpenSimplex2.
Copyright 2022 Yuki2 (https://github.com/NoahR02)
*/
-//+private
+#+private
package math_noise
/*
diff --git a/core/math/noise/opensimplex2.odin b/core/math/noise/opensimplex2.odin
index d28356f2c..634c32948 100644
--- a/core/math/noise/opensimplex2.odin
+++ b/core/math/noise/opensimplex2.odin
@@ -1,8 +1,8 @@
/*
OpenSimplex2 noise implementation.
- Ported from https://github.com/KdotJPG/OpenSimplex2.
- Copyright 2022 Yuki2 (https://github.com/NoahR02)
+ Ported from [[ https://github.com/KdotJPG/OpenSimplex2 }].
+ Copyright 2022 Yuki2 [[ https://github.com/NoahR02 ]]
*/
package math_noise
@@ -177,4 +177,4 @@ noise_4d_fallback :: proc(seed: i64, coord: Vec4) -> (value: f32) {
// Get points for A4 lattice
skew := f64(SKEW_4D) * (coord.x + coord.y + coord.z + coord.w)
return _internal_noise_4d_unskewed_base(seed, coord + skew)
-} \ No newline at end of file
+}