From 235001c347447d5f5eb1cde96f72e4266e67eb53 Mon Sep 17 00:00:00 2001 From: Olivier Louvignes Date: Thu, 16 Nov 2023 20:38:54 +0100 Subject: [PATCH 1/2] feat(typescript): add generics to src/random functions to properly infer TypedArray --- packages/maath/src/random/index.ts | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/maath/src/random/index.ts b/packages/maath/src/random/index.ts index 01a54ac..e808aef 100644 --- a/packages/maath/src/random/index.ts +++ b/packages/maath/src/random/index.ts @@ -143,11 +143,11 @@ const defaultSphere = { // random on surface of sphere // - https://twitter.com/fermatslibrary/status/1430932503578226688 // - https://mathworld.wolfram.com/SpherePointPicking.html -export function onSphere( - buffer: TypedArray, +export function onSphere( + buffer: T, sphere?: Sphere, rng: Generator = defaultGen -) { +): T { const { radius, center } = { ...defaultSphere, ...sphere, @@ -169,11 +169,11 @@ export function onSphere( } // from "Another Method" https://datagenetics.com/blog/january32020/index.html -export function inSphere( - buffer: TypedArray, +export function inSphere( + buffer: T, sphere?: Sphere, rng: Generator = defaultGen -) { +): T { const { radius, center } = { ...defaultSphere, ...sphere, @@ -213,11 +213,11 @@ const defaultCircle = { }; // random circle https://stackoverflow.com/a/50746409 -export function inCircle( - buffer: TypedArray, +export function inCircle( + buffer: T, circle?: Circle, rng: Generator = defaultGen -): TypedArray { +): T { const { radius, center } = { ...defaultCircle, ...circle, @@ -234,11 +234,11 @@ export function inCircle( return buffer; } -export function onCircle( - buffer: TypedArray, +export function onCircle( + buffer: T, circle?: Circle, rng: Generator = defaultGen -) { +): T { const { radius, center } = { ...defaultCircle, ...circle, @@ -287,22 +287,22 @@ export function inRect( return buffer; } -export function onRect( - buffer: TypedArray, +export function onRect( + buffer: T, rect?: Rect, rng: Generator = defaultGen -) { +): T { return buffer; } /*** * [3D] Box */ -export function inBox( - buffer: TypedArray, +export function inBox( + buffer: T, box?: Box, rng: Generator = defaultGen -) { +): T { const { sides, center } = { ...defaultBox, ...box, @@ -331,11 +331,11 @@ const defaultBox = { center: [0, 0, 0], }; -export function onBox( - buffer: TypedArray, +export function onBox( + buffer: T, box?: Box, rng: Generator = defaultGen -) { +): T { const { sides, center } = { ...defaultBox, ...box, From aa4a1baa025d9af6a0ace87c8f36ab975734cd26 Mon Sep 17 00:00:00 2001 From: Olivier Louvignes Date: Thu, 16 Nov 2023 21:59:45 +0100 Subject: [PATCH 2/2] feat(npm): add changeset --- .changeset/nice-chefs-greet.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nice-chefs-greet.md diff --git a/.changeset/nice-chefs-greet.md b/.changeset/nice-chefs-greet.md new file mode 100644 index 0000000..bff2832 --- /dev/null +++ b/.changeset/nice-chefs-greet.md @@ -0,0 +1,5 @@ +--- +"maath": patch +--- + +Added generics to src/random functions to properly infer TypedArray