{"id":26607323,"url":"https://github.com/clumsycomputer/clumsy-math","last_synced_at":"2025-04-09T21:05:47.346Z","repository":{"id":50586500,"uuid":"514845443","full_name":"clumsycomputer/clumsy-math","owner":"clumsycomputer","description":"a little library of helpful math utensils 🙂","archived":false,"fork":false,"pushed_at":"2023-06-14T13:10:57.000Z","size":499,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"alpha","last_synced_at":"2025-04-09T21:05:42.580Z","etag":null,"topics":["math","typescript"],"latest_commit_sha":null,"homepage":"https://clumsy-math.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clumsycomputer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-17T13:04:02.000Z","updated_at":"2023-06-14T13:11:43.000Z","dependencies_parsed_at":"2025-03-23T23:01:26.349Z","dependency_job_id":null,"html_url":"https://github.com/clumsycomputer/clumsy-math","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clumsycomputer","download_url":"https://codeload.github.com/clumsycomputer/clumsy-math/tar.gz/refs/heads/alpha","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111982,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["math","typescript"],"created_at":"2025-03-23T22:50:38.925Z","updated_at":"2025-04-09T21:05:47.311Z","avatar_url":"https://github.com/clumsycomputer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clumsy-math\n\na math library for the clumsy and curious 🙂\n\n## installation\n\n```bash\nyarn add clumsy-math\n```\n\n## documentation\n\n- **[spacer _(concepts)_](#spacer-concepts)**\n\n- **[spacer _(encodings)_](#spacer-encodings)**\n\n- **[spacer _(functions)_](#spacer-functions)**\n\n- **[prime _(concepts)_](#prime-concepts)**\n\n- **[prime _(functions)_](#prime-functions)**\n\n- **[prime _(encodings)_](#prime-encodings)**\n\n- **[loop _(functions)_](#loop-functions)**\n\n## spacer _(concepts)_\n\n###### aligned recursive euclid spacer\n\n\u003e a recursive euclid spacer where each layer has a point at the zero slot\n\n```typescript\nconst baseEuclidMap = [true, true, false, true, false]\nconst terminalEuclidMap = [true, false, true]\nconst resultEuclidMap = [true, false, false, true, false]\n```\n\n###### basic euclid spacer\n\n\u003e a euclid spacer that has an orientation and phase of zero (default layout) (most left dense)\n\n```typescript\nconst euclidMapA = [true, true, false, true, false] // basic\nconst euclidMapB = [true, false, true, false, true] // not basic\nconst euclidMapC = [true, false, true, true, false] // not basic\n```\n\n###### component spacer\n\n\u003e a recursive euclidean spacer of a recursive euclidean spacer\n\n```typescript\nconst baseComponentMap = [true, true, false, true, false]\nconst interposedComponentMap = [true, false, false, true, false]\nconst terminalComponentMap = [true, false, false, false, false]\n```\n\n###### core euclid spacer\n\n\u003e a basic euclid spacer that is reduced to its simplest form\n\n```typescript\nconst fullEuclidMap = [true, false, true, false]\nconst coreEuclidMap = [true, false]\n```\n\n###### euclid spacer\n\n\u003e a spacer whose points are as evenly distributed as possible throughout a discrete space\n\n```typescript\nconst euclidMapA = [true, true, false, true, false]\nconst euclidMapB = [true, false, true, false, true]\nconst euclidMapC = [true, false, true, true, false]\n```\n\n###### phased recursive euclid spacer\n\n\u003e a recursive euclid spacer where all of the individual layers are phaseable\n\n```typescript\nconst baseEuclidMap = [true, true, false, true, false]\nconst terminalEuclidMap = [false, true, true]\nconst resultEuclidMap = [false, true, false, true, false]\n```\n\n###### recursive euclid spacer\n\n\u003e a spacer where euclid spacers are stacked on top of one another such that the base spacer's density / points determines the next spacer's resolution / space\n\n```typescript\nconst baseEuclidMap = [true, true, false, true, false]\nconst terminalEuclidMap = [true, true, flase]\nconst resultEuclidMap = [true, true, false, false, false]\n```\n\n###### spacer\n\n\u003e a discrete sequence / cycle of binary values (slots)\n\n```typescript\nconst spacerString = \"1010\"\nconst spacerMap = [true, false, true, false];\nconst spacer = {\n  resolution: 4,\n  points: [0, 2]\n}\n```\n\n###### spacer density\n\n\u003e the number of points in a spacer\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerPoints = [0, 1, 3]\nconst spacerDensity = 3 // spacerPoints.length\n```\n\n###### spacer group\n\n\u003e a set of aligned recursive euclidean spacers that share a static base structure and a dynamic member structure where the density structure is the same but orientations are different\n\n```typescript\nconst groupBase = [true, true, false, true, false]\nconst groupMapsA = [\n  [true, true, false, true, false],\n  [true, false, false, true, false],\n]\n```\n\n###### spacer interval\n\n\u003e starting at a base point, the distance upto the next point\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerPoints = [0, 1, 3]\nconst spacerIntervals = [1, 2, 2]\n```\n\n###### spacer lineage\n\n\u003e all spacer groups an aligned recursive euclidean spacer belongs to\n\n```typescript\nconst spacerMapA = [true, false, false, true, false]\nconst lineageMapsA = [\n  [\n    [true, true, false, false, false],\n    [true, false, false, true, false],\n    [true, false, true, false, false],\n    [true, false, false, false, true],\n    [true, false, true, false, false],\n    [true, false, false, true, false],\n  ],\n  [\n    [true, true, false, false, false],\n    [true, false, false, true, false],\n  ],\n];\n```\n\n###### spacer orientation\n\n\u003e the offset of an aligned spacer, measured in points, relative to a base spacer\n\n```typescript\nconst baseSpacerMap = [true, true, false, true, false]\nconst spacerOrientation = 2\nconst reorientedSpacerMap = [true, false, true, true, false]\n```\n\n###### spacer phase\n\n\u003e the offset of a spacer, measured in slots, relative to a base spacer\n\n```typescript\nconst baseSpacerMap = [true, true, false, true, false]\nconst spacerPhase = -1; // spacerMap.length\nconst phasedSpacerMap = [false, true, true, false, true]\n```\n\n###### spacer point\n\n\u003e the index of a slot whose value is true (1)\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerPoints = [0, 1, 3]\n```\n\n###### spacer point weight\n\n\u003e a point's corresponding slot weight\n\n```typescript\nconst spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0\nconst spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1\nconst spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0\nconst groupSlotWeights = [3, 1, 2, 2, 1];\nconst spacerPointsA = [0, 1, 3]\nconst spacerPointWeightsA = [3, 1, 2]\n```\n\n###### spacer relative point\n\n\u003e a point whose value is normalized within the range of [0, 1)\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerPoints = [0, 1, 3]\nconst relativeSpacerPoints = [0.0, 0.2, 0.6]\n```\n\n###### spacer resolution\n\n\u003e the number of slots constituting a spacer\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerResolution = 5; // spacerMap.length\n```\n\n###### spacer slot\n\n\u003e the building block of spacer\n\n```typescript\nconst spacerMap = [true, true, false, true, false]\nconst spacerSlotZero = spacerMap[0] // true\nconst spacerSlotTwo = spacerMap[2] // false\n```\n\n###### spacer slot weight\n\n\u003e the sum of points at a slot across a set of spacers with the same resolution\n\n```typescript\nconst spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0\nconst spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1\nconst spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0\nconst groupSlotWeights = [3, 1, 2, 2, 1];\nconst slotWeightZero = 3; // groupSlotWeights[0]\n```\n\n###### spacer weight\n\n\u003e the sum of a spacer's point weight\n\n```typescript\nconst spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0\nconst spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1\nconst spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0\nconst groupSlotWeights = [3, 1, 2, 2, 1];\nconst spacerPointsA = [0, 1, 3]\nconst spacerPointWeightsA = [3, 1, 2]\nconst spacerWeightA = 6 // 3 + 1 + 2\n```\n\n## spacer _(encodings)_\n\n###### AlignedEuclidSpacerLayer\n\n\u003e encoding for defining a [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure) layer's components\n\n###### AlignedRecursiveEuclidSpacer\n\n\u003e [aligned recursive euclid spacer](#aligned-recursive-euclid-spacer) as [Spacer](#spacer-1)\n\n###### AlignedRecursiveEuclidSpacerStructure\n\n\u003e ergonomic encoding for defining [aligned recursive euclid spacer](#aligned-recursive-euclid-spacer)\n\n###### AlignedSpacerStructure\n\n\u003e compressed alias for [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure)\n\n###### BasicEuclidSpacer\n\n\u003e [basic euclid spacer](#basic-euclid-spacer) as [Spacer](#spacer-1)\n\n###### CoreEuclidSpacer\n\n\u003e [core euclid spacer](#core-euclid-spacer) as [Spacer](#spacer-1)\n\n###### EuclidSpacer\n\n\u003e [euclid spacer](#euclid-spacer) as [Spacer](#spacer-1)\n\n###### EuclidSpacerMap\n\n\u003e [euclid spacer](#euclid-spacer) as [SpacerMap](#spacermap)\n\n###### PhasedEuclidSpacerLayer\n\n\u003e encoding for defining a [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure) layer's components\n\n###### PhasedRecursiveEuclidSpacer\n\n\u003e [phased recursive euclid spacer](#phased-recursive-euclid-spacer) as [Spacer](#spacer-1)\n\n###### PhasedRecursiveEuclidSpacerStructure\n\n\u003e ergonomic encoding for defining [phased recursive euclid spacer](#phased-recursive-euclid-spacer)\n\n###### PhasedSpacerStructure\n\n\u003e compressed alias for [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure)\n\n###### RecursiveEuclidSpacer\n\n\u003e [recursive euclid spacer](#recursive-euclid-spacer) as [Spacer](#spacer-1)\n\n###### RecursiveEuclidSpacerStructure\n\n\u003e useful encoding for either [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure) or [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure)\n\n###### RelativeSpacerPoint\n\n\u003e a real number in the range of [0, 1)\n\n###### Spacer\n\n\u003e defacto encoding for working with [spacer](#spacer)\n\n###### SpacerDensity\n\n\u003e an integer in the range of [0, spacerResolution]\n\n###### SpacerGroupBaseStructure\n\n\u003e encoding for defining the base structure of a [SpacerGroupStructure](#spacergroupstructure)\n\n###### SpacerGroupMemberStructure\n\n\u003e encoding for defining the member structure of a [SpacerGroupStructure](#spacergroupstructure)\n\n###### SpacerGroupStructure\n\n\u003e ergonomic encoding for defining [spacer group](#spacer-group)\n\n###### SpacerInterval\n\n\u003e an integer in the range of [1, spacerResolution]\n\n###### SpacerMap\n\n\u003e [spacer](#spacer) as Array\\\u003cboolean\\\u003e\n\n###### SpacerOrientation\n\n\u003e an integer in the range of [0, spacerDensity)\n\n###### SpacerPhase\n\n\u003e an integer in the range of (-spacerResolution, spacerResolution)\n\n###### SpacerPoint\n\n\u003e an integer in the range of [0, spacerResolution)\n\n###### SpacerPointWeight\n\n\u003e an integer in the range of [0, ∞)\n\n###### SpacerResolution\n\n\u003e an integer in the range of [1, ∞)\n\n###### SpacerSlot\n\n\u003e a boolean that's either true or false\n\n###### SpacerSlotWeight\n\n\u003e an integer in the range of [0, ∞)\n\n###### SpacerString\n\n\u003e [spacer](#spacer) as a string of 1's and 0's\n\n###### SpacerWeight\n\n\u003e an integer in the range of [0, ∞)\n\n## spacer _(functions)_\n\n###### basicEuclidSpacer\n\n\u003e great for working with euclid spacers where orientation and phase are not needed\n\n```typescript\nconst basicSpacerA = basicEuclidSpacer(5, 3)\n// basicSpacerA === [5, [0, 1, 3]]\n```\n\n###### componentSpacers\n\n\u003e great for destructuring a spacer structure into its constituent spacers\n\n```typescript\nconst componentsA = spacerComponents([5, [3, 1, 0], [2, 0, 0]])\n// const componentsA === [\n//   [5, [3, 1, 0]], // baseSpacerStructure\n//   [5, [3, 1, 0], [2, 0, 0]]\n// ]\n```\n\n###### coreEuclidMap\n\n\u003e most important spacer function, but rarely invoked by itself\n\n```typescript\nconst coreSpacerMapA = coreEuclidMap(5, 3)\n// coreSpacerMapA === [true, true, false, true, false]\n```\n\n###### coreEuclidSpacer\n\n\u003e great for working with simplified euclid spacers\n\n```typescript\nconst coreSpacerA = coreEuclidSpacer(8, 4)\n// coreSpacerA === [2, [0]]\n```\n\n###### euclidSpacer\n\n\u003e great for working with unlayered euclid spacers\n\n```typescript\nconst spacerA = euclidSpacer(5, 3, 1, 0)\n// spacerA === [5, [0, 2, 4]]\n```\n\n###### orientatedSpacer\n\n\u003e great for reorienting an aligned spacer after it's been created\n\n```typescript\nconst spacerA = spacer(5, [3, 1])\nconst spacerB = orientatedSpacer(spacerA, 1)\n// spacerB === [5, [0, 2, 3]]\n```\n\n###### phasedSpacer\n\n\u003e great for phasing a spacer after it's been created\n\n```typescript\nconst spacerA = spacer([5, [3, 1]]),\nconst  spacerB = phasedSpacer(spacerA, 1)\n// spacerB === [5, [1, 3, 4]]\n```\n\n###### relativeSpacerPoints\n\n\u003e great for normalizing spacers across different resolutions\n\n```typescript\nconst relativePointsA = relativeSpacerPoints(\n  spacer([5, [3, 1]])\n)\n// relativePointsA === [0, 0.4, 0.8]\n```\n\n###### spacer\n\n\u003e primary function for working with spacer\n\n```typescript\nconst spacerA = spacer([5, [3, 1, 0]])\n// const spacerA === [5, [0, 2, 4]]\n```\n\n###### spacerFullSlotWeights\n\n\u003e great for normalizing a spacer and it's orientations against itself\n\n```typescript\nspacerFullSlotWeights(\n  spacer([5, [3, 0]]),\n) // [3, 1, 2, 2, 1]\n```\n\n###### spacerGroup\n\n\u003e great for defining a set of related spacers at a desired altitude / scope\n\n```typescript\nconst groupA = spacerGroup([[5], [3]])\n// groupA === [\n//   [5, [3, 0]],\n//   [5, [3, 1]],\n//   [5, [3, 2]]\n// ]\n```\n\n###### spacerGroupId\n\n\u003e great for logging and working with datasets of spacer groups\n\n```typescript\nconst groupIdA = spacerGroupId([[5, [3, 1]], [2]])\n// groupIdA === \"group___5__3_1___2\"\n```\n\n###### spacerId\n\n\u003e great for logging and working with datasets of spacer structures\n\n```typescript\nconst idA = spacerId([5, [3, 1, 0]])\n// const idA === \"phased__5__3_1_0\"\n```\n\n###### spacerIntervals\n\n\u003e great for making calculations between spacer points\n\n```typescript\nconst intervalsA = spacerIntervals(\n  spacer([5, [3, 1]])\n)\n// intervalsA === [2, 2, 1]\n```\n\n###### spacerLineage\n\n\u003e great for getting related spacers at a given altitude / scope / lineageIndex\n\n```typescript\nconst lineageA = spacerLineage([5, [3, 1], [2, 0]])\n// lineageA === [\n//   [[5], [3, 2]], // high-altitude or zoomed-out\n//   [[5, [3, 1]], [2]] // low-altitude or zoomed-in\n// ]\n```\n\n###### spacerPointWeights\n\n\u003e great for working with a spacer's points in the context of a set of spacers\n\n```typescript\nconst pointWeightsA = spacerPointWeights(\n  spacerSlotWeights([\n    spacer([5, [3, 0]]),\n    spacer([5, [3, 1]]),\n    spacer([5, [3, 2]])\n  ]),\n  spacer([5, [3, 2]])\n)\n// const pointWeightsA === [3, 2, 2]\n```\n\n###### spacerSlotWeights\n\n\u003e great for understanding point distribution across a set of spacers\n\n```typescript\nconst slotWeightsA = spacerSlotWeights([\n  spacer([5, [3, 0]]),\n  spacer([5, [3, 1]]),\n  spacer([5, [3, 2]])\n])\n// slotWeightsA === [3, 1, 2, 2, 1]\n```\n\n###### spacerString\n\n\u003e great for logging and visualizing short spacers\n\n```typescript\nconst stringA = spacerString(\n  spacer([5, [3, 1]])\n)\n// stringA === \"10101\"\n```\n\n###### spacerWeight\n\n\u003e great for differentiating a spacer against a set of spacers\n\n```typescript\nconst weightA = spacerWeight(\n  spacerSlotWeights([\n    spacer([5, [3, 0]]),\n    spacer([5, [3, 1]]),\n    spacer([5, [3, 2]])\n  ]),\n  spacer([5, [3, 2]])\n)\n// const weightA === 7\n```\n\n## prime _(concepts)_\n\n###### prime\n\n\u003e a natural number greater than one whose factors are one and itself\n\n```typescript\nconst prime = 5 // 5 * 1\nconst notPrime = 4 // 2 * 2, 4 * 1\n```\n\n###### prime container\n\n\u003e a natural number where both it's immediate neighbors are prime\n\n```typescript\nconst containerA = 6 // 5 \u0026 7\nconst containerB = 12 // 11 \u0026 13\n```\n\n###### prime tribe\n\n\u003e the set of primes bounded by adjacent prime containers\n\n## prime _(functions)_\n\n###### isPrime\n\n\u003e use for checking if some number is prime\n\n```typescript\nisPrime(4) // false\nisPrime(5) // true\n```\n\n###### isPrimeContainer\n\n\u003e use for checking if some number is a prime container\n\n```typescript\nisPrimeContainer(4) // true\nisPrimeContainer(5) // false\n```\n\n###### nearestPrimes\n\n\u003e great for rounding some number to nearest prime\n\n```typescript\nnearestPrimes(1) // [null, 2]\nnearestPrimes(3) // [3, 3]\nnearestPrimes(8) // [7, 11]\n```\n\n###### prime\n\n\u003e use for getting prime by index\n\n```typescript\nprime(0) // 2\nprime(1) // 3\nprime(2) // 5\n```\n\n###### primeContainer\n\n\u003e great for organizing primes and who knows what else\n\n```typescript\nprimeContainer(0) // 4\nprimeContainer(1) // 6\nprimeContainer(2) // 12\n```\n\n###### primeContainerSequence\n\n\u003e use for working with the first n prime containers\n\n```typescript\nprimeContainerSequence(2) // [4, 6, 12]\n```\n\n###### primeSequence\n\n\u003e use for working with the first n primes\n\n```typescript\nprimeSeqeunce(2) // [2, 3, 5]\n```\n\n###### primeSequenceInclusive\n\n\u003e use for getting all primes less than some number\n\n```typescript\nprimeSequenceInclusive(6) // [2, 3, 5]\n```\n\n###### primeSequenceInRange\n\n\u003e great for working with primes between containers\n\n```typescript\nprimeSequenceInRange(12, 18) // [13, 17]\n```\n\n###### primeTribe\n\n\u003e great for working with primes that share bounds and analyzing prime distribution\n\n```typescript\nprimeTribe(0) // [5]\nprimeTribe(1) // [7, 11]\nprimeTribe(2) // [13, 17]\n```\n\n###### tribeSpacer\n\n\u003e great for analyzing the layout of a prime tribe\n\n```typescript\ntribeSpacer(2) // [6, [0, 4]]\ntribeSpacer(3) // [12, [0, 4, 10]]\ntribeSpacer(4) // [12, [0, 6, 10]]\n```\n\n## prime _(encodings)_\n\n###### Prime\n\n\u003e [prime](#prime) as number\n\n###### PrimeContainer\n\n\u003e [prime container](#prime-container) as number\n\n## loop _(functions)_\n\n###### loopCosine\n\n\u003e great for generating cosine waves of a loop\n\n###### loopPendulum\n\n\u003e great for generating pendulum waves of a loop\n\n###### loopPoint\n\n\u003e great for rendering geometry and synthesizing waves\n\n###### loopSine\n\n\u003e great for generating sine waves of a loop\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclumsycomputer%2Fclumsy-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclumsycomputer%2Fclumsy-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclumsycomputer%2Fclumsy-math/lists"}