From 71990982c69a2d119221d0ffe23679c695c816c5 Mon Sep 17 00:00:00 2001 From: Kurogoma Date: Mon, 8 Jan 2024 21:42:26 +0900 Subject: [PATCH] Refactor clampInputParam --- interactive/src/controlParam/param.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/interactive/src/controlParam/param.ts b/interactive/src/controlParam/param.ts index feebd8f..eb89b1c 100644 --- a/interactive/src/controlParam/param.ts +++ b/interactive/src/controlParam/param.ts @@ -15,27 +15,19 @@ export const inputParamNames: (keyof InputParam)[] = [ "bottomBearing", ]; -function limVal( - map: InputParam, - name: keyof InputParam, - lim: number, - isMax = false -) { - map[name] = isMax ? Math.min(map[name], lim) : Math.max(map[name], lim); -} export function clampInputParam( { ...map }: InputParam, name?: keyof InputParam -) { - if (name) limVal(map, name, 1); +): InputParam { + if (name) map[name] = Math.max(map[name], 1); if (name === "stem_interval") { - limVal(map, "weight_x", map.stem_interval, true); + map.weight_x = Math.min(map.weight_x, map.stem_interval); } else { - limVal(map, "stem_interval", map.weight_x); + map.stem_interval = Math.max(map.stem_interval, map.weight_x); } const ipdifxy = map.stem_interval + Math.abs(map.weight_x - map.weight_y); - limVal(map, "xHeight", 2 * ipdifxy + map.weight_y); - limVal(map, "ascender", ipdifxy + map.xHeight); - limVal(map, "descender", ipdifxy); + map.xHeight = Math.max(map.xHeight, 2 * ipdifxy + map.weight_y); + map.ascender = Math.max(map.ascender, ipdifxy + map.xHeight); + map.descender = Math.max(map.descender, ipdifxy); return map; }