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
+25
View File
@@ -92,3 +92,28 @@ export function formatInputValue(
return `${(mm / 1000).toFixed(3)}`;
}
}
/**
* Format a raw world-unit squared area value (Task H5).
* @param rawSquared squared world-units (e.g. polygonArea result)
* @param unit target display unit
* @param scaleFactor world-units → mm conversion (like formatDistance)
* @returns formatted string like "5000 mm²", "50.0 cm²", "5.00 m²"
*/
export function formatArea(
rawSquared: number,
unit: UnitType,
scaleFactor: number = 1,
): string {
const mmSquared = rawSquared * scaleFactor * scaleFactor;
switch (unit) {
case 'mm':
return `${mmSquared.toFixed(0)} mm²`;
case 'cm':
return `${(mmSquared / 100).toFixed(1)} cm²`;
case 'm':
return `${(mmSquared / 1000000).toFixed(2)}`;
default:
return `${mmSquared.toFixed(0)} mm²`;
}
}