-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathgizmo-snap-preferences.ts
More file actions
40 lines (35 loc) · 1.14 KB
/
gizmo-snap-preferences.ts
File metadata and controls
40 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** Minimum snap step (two-decimal increments cannot be smaller than 0.01). */
export const gizmoSnapMinStep = 0.01;
const snapDecimalRoundFactor = 100;
export interface IGizmoSnapPreferences {
translationEnabled: boolean;
translationStep: number;
rotationEnabled: boolean;
rotationStepDegrees: number;
scaleEnabled: boolean;
scaleStep: number;
}
/**
* Snap steps are stored and applied with at most two decimal places.
*/
export function roundGizmoSnapSteps(prefs: IGizmoSnapPreferences): IGizmoSnapPreferences {
const roundStep = (value: number): number => {
const clampedLow = Math.max(gizmoSnapMinStep, value);
const rounded = Math.round(clampedLow * snapDecimalRoundFactor) / snapDecimalRoundFactor;
return Math.max(gizmoSnapMinStep, rounded);
};
return {
...prefs,
translationStep: roundStep(prefs.translationStep),
rotationStepDegrees: roundStep(prefs.rotationStepDegrees),
scaleStep: roundStep(prefs.scaleStep),
};
}
export const defaultGizmoSnapPreferences: IGizmoSnapPreferences = {
translationEnabled: false,
translationStep: 1,
rotationEnabled: false,
rotationStepDegrees: 15,
scaleEnabled: false,
scaleStep: 0.25,
};