From e32ae96305afb44f00487c39b863da6497104471 Mon Sep 17 00:00:00 2001 From: nuintun Date: Sat, 16 Mar 2024 23:41:37 +0800 Subject: [PATCH] feat: Update finder pattern group --- .../core/src/detector/FinderPatternGroup.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/core/src/detector/FinderPatternGroup.ts b/packages/core/src/detector/FinderPatternGroup.ts index 19aa9c33..2e821edc 100644 --- a/packages/core/src/detector/FinderPatternGroup.ts +++ b/packages/core/src/detector/FinderPatternGroup.ts @@ -103,20 +103,6 @@ export class FinderPatternGroup { #patterns: OrderedPatterns; #moduleSizes?: ModuleSizeGroup; - static #calculateArea(finderPatternGroup: FinderPatternGroup): number { - const [topLeft, topRight, bottomLeft] = finderPatternGroup.#patterns; - const bottomRight = FinderPatternGroup.bottomRight(finderPatternGroup); - - if (finderPatternGroup.#area == null) { - const s1 = calculateTriangleArea(topLeft, topRight, bottomRight); - const s2 = calculateTriangleArea(bottomRight, bottomLeft, topLeft); - - finderPatternGroup.#area = s1 + s2; - } - - return finderPatternGroup.#area; - } - public static moduleSizes(finderPatternGroup: FinderPatternGroup): ModuleSizeGroup { if (finderPatternGroup.#moduleSizes == null) { const matrix = finderPatternGroup.#matrix; @@ -150,7 +136,7 @@ export class FinderPatternGroup { } public static contains(finderPatternGroup: FinderPatternGroup, pattern: Pattern): boolean { - const area = FinderPatternGroup.#calculateArea(finderPatternGroup); + const area = finderPatternGroup.#calculateArea(); const [topLeft, topRight, bottomLeft] = finderPatternGroup.#patterns; const bottomRight = FinderPatternGroup.bottomRight(finderPatternGroup); const s1 = calculateTriangleArea(topLeft, topRight, pattern); @@ -186,6 +172,20 @@ export class FinderPatternGroup { public get bottomLeft(): Pattern { return this.#patterns[2]; } + + #calculateArea(): number { + const [topLeft, topRight, bottomLeft] = this.#patterns; + const bottomRight = FinderPatternGroup.bottomRight(this); + + if (this.#area == null) { + const s1 = calculateTriangleArea(topLeft, topRight, bottomRight); + const s2 = calculateTriangleArea(bottomRight, bottomLeft, topLeft); + + this.#area = s1 + s2; + } + + return this.#area; + } } export function calculateTopLeftAngle({ topLeft, topRight, bottomLeft }: FinderPatternGroup): number {