task(H5): polygon area calculation - shoelace polygonArea, formatArea with quadratic scaling, measure-area tool, properties panel area display
This commit is contained in:
@@ -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)} m²`;
|
||||
default:
|
||||
return `${mmSquared.toFixed(0)} mm²`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user