Skip to content

Commit 47d7d93

Browse files
fix(ui): float input precision
Determine the "base" step for floats. If no `multipleOf` is provided, the "base" step is `undefined`, meaning the float can have any number of decimal places. The UI library does its own step constrains though and is rounding to 3 decimal places. Probably need to update the logic in the UI library to have truly arbitrary precision for float fields.
1 parent 0e17950 commit 47d7d93

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/FloatField/useFloatField.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export const useFloatField = (
3737
return fieldTemplate.multipleOf;
3838
}, [fieldTemplate.multipleOf, overrideStep]);
3939

40+
const baseStep = useMemo(() => {
41+
if (isNil(fieldTemplate.multipleOf)) {
42+
return undefined;
43+
}
44+
return fieldTemplate.multipleOf;
45+
}, [fieldTemplate.multipleOf]);
46+
4047
const min = useMemo(() => {
4148
let min = -NUMPY_RAND_MAX;
4249

@@ -67,8 +74,8 @@ export const useFloatField = (
6774

6875
const constrainValue = useCallback(
6976
(v: number) =>
70-
constrainNumber(v, { min, max, step: step }, { min: overrideMin, max: overrideMax, step: overrideStep }),
71-
[max, min, overrideMax, overrideMin, overrideStep, step]
77+
constrainNumber(v, { min, max, step: baseStep }, { min: overrideMin, max: overrideMax, step: overrideStep }),
78+
[max, min, overrideMax, overrideMin, overrideStep, baseStep]
7279
);
7380

7481
const onChange = useCallback(

invokeai/frontend/web/src/features/nodes/util/constrainNumber.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PartialDeep } from 'type-fest';
22

3-
type NumberConstraints = { min: number; max: number; step: number };
3+
type NumberConstraints = { min: number; max: number; step?: number };
44

55
/**
66
* Constrain a number to a range and round to the nearest multiple of a given value.

0 commit comments

Comments
 (0)