@esmirnov.ai/sperm-lab 0.0.0-stage → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eduard Smirnov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,189 @@
1
- # Temporary Holding Version
1
+ # Sperm Lab
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Explore sperm movement, anatomy, and DNA in one live sample.
4
+ Combine 12 independent factor controls.
5
+ Make a current with the mouse.
6
+ Select a cell to inspect its head, midpiece, tail, and DNA.
7
+
8
+ [Open the live lab](https://esmirnov.ai/sperm-lab/) · [Source code](https://github.com/eduard-s/sperm-lab) · [npm package](https://www.npmjs.com/package/@esmirnov.ai/sperm-lab)
9
+
10
+ The package includes a TypeScript simulation and a React component.
11
+ The component runs in the browser without a backend.
12
+ The headless simulation does not need React.
13
+
14
+ ## Install
15
+
16
+ Use Node.js 22.12 or a later version for the development tools.
17
+ The React component supports React 18.2 through React 19.
18
+
19
+ ```sh
20
+ npm install @esmirnov.ai/sperm-lab
21
+ ```
22
+
23
+ ```tsx
24
+ import { SpermLab } from "@esmirnov.ai/sperm-lab";
25
+ import "@esmirnov.ai/sperm-lab/styles.css";
26
+
27
+ export default function App() {
28
+ return <SpermLab seed={42} count={48} initialFactors={{ smoking: 0.5, heat: 0.3 }} />;
29
+ }
30
+ ```
31
+
32
+ For Next.js, put the component inside a client component.
33
+ Import the stylesheet from your page or layout.
34
+
35
+ ```tsx
36
+ "use client";
37
+
38
+ import { SpermLab } from "@esmirnov.ai/sperm-lab";
39
+
40
+ export default function Lab() {
41
+ return <SpermLab />;
42
+ }
43
+ ```
44
+
45
+ ## Explore the lab
46
+
47
+ 1. Adjust a factor slider.
48
+ 2. Combine more factors in the same sample.
49
+ 3. Drag across the sample to make a current.
50
+ 4. Select Explore to follow a swimmer and examine its details.
51
+ 5. Use the DNA view to reveal hidden damage.
52
+ 6. Use the prepared morphology sample to find different cell forms.
53
+
54
+ All 12 factor sliders remain visible.
55
+ Each slider has its own value and explanation.
56
+ The sample can show forward movement, slow movement, circles, and immobility.
57
+ Cell traits include head shapes, multiple tails, midpiece differences, and red DNA fragmentation marks.
58
+
59
+ The lab separates movement, vitality, shape, and DNA damage.
60
+ An immotile sperm can be alive.
61
+ Typical shape and forward movement do not prove that DNA is intact.
62
+
63
+ ## Live cell inspection
64
+
65
+ Defects appear in the live sample as cells move.
66
+ Select Explore to follow a swimmer without a context menu.
67
+ Select a visible head, midpiece, or tail to inspect its cell.
68
+ The detail popup tracks the selected cell.
69
+ It shows movement, vitality, head shape, tail shape, midpiece traits, and DNA integrity.
70
+ The popup keeps the sample interactive.
71
+
72
+ Press Escape to dismiss the popup.
73
+ Click empty sample space to clear the selection.
74
+ Select Full anatomy for the enlarged diagram.
75
+ Select Next swimmer to inspect another cell.
76
+ The focused canvas also accepts Enter to select the next cell.
77
+
78
+ The Concentration readout shows the current count as cells per model field.
79
+ Factor changes update the count when they prepare a new population.
80
+ This is synthetic density without clinical units or thresholds.
81
+ It does not represent a semen measurement.
82
+
83
+ ## The 12 factors
84
+
85
+ | Factor | Educational scope |
86
+ | --- | --- |
87
+ | Regular exercise | Physical activity and metabolic context. |
88
+ | High-volume running | Endurance load, energy availability, and recovery. |
89
+ | Long cycling sessions | Exercise conditions and uncertain associations. |
90
+ | Smoking | Oxidative stress and damage pathways. |
91
+ | Heavy alcohol use | Hormones and sperm production. |
92
+ | Chronic psychological stress | Possible pathways and uncertain human evidence. |
93
+ | Disrupted sleep | Observational evidence about sleep and semen quality. |
94
+ | Prolonged heat exposure | Sperm development and function. |
95
+ | Fever | Delayed changes after an illness. |
96
+ | Obesity and metabolic health | Hormones, inflammation, and metabolic context. |
97
+ | Testosterone and anabolic steroids | Suppression of signals that support sperm production. |
98
+ | Certain pesticides | Effects that depend on the chemical and exposure. |
99
+
100
+ The factor explanations include sources and evidence limits.
101
+ Regular exercise does not share a fixed damage rule with high-volume endurance exercise.
102
+
103
+ ## Common defect examples
104
+
105
+ The teaching catalog includes 18 selected morphology, injury, and movement examples.
106
+ It is not a complete list of clinical phenotypes.
107
+ It does not show how often each trait occurs in people.
108
+
109
+ | Region | Examples |
110
+ | --- | --- |
111
+ | Head | Small, large, tapered, round, and double heads. |
112
+ | Tail | Bent, coiled, short, absent, double, and triple tails. |
113
+ | Midpiece | Bent or thick outlines, plus a separate injury marker. |
114
+ | DNA | Red fragments inside a compact nucleus. |
115
+ | Movement | Slow, immotile, and nonprogressive cells. |
116
+
117
+ The React component includes the teaching population by default.
118
+ It keeps at least 18 cells so each category has a matching example.
119
+ Factor controls still affect the sample through illustrative channels.
120
+ Each cell can have more than one trait.
121
+ The catalog does not establish a lifestyle cause for a particular defect.
122
+ Use `teachingPopulation={false}` for a synthetic population without guaranteed catalog coverage.
123
+
124
+ ## Model limits
125
+
126
+ All cells, counts, and factor strengths are fictional teaching examples.
127
+ The model does not calculate personal fertility, clinical doses, or treatment outcomes.
128
+ Its movement model does not solve fluid dynamics.
129
+
130
+ Factor controls prepare one new synthetic population with the selected combination.
131
+ Motion steps do not change the shape or DNA of existing cells.
132
+ Combined controls use authored rules for possible pathways.
133
+ Those rules do not measure combined clinical risk.
134
+
135
+ Structural forms in the teaching catalog remain independent of lifestyle settings.
136
+ The model does not assign those forms to a particular lifestyle factor.
137
+ Red DNA fragmentation is a symbolic overlay inside the nucleus.
138
+ It does not depict molecular breaks visible through ordinary microscopy.
139
+
140
+ Uncertain factors use possible-pathway examples.
141
+ The example is not a measured effect size or a prediction.
142
+ Read the [model and evidence guide](docs/MODEL.md) for the scientific scope.
143
+
144
+ ## Use the headless simulation
145
+
146
+ ```ts
147
+ import {
148
+ FACTORS,
149
+ createSimulation,
150
+ stepSimulation,
151
+ getMetrics,
152
+ getTailPoints,
153
+ } from "@esmirnov.ai/sperm-lab/core";
154
+
155
+ const sample = createSimulation({
156
+ seed: 42,
157
+ count: 48,
158
+ factors: { smoking: 0.5, heat: 0.3 },
159
+ });
160
+
161
+ stepSimulation(sample, 1 / 60);
162
+ console.log(FACTORS.length, getMetrics(sample));
163
+ const tail = getTailPoints(sample.cells[0], sample.time);
164
+ ```
165
+
166
+ The core uses normalized coordinates from 0 to 1.
167
+ Use the [API guide](docs/API.md) for the exports and options.
168
+
169
+ ## Develop
170
+
171
+ ```sh
172
+ npm ci
173
+ npm run dev
174
+ ```
175
+
176
+ The standalone demo opens at `http://127.0.0.1:4177`.
177
+
178
+ ```sh
179
+ npm test
180
+ npm run typecheck
181
+ npm run test:package
182
+ npm run build:demo
183
+ ```
184
+
185
+ The package smoke tests install the archive in a clean directory.
186
+ They examine core imports without React and server output with React 18 and React 19.
187
+
188
+ Read the [release guide](docs/DEPLOY.md) before a release.
189
+ The project uses the MIT license.
@@ -0,0 +1,2 @@
1
+ /** A relative animation threshold, without clinical units. */
2
+ export declare const SLOW_SPEED_THRESHOLD = 0.035;
@@ -0,0 +1,2 @@
1
+ /** A relative animation threshold, without clinical units. */
2
+ export const SLOW_SPEED_THRESHOLD = .035;
@@ -0,0 +1,214 @@
1
+ import type { Defect, DefectId, Simulation, SpermCell } from "./types.js";
2
+ export declare const MORPHOLOGY_SOURCES: readonly [{
3
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
4
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
5
+ }, {
6
+ readonly title: "Another look at human sperm morphology";
7
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
8
+ }];
9
+ /** Common teaching categories. These examples are not a complete clinical classification. */
10
+ export declare const DEFECT_CATALOG: readonly [{
11
+ readonly id: "double-head";
12
+ readonly title: "Two heads";
13
+ readonly description: "Two heads share one connecting region in this example.";
14
+ readonly region: "head";
15
+ readonly sources: readonly [{
16
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
17
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
18
+ }, {
19
+ readonly title: "Another look at human sperm morphology";
20
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
21
+ }];
22
+ }, {
23
+ readonly id: "small-head";
24
+ readonly title: "Small head";
25
+ readonly description: "The head is smaller than the typical model outline.";
26
+ readonly region: "head";
27
+ readonly sources: readonly [{
28
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
29
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
30
+ }, {
31
+ readonly title: "Another look at human sperm morphology";
32
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
33
+ }];
34
+ }, {
35
+ readonly id: "large-head";
36
+ readonly title: "Large head";
37
+ readonly description: "The head is larger than the typical model outline.";
38
+ readonly region: "head";
39
+ readonly sources: readonly [{
40
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
41
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
42
+ }, {
43
+ readonly title: "Another look at human sperm morphology";
44
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
45
+ }];
46
+ }, {
47
+ readonly id: "tapered-head";
48
+ readonly title: "Tapered head";
49
+ readonly description: "The head narrows toward its tip.";
50
+ readonly region: "head";
51
+ readonly sources: readonly [{
52
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
53
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
54
+ }, {
55
+ readonly title: "Another look at human sperm morphology";
56
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
57
+ }];
58
+ }, {
59
+ readonly id: "round-head";
60
+ readonly title: "Round head";
61
+ readonly description: "The head has a round contour. The drawing does not determine acrosome function.";
62
+ readonly region: "head";
63
+ readonly sources: readonly [{
64
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
65
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
66
+ }, {
67
+ readonly title: "Another look at human sperm morphology";
68
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
69
+ }];
70
+ }, {
71
+ readonly id: "double-tail";
72
+ readonly title: "Two tails";
73
+ readonly description: "Two tail branches extend from one cell.";
74
+ readonly region: "tail";
75
+ readonly sources: readonly [{
76
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
77
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
78
+ }, {
79
+ readonly title: "Another look at human sperm morphology";
80
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
81
+ }];
82
+ }, {
83
+ readonly id: "triple-tail";
84
+ readonly title: "Three tails";
85
+ readonly description: "Three tail branches illustrate the multiple-tail category.";
86
+ readonly region: "tail";
87
+ readonly sources: readonly [{
88
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
89
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
90
+ }, {
91
+ readonly title: "Another look at human sperm morphology";
92
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
93
+ }];
94
+ }, {
95
+ readonly id: "bent-tail";
96
+ readonly title: "Bent tail";
97
+ readonly description: "The tail has an angular bend.";
98
+ readonly region: "tail";
99
+ readonly sources: readonly [{
100
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
101
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
102
+ }, {
103
+ readonly title: "Another look at human sperm morphology";
104
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
105
+ }];
106
+ }, {
107
+ readonly id: "coiled-tail";
108
+ readonly title: "Coiled tail";
109
+ readonly description: "The tail forms a tight curve or loop.";
110
+ readonly region: "tail";
111
+ readonly sources: readonly [{
112
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
113
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
114
+ }, {
115
+ readonly title: "Another look at human sperm morphology";
116
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
117
+ }];
118
+ }, {
119
+ readonly id: "short-tail";
120
+ readonly title: "Short tail";
121
+ readonly description: "The tail is shorter than the typical model tail.";
122
+ readonly region: "tail";
123
+ readonly sources: readonly [{
124
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
125
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
126
+ }, {
127
+ readonly title: "Another look at human sperm morphology";
128
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
129
+ }];
130
+ }, {
131
+ readonly id: "absent-tail";
132
+ readonly title: "Absent tail";
133
+ readonly description: "This example has an isolated head without an attached tail.";
134
+ readonly region: "tail";
135
+ readonly sources: readonly [{
136
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
137
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
138
+ }, {
139
+ readonly title: "Another look at human sperm morphology";
140
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
141
+ }];
142
+ }, {
143
+ readonly id: "bent-midpiece";
144
+ readonly title: "Bent midpiece";
145
+ readonly description: "The connecting region bends away from the head axis.";
146
+ readonly region: "midpiece";
147
+ readonly sources: readonly [{
148
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
149
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
150
+ }, {
151
+ readonly title: "Another look at human sperm morphology";
152
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
153
+ }];
154
+ }, {
155
+ readonly id: "thick-midpiece";
156
+ readonly title: "Thick midpiece";
157
+ readonly description: "The midpiece is wider than the typical model outline.";
158
+ readonly region: "midpiece";
159
+ readonly sources: readonly [{
160
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
161
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
162
+ }, {
163
+ readonly title: "Another look at human sperm morphology";
164
+ readonly url: "https://doi.org/10.1093/humrep/dev251";
165
+ }];
166
+ }, {
167
+ readonly id: "midpiece-damage";
168
+ readonly title: "Midpiece damage";
169
+ readonly description: "A marker identifies model cellular injury. This trait differs from midpiece shape.";
170
+ readonly region: "midpiece";
171
+ readonly sources: readonly [{
172
+ readonly title: "Sperm energy pathways and mitochondrial function";
173
+ readonly url: "https://pmc.ncbi.nlm.nih.gov/articles/PMC3501448/";
174
+ }];
175
+ }, {
176
+ readonly id: "dna-fragmentation";
177
+ readonly title: "DNA fragmentation";
178
+ readonly description: "Separated strand pieces mark model DNA damage. Their number is illustrative.";
179
+ readonly region: "dna";
180
+ readonly sources: {
181
+ title: string;
182
+ url: string;
183
+ }[];
184
+ }, {
185
+ readonly id: "slow";
186
+ readonly title: "Slow movement";
187
+ readonly description: "This cell has a low active speed in model units.";
188
+ readonly region: "movement";
189
+ readonly sources: {
190
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
191
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
192
+ }[];
193
+ }, {
194
+ readonly id: "immotile";
195
+ readonly title: "Still, but alive";
196
+ readonly description: "This cell has no active movement and remains alive in the model.";
197
+ readonly region: "movement";
198
+ readonly sources: {
199
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
200
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
201
+ }[];
202
+ }, {
203
+ readonly id: "nonprogressive";
204
+ readonly title: "Motion without progress";
205
+ readonly description: "This cell moves without a forward path.";
206
+ readonly region: "movement";
207
+ readonly sources: {
208
+ readonly title: "WHO: Laboratory manual for human semen, sixth edition";
209
+ readonly url: "https://www.who.int/publications/i/item/9789240030787";
210
+ }[];
211
+ }];
212
+ export declare function cellMatchesDefect(cell: SpermCell, id: DefectId): boolean;
213
+ export declare function getDefectCounts(world: Simulation): Record<DefectId, number>;
214
+ export declare function getCellDefects(cell: SpermCell): Defect[];
@@ -0,0 +1,57 @@
1
+ import { SLOW_SPEED_THRESHOLD } from "./constants.js";
2
+ export const MORPHOLOGY_SOURCES = [
3
+ { title: "WHO: Laboratory manual for human semen, sixth edition", url: "https://www.who.int/publications/i/item/9789240030787" },
4
+ { title: "Another look at human sperm morphology", url: "https://doi.org/10.1093/humrep/dev251" },
5
+ ];
6
+ const movementSources = [MORPHOLOGY_SOURCES[0]];
7
+ const dnaSources = [{ title: "EAU: Sperm DNA fragmentation and separate semen measures", url: "https://uroweb.org/guidelines/sexual-and-reproductive-health/chapter/male-infertility" }];
8
+ /** Common teaching categories. These examples are not a complete clinical classification. */
9
+ export const DEFECT_CATALOG = [
10
+ { id: "double-head", title: "Two heads", description: "Two heads share one connecting region in this example.", region: "head", sources: MORPHOLOGY_SOURCES },
11
+ { id: "small-head", title: "Small head", description: "The head is smaller than the typical model outline.", region: "head", sources: MORPHOLOGY_SOURCES },
12
+ { id: "large-head", title: "Large head", description: "The head is larger than the typical model outline.", region: "head", sources: MORPHOLOGY_SOURCES },
13
+ { id: "tapered-head", title: "Tapered head", description: "The head narrows toward its tip.", region: "head", sources: MORPHOLOGY_SOURCES },
14
+ { id: "round-head", title: "Round head", description: "The head has a round contour. The drawing does not determine acrosome function.", region: "head", sources: MORPHOLOGY_SOURCES },
15
+ { id: "double-tail", title: "Two tails", description: "Two tail branches extend from one cell.", region: "tail", sources: MORPHOLOGY_SOURCES },
16
+ { id: "triple-tail", title: "Three tails", description: "Three tail branches illustrate the multiple-tail category.", region: "tail", sources: MORPHOLOGY_SOURCES },
17
+ { id: "bent-tail", title: "Bent tail", description: "The tail has an angular bend.", region: "tail", sources: MORPHOLOGY_SOURCES },
18
+ { id: "coiled-tail", title: "Coiled tail", description: "The tail forms a tight curve or loop.", region: "tail", sources: MORPHOLOGY_SOURCES },
19
+ { id: "short-tail", title: "Short tail", description: "The tail is shorter than the typical model tail.", region: "tail", sources: MORPHOLOGY_SOURCES },
20
+ { id: "absent-tail", title: "Absent tail", description: "This example has an isolated head without an attached tail.", region: "tail", sources: MORPHOLOGY_SOURCES },
21
+ { id: "bent-midpiece", title: "Bent midpiece", description: "The connecting region bends away from the head axis.", region: "midpiece", sources: MORPHOLOGY_SOURCES },
22
+ { id: "thick-midpiece", title: "Thick midpiece", description: "The midpiece is wider than the typical model outline.", region: "midpiece", sources: MORPHOLOGY_SOURCES },
23
+ { id: "midpiece-damage", title: "Midpiece damage", description: "A marker identifies model cellular injury. This trait differs from midpiece shape.", region: "midpiece", sources: [{ title: "Sperm energy pathways and mitochondrial function", url: "https://pmc.ncbi.nlm.nih.gov/articles/PMC3501448/" }] },
24
+ { id: "dna-fragmentation", title: "DNA fragmentation", description: "Separated strand pieces mark model DNA damage. Their number is illustrative.", region: "dna", sources: dnaSources },
25
+ { id: "slow", title: "Slow movement", description: "This cell has a low active speed in model units.", region: "movement", sources: movementSources },
26
+ { id: "immotile", title: "Still, but alive", description: "This cell has no active movement and remains alive in the model.", region: "movement", sources: movementSources },
27
+ { id: "nonprogressive", title: "Motion without progress", description: "This cell moves without a forward path.", region: "movement", sources: movementSources },
28
+ ];
29
+ export function cellMatchesDefect(cell, id) {
30
+ switch (id) {
31
+ case "double-head": return cell.headCount === 2;
32
+ case "small-head": return cell.headShape === "small";
33
+ case "large-head": return cell.headShape === "large";
34
+ case "tapered-head": return cell.headShape === "tapered";
35
+ case "round-head": return cell.headShape === "round";
36
+ case "double-tail": return cell.tailCount === 2;
37
+ case "triple-tail": return cell.tailCount === 3;
38
+ case "bent-tail": return cell.tailShape === "bent";
39
+ case "coiled-tail": return cell.tailShape === "coiled";
40
+ case "short-tail": return cell.tailShape === "short";
41
+ case "absent-tail": return cell.tailCount === 0 || cell.tailShape === "absent";
42
+ case "bent-midpiece": return cell.midpieceShape === "bent";
43
+ case "thick-midpiece": return cell.midpieceShape === "thick";
44
+ case "midpiece-damage": return cell.midpieceDamage;
45
+ case "dna-fragmentation": return cell.dnaDamage && cell.dnaFragmentation > 0;
46
+ case "slow": return cell.alive && cell.speed > 0 && cell.speed < SLOW_SPEED_THRESHOLD;
47
+ case "immotile": return cell.alive && cell.speed === 0;
48
+ case "nonprogressive": return cell.alive && cell.speed > 0 && !cell.progressive;
49
+ default: throw new RangeError(`Unknown defect: ${String(id)}`);
50
+ }
51
+ }
52
+ export function getDefectCounts(world) {
53
+ return Object.fromEntries(DEFECT_CATALOG.map(defect => [defect.id, world.cells.filter(cell => cellMatchesDefect(cell, defect.id)).length]));
54
+ }
55
+ export function getCellDefects(cell) {
56
+ return DEFECT_CATALOG.filter(defect => cellMatchesDefect(cell, defect.id));
57
+ }