-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vectors): add new bvec ops & types, update readme
- add `every` / `some` unary ops - add `logicAndN` / `logicOrN`
- Loading branch information
1 parent
1c9906f
commit 931ee43
Showing
7 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MultiBVecOpRoV } from "./api"; | ||
import { vop } from "./internal/vop"; | ||
|
||
/** | ||
* Returns returns true if all vector components in `v` are truthy. | ||
* | ||
* @param v | ||
*/ | ||
export const every: MultiBVecOpRoV<boolean> = vop(); | ||
|
||
every.default((v) => { | ||
for (let i = v.length; --i >= 0; ) { | ||
if (!v[i]) return false; | ||
} | ||
return true; | ||
}); | ||
|
||
export const every2 = every.add(2, (a) => a[0] && a[1]); | ||
export const every3 = every.add(3, (a) => a[0] && a[1] && a[2]); | ||
export const every4 = every.add(4, (a) => a[0] && a[1] && a[2] && a[3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { BVecOpVV, MultiBVecOpVV } from "./api"; | ||
import { defOp } from "./internal/codegen"; | ||
import { MATH } from "./internal/templates"; | ||
import { | ||
BVecOpVN, | ||
BVecOpVV, | ||
MultiBVecOpVN, | ||
MultiBVecOpVV | ||
} from "./api"; | ||
import { ARGS_VN, defOp } from "./internal/codegen"; | ||
import { MATH, MATH_N } from "./internal/templates"; | ||
|
||
export const [logicAnd, logicAnd2, logicAnd3, logicAnd4] = defOp< | ||
MultiBVecOpVV, | ||
BVecOpVV | ||
>(MATH("&&")); | ||
|
||
export const [logicAndN, logicAndN2, logicAndN3, logicAndN4] = defOp< | ||
MultiBVecOpVN, | ||
BVecOpVN | ||
>(MATH_N("&&"), ARGS_VN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { BVecOpVV, MultiBVecOpVV } from "./api"; | ||
import { defOp } from "./internal/codegen"; | ||
import { MATH } from "./internal/templates"; | ||
import { | ||
BVecOpVN, | ||
BVecOpVV, | ||
MultiBVecOpVN, | ||
MultiBVecOpVV | ||
} from "./api"; | ||
import { ARGS_VN, defOp } from "./internal/codegen"; | ||
import { MATH, MATH_N } from "./internal/templates"; | ||
|
||
export const [logicOr, logicOr2, logicOr3, logicOr4] = defOp< | ||
MultiBVecOpVV, | ||
BVecOpVV | ||
>(MATH("||")); | ||
|
||
export const [logicOrN, logicOrN2, logicOrN3, logicOrN4] = defOp< | ||
MultiBVecOpVN, | ||
BVecOpVN | ||
>(MATH_N("||"), ARGS_VN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { MultiBVecOpRoV } from "./api"; | ||
import { vop } from "./internal/vop"; | ||
|
||
/** | ||
* Returns returns true if at least one vector component in `v` is | ||
* truthy. | ||
* | ||
* @param v | ||
*/ | ||
export const some: MultiBVecOpRoV<boolean> = vop(); | ||
|
||
some.default((v) => { | ||
for (let i = v.length; --i >= 0; ) { | ||
if (v[i]) return true; | ||
} | ||
return false; | ||
}); | ||
|
||
export const some2 = some.add(2, (a) => a[0] || a[1]); | ||
export const some3 = some.add(3, (a) => a[0] || a[1] || a[2]); | ||
export const some4 = some.add(4, (a) => a[0] || a[1] || a[2] || a[3]); |