16 lines
798 B
TypeScript
16 lines
798 B
TypeScript
import { PRECISION } from './limits';
|
|
|
|
export const mm = (value: number) =>
|
|
Number.isFinite(value)
|
|
? new Intl.NumberFormat('en-GB', { maximumFractionDigits: 1 }).format(value)
|
|
: '—';
|
|
/** Round cutting marks up without letting floating-point noise add a half millimetre. */
|
|
export const cutLength = (value: number) => Math.ceil(value * 2 - PRECISION.roundingNoise) / 2 + 0;
|
|
/** An exact-fit stock edge or remnant needs no rounded-up preparation cut. */
|
|
export const cutMm = (value: number, available = Infinity) =>
|
|
mm(Math.min(cutLength(value), available));
|
|
export const area = (value: number) =>
|
|
new Intl.NumberFormat('en-GB', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
|
|
value / 1e6,
|
|
);
|
|
export const degree = (value: number) => `${mm(Math.abs(value))}°`;
|