Skip to content

Commit

Permalink
common: add polygon area
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Feb 15, 2024
1 parent b28eef9 commit 88da7fc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/objectdetector/src/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ export function normalizeBox(boundingBox: [number, number, number, number], inpu
y2 = y2 * 100 / inputDimensions[1];
return [[x, y], [x2, y], [x2, y2], [x, y2]];
}

export function polygonArea(p: Point[]): number {
let area = 0;
const n = p.length;
for (let i = 0; i < n; i++) {
const j = (i + 1) % n;
area += p[i][0] * p[j][1];
area -= p[j][0] * p[i][1];
}
return Math.abs(area / 2);
}

0 comments on commit 88da7fc

Please sign in to comment.