From bf3ec38a381be5552cf1e03fc39a7c9a4f233092 Mon Sep 17 00:00:00 2001 From: treeform Date: Sat, 20 Sep 2025 16:58:54 -0700 Subject: [PATCH 1/2] Some style improvements. --- src/vmath.nim | 9 +++++---- src/vmath/macroswizzle.nim | 3 +++ src/vmath/swizzle.nim | 2 +- tests/bench.nim | 4 +++- tests/bench_isNan.nim | 4 +++- tests/bench_raytracer.nim | 4 +++- tests/bench_raytracer_glm.nim | 4 +++- tests/bench_rep.nim | 3 ++- tests/bench_swizzle.nim | 4 +++- tests/test.nim | 4 +++- tools/genswizzle.nim | 5 +++-- 11 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/vmath.nim b/src/vmath.nim index 371d1d2..2f0e926 100644 --- a/src/vmath.nim +++ b/src/vmath.nim @@ -30,7 +30,8 @@ float64 double DVec2 DVec3 DVec4 DMat3 DMat4 DQuat ]## -import macros, math, strutils +import + std/[macros, math, strutils] export math except isNan {.push inline.} @@ -389,8 +390,8 @@ type proc `~=`*[T: SomeFloat](a, b: T): bool = ## Almost equal. - const epsilon = 0.000001 - abs(a - b) <= epsilon + const Epsilon = 0.000001 + abs(a - b) <= Epsilon proc between*[T](value, min, max: T): bool = ## Returns true if value is between min and max or equal to them. @@ -411,7 +412,7 @@ proc fract*[T: SomeFloat](v: T): T = result = abs(v) result = result - trunc(result) -proc fractional*[T: SomeFloat](v: T): T {.deprecated: "Use frac() insetad"} = +proc fractional*[T: SomeFloat](v: T): T {.deprecated: "Use fract() instead"} = ## Returns fractional part of a number. fract(v) diff --git a/src/vmath/macroswizzle.nim b/src/vmath/macroswizzle.nim index 9b7908c..77d4a37 100644 --- a/src/vmath/macroswizzle.nim +++ b/src/vmath/macroswizzle.nim @@ -1,4 +1,7 @@ +import + std/[macros] + {.experimental: "dotOperators".} proc num(letter: char, fields: NimNode): int = ## Given a swizzle character gives back the location number. diff --git a/src/vmath/swizzle.nim b/src/vmath/swizzle.nim index 5cadb31..cfe355d 100644 --- a/src/vmath/swizzle.nim +++ b/src/vmath/swizzle.nim @@ -1,4 +1,4 @@ -# Generated by tools/gensswizzle - don't edit manually. +# Generated by tools/genswizzle - don't edit manually. # 1 x rgba proc r*[T](a: GVec234[T]): T = a[0] diff --git a/tests/bench.nim b/tests/bench.nim index f9d3e51..9e13bb8 100644 --- a/tests/bench.nim +++ b/tests/bench.nim @@ -1,4 +1,6 @@ -import benchy, vmath +import + benchy, + vmath # TODO: I don't trust these simple benchmarks, make a better test. # echo "new vmath" diff --git a/tests/bench_isNan.nim b/tests/bench_isNan.nim index 8a5aedd..77eace4 100644 --- a/tests/bench_isNan.nim +++ b/tests/bench_isNan.nim @@ -1,4 +1,6 @@ -import benchy, vmath +import + benchy, + vmath proc isNaNSlow(f: SomeFloat): bool = ## Returns true if number is a NaN. diff --git a/tests/bench_raytracer.nim b/tests/bench_raytracer.nim index 5ef9d41..f70ef6f 100644 --- a/tests/bench_raytracer.nim +++ b/tests/bench_raytracer.nim @@ -2,7 +2,9 @@ ## MIT License ## Copyright (c) 2021 Edin Omeragic -import benchy, chroma, math, pixie, vmath +import + std/math, + benchy, chroma, pixie, vmath {.push inline, noinit, checks: off.} diff --git a/tests/bench_raytracer_glm.nim b/tests/bench_raytracer_glm.nim index 646d586..64d0e72 100644 --- a/tests/bench_raytracer_glm.nim +++ b/tests/bench_raytracer_glm.nim @@ -2,7 +2,9 @@ ## MIT License ## Copyright (c) 2021 Edin Omeragic -import benchy, chroma, math, glm +import + std/math, + benchy, chroma, glm from pixie import Image, newImage, writeFile, dataIndex type Vec3 = glm.Vec3[float32] diff --git a/tests/bench_rep.nim b/tests/bench_rep.nim index 031f016..a82d09d 100644 --- a/tests/bench_rep.nim +++ b/tests/bench_rep.nim @@ -1,4 +1,5 @@ -import benchy +import + benchy type Vec3Obj = object diff --git a/tests/bench_swizzle.nim b/tests/bench_swizzle.nim index d7169ae..01aa8f5 100644 --- a/tests/bench_swizzle.nim +++ b/tests/bench_swizzle.nim @@ -1,4 +1,6 @@ -import benchy, vmath +import + benchy, + vmath block: var diff --git a/tests/test.nim b/tests/test.nim index db40f24..7f57da1 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -1,4 +1,6 @@ -import random, vmath +import + std/random, + vmath randomize(1234) diff --git a/tools/genswizzle.nim b/tools/genswizzle.nim index 2d15235..7e108bb 100644 --- a/tools/genswizzle.nim +++ b/tools/genswizzle.nim @@ -1,10 +1,11 @@ -import strformat +import + std/strformat var swizzles = @["xyzw", "rgba", "stpq"] code = "" -code.add "# Generated by tools/gensswizzle - don't edit manually.\n" +code.add "# Generated by tools/genswizzle - don't edit manually.\n" for swizzle in swizzles[1 .. ^1]: code.add "\n# 1 x " & swizzle & "\n" From a9ea9ffdbb48c5c26c48ec79e910e3a4cbb05a62 Mon Sep 17 00:00:00 2001 From: treeform Date: Sat, 20 Sep 2025 17:02:18 -0700 Subject: [PATCH 2/2] read me fixs --- README.md | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 57fd69b..58b046e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Supports c, cpp and js backend. ## About -Your one stop shop for vector math routines for 2d and 3d graphics. +Your one stop shop for vector math routines for 2D and 3D graphics. * Pure Nim with no dependencies. * Very similar to GLSL Shader Language with extra stuff. @@ -42,7 +42,7 @@ float64 | double | DVec2 | DVec3 | DVec4 | DMat3 | DMat4 | DQuat | ## 2D & 3D matrix math -You can combine and create 2d and 3d matrices by passing 2d or 3d vectors to matrix functions: +You can combine and create 2D and 3D matrices by passing 2D or 3D vectors to matrix functions: ```nim let mat2d = translate(vec2(10, 20)) * rotate(45.toRadians) * scale(vec2(2)) @@ -63,15 +63,14 @@ quat(1.0, 2.0, 3.0, 4.0) ~= quat(1.0, 2.0, 3.0, 4.0) * `between` - Returns true if value is between min and max or equal to them. * `sign` - Returns the sign of a number, -1 or 1. -* `quantize` - Makes v be a multiple of n. Rounding to integer quantize by 1.0. -* `fractional` - Returns fractional part of a number. 3.14 -> 0.14 +* `quantize` - Makes v be a multiple of n. Rounding to integer quantizes by 1.0. * `lerp` - Interpolates value between a and b. ## Angle functions -* `fixAngle` - Make angle be from -PI to PI radians. -* `angleBetween` - Find the angle between angle a and angle b. -* `turnAngle` - Move from angle a to angle b with step of v. +* `fixAngle` - Makes angle be from -PI to PI radians. +* `angleBetween` - Finds the angle between angle a and angle b. +* `turnAngle` - Moves from angle a to angle b with step of v. ## Vector and matrix representation and benchmarks. @@ -93,11 +92,11 @@ vmathObjArrayBased ................ 73.968 ms 74.292 ms ±0.631 x100 ## Zmod - GLSL mod -GLSL uses a different type of float point mod. Because mod is a Nim keyword please use `zmod` when you need GLSL `mod` behavior. +GLSL uses a different type of float point mod. Because mod is a Nim keyword, please use `zmod` when you need GLSL `mod` behavior. ## Coordinate System -Right-hand z-forward coordinate system +Right-hand Z-forward coordinate system This is the same system used in the GLTF file format. @@ -124,18 +123,18 @@ OpenGL/GLSL/vmath vs Math/Specification notation: ``` # 1.x.x to 2.0.0 vmath breaking changes: -* New right-hand-z-forward cordate system and functions that care about -coordinate system where moved there. -* deprecated `lookAt()` please use `toAngles()`/`fromAngles()` instead. -* deprecated `fractional()` use `frac()` instead. +* New right-hand-Z-forward coordinate system and functions that care about +coordinate system were moved there. +* Deprecated `lookAt()`, please use `toAngles()`/`fromAngles()` instead. +* Deprecated `fractional()`, use `frac()` instead. # 0.x.x to 1.0.0 vmath breaking changes: -* `vec3(v)` no longer works please use `vec3(v.x, v.y, 0)` instead. -* `vec3(v, 0)` no longer works please use `vec3(v.x, v.y, 0)` instead. -* `2 * v` no longer works due to more vec types please use `v * 2` instead. +* `vec3(v)` no longer works, please use `vec3(v.x, v.y, 0)` instead. +* `vec3(v, 0)` no longer works, please use `vec3(v.x, v.y, 0)` instead. +* `2 * v` no longer works due to more vec types, please use `v * 2` instead. * `m[15]` no longer works because matrices are now m[x, y]. -* Concept of 3x3 rotation 3d matrix was removed. +* Concept of 3x3 rotation 3D matrix was removed. * `angleBetween` got renamed to `angle(a, b)` * `scaleMat` got renamed to `scale(v)` * `rotationMat3` got renamed to `rotate(x)`