From a79717e97894b68dc0f0bbb9c01348e7a8d0f5dd Mon Sep 17 00:00:00 2001 From: Walter Perdan Date: Wed, 8 Jul 2026 14:40:34 +0200 Subject: [PATCH] refactor(pyramid_t): de-duplicate pyramid_t module (#47) Fourth de-duplication step of #47, following the established pattern. - src/pyramid_t/pyramid_t.ts: replace the type-only stub with the REAL implementation moved verbatim from the monolith (allocate, build). Only deliberate change: the constructor instantiates imgproc via direct module import instead of the jsfeatNext.imgproc static slot. - src/jsfeatNext.ts: shrinks by ~43 lines. Verified behavior-preserving: tsc --noEmit clean; npm test 57/57 (the optical_flow_lk parity test exercises pyramid_t against the oracle); UMD bundle smoke-checked (instanceof, allocate/build on a synthetic image with correct per-level dimensions). Co-Authored-By: Claude Fable 5 --- src/jsfeatNext.ts | 44 +---------------------------- src/pyramid_t/pyramid_t.ts | 58 ++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/jsfeatNext.ts b/src/jsfeatNext.ts index 00cb868..7b4e7ea 100644 --- a/src/jsfeatNext.ts +++ b/src/jsfeatNext.ts @@ -507,49 +507,7 @@ class homography2d extends motion_model { jsfeatNext.cache = cache; -jsfeatNext.pyramid_t = class pyramid_t extends jsfeatNext { - public levels: number; - public data: any; - private pyrdown: any; - - constructor(levels: number) { - super(); - this.levels = levels | 0; - this.data = new Array(levels); - const _imgproc = new jsfeatNext.imgproc(); - this.pyrdown = _imgproc.pyrdown; - } - - allocate(start_w: number, start_h: number, data_type: number): void { - let i = this.levels; - while (--i >= 0) { - this.data[i] = new matrix_t(start_w >> i, start_h >> i, data_type); - } - } - - build(input: matrix_t, skip_first_level: boolean): void { - if (typeof skip_first_level === "undefined") { - skip_first_level = true; - } - // just copy data to first level - let i = 2, - a = input, - b: any = this.data[0]; - if (!skip_first_level) { - let j = input.cols * input.rows; - while (--j >= 0) { - b.data[j] = input.data[j]; - } - } - b = this.data[1]; - this.pyrdown(a, b); - for (; i < this.levels; ++i) { - a = b; - b = this.data[i]; - this.pyrdown(a, b); - } - } -}; +jsfeatNext.pyramid_t = pyramid_t; jsfeatNext.transform = transform; diff --git a/src/pyramid_t/pyramid_t.ts b/src/pyramid_t/pyramid_t.ts index 8295464..f2ddb7c 100644 --- a/src/pyramid_t/pyramid_t.ts +++ b/src/pyramid_t/pyramid_t.ts @@ -1,8 +1,54 @@ +import jsfeatNext from "../core/core"; import { matrix_t } from "../matrix_t/matrix_t"; -export class pyramid_t { - data: any; - levels: number; - constructor(levels: number) {} - allocate(start_w: number, start_h: number, data_type: number): void {} - build(input: matrix_t, skip_first_level: boolean): void {} +import { imgproc } from "../imgproc/imgproc"; + +/** + * Real implementation, moved out of the src/jsfeatNext.ts monolith (issue #47). + * This file previously held a type-only stub — the implementation below is the + * inline code from the monolith, verbatim (the only change: the constructor + * instantiates the imgproc module directly instead of via the + * jsfeatNext.imgproc static slot). + */ +export class pyramid_t extends jsfeatNext { + public levels: number; + public data: any; + private pyrdown: any; + + constructor(levels: number) { + super(); + this.levels = levels | 0; + this.data = new Array(levels); + const _imgproc = new imgproc(); + this.pyrdown = _imgproc.pyrdown; + } + + allocate(start_w: number, start_h: number, data_type: number): void { + let i = this.levels; + while (--i >= 0) { + this.data[i] = new matrix_t(start_w >> i, start_h >> i, data_type); + } + } + + build(input: matrix_t, skip_first_level: boolean): void { + if (typeof skip_first_level === "undefined") { + skip_first_level = true; + } + // just copy data to first level + let i = 2, + a = input, + b: any = this.data[0]; + if (!skip_first_level) { + let j = input.cols * input.rows; + while (--j >= 0) { + b.data[j] = input.data[j]; + } + } + b = this.data[1]; + this.pyrdown(a, b); + for (; i < this.levels; ++i) { + a = b; + b = this.data[i]; + this.pyrdown(a, b); + } + } }