Skip to content

Commit

Permalink
feat: Update finder pattern group
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun committed Mar 16, 2024
1 parent 7817b82 commit e32ae96
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/core/src/detector/FinderPatternGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e32ae96

Please sign in to comment.