Commit 3b9eb95
feat(api)!: singleton modules, shared cache, direct namespace export (#41)
BREAKING CHANGE: restores original jsfeat's calling convention (ships as
0.9.0). Designed via /brainstorming with every decision user-confirmed;
full migration guide in docs/migration-0.9.md.
What changed:
- The 14 algorithm modules (imgproc, math, matmath, linalg, transform,
fast_corners, yape, yape06, orb, optical_flow_lk, motion_estimator,
affine2d, homography2d, cache) are now SINGLETON INSTANCES on the
namespace: jsfeatNext.imgproc.grayscale(...) -- no `new`. The classes
themselves are untouched (kept verbatim so the parity suite still
guards unmodified algorithm code); the aggregator instantiates them
once at load.
- ONE shared buffer pool: src/core/core.ts now creates a module-level
shared_cache that every module binds to, replacing the per-instance
30-buffer/76.8KB pools. jsfeatNext.cache is that pool instance
(get_buffer/put_buffer), matching original jsfeat's global
jsfeat.cache -- which was never a constructor.
- The jsfeatNext.jsfeatNext double namespace is gone: src/index.ts
default-exports the namespace directly (UMD global and ESM default
are now the namespace itself).
- Data-structure constructors unchanged: matrix_t, keypoint_t,
pyramid_t, ransac_params_t are still `new`ed, as in original jsfeat.
Ground truth for the design (verified against inspirit/jsfeat source,
not assumed): jsfeat's own modules are singletons even when stateful
(fast_corners keeps closure-level _threshold and is configured once via
set_threshold(20) at load); imgproc borrows from the single global
jsfeat.cache -- per-instance pools defeated the cache's purpose and
made new-in-a-frame-loop silently reallocate pools every frame.
Also in this change:
- tests: parity suite converted to the new convention (63 tests total,
including a new tests/api-shape.test.ts pinning the namespace shape,
singleton identity, shared-cache identity and constructor surface)
- examples: all 22 converted and validated against the new bundle (the
5 non-camera ones executed in Node, all 22 static-scanned, and
browser-tested by the user); browser.html's cache usage rewritten (it
used new jsfeat.cache()+allocate(), which original jsfeat never
supported either); grayscale example simplified to direct
jsfeatNext.imgproc.grayscale() calls
- docs: docs/migration-0.9.md (full old->new mapping + motivation),
README quick start, AGENTS.md architecture/gotchas (also refreshed
for the post-#47 layout), CLAUDE.md notes (were stale re: monolith
and 'no tests'), copilot-instructions, audit doc Axis 2 marked
resolved with a status column on the severity table
- dist/ + types/ rebuilt and committed IN THIS PR (deviation from the
source-only convention, at user request: an API-breaking change with
a stale committed bundle made local example testing confusing)
Verified: tsc --noEmit clean; npm test 63/63; prettier clean; UMD and
ESM bundle shapes checked (no double namespace, singletons callable,
shared pool public); examples validated against the new bundle and
manually tested in a browser by the user.
Closes #41.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 5159e61 commit 3b9eb95
45 files changed
Lines changed: 633 additions & 438 deletions
File tree
- .github
- dist
- docs
- examples
- src
- cache
- core
- tests
- parity
- types/src
- cache
- core
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
36 | 33 | | |
37 | 34 | | |
38 | 35 | | |
| |||
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
47 | | - | |
| 44 | + | |
48 | 45 | | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | 51 | | |
54 | | - | |
55 | | - | |
| 52 | + | |
| 53 | + | |
56 | 54 | | |
57 | 55 | | |
58 | 56 | | |
59 | | - | |
60 | | - | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 23 | + | |
28 | 24 | | |
29 | | - | |
| 25 | + | |
30 | 26 | | |
31 | 27 | | |
32 | | - | |
| 28 | + | |
33 | 29 | | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 33 | + | |
41 | 34 | | |
42 | 35 | | |
43 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
| |||
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
76 | | - | |
| 73 | + | |
77 | 74 | | |
78 | 75 | | |
79 | 76 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments