task(H5): polygon area calculation - shoelace polygonArea, formatArea with quadratic scaling, measure-area tool, properties panel area display

This commit is contained in:
Agent Zero
2026-08-29 03:09:35 +02:00
parent 21e18b81d8
commit b210ccc5b8
5 changed files with 254 additions and 3 deletions
@@ -588,3 +588,19 @@ export function distance(p1: { x: number; y: number }, p2: { x: number; y: numbe
export function angleBetween(p1: { x: number; y: number }, p2: { x: number; y: number }): number {
return (Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180) / Math.PI;
}
/**
* Fläche eines Polygons via Shoelace-Formel (Task H5).
* Absolutwert — Uhrzeigersinn und gegen Uhrzeigersinn ergeben dasselbe.
* Weniger als 3 Punkte oder kollineare Punkte → 0.
*/
export function polygonArea(pts: Array<{ x: number; y: number }>): number {
if (!Array.isArray(pts) || pts.length < 3) return 0;
let sum = 0;
for (let i = 0; i < pts.length; i++) {
const a = pts[i];
const b = pts[(i + 1) % pts.length];
sum += a.x * b.y - b.x * a.y;
}
return Math.abs(sum / 2);
}