🎥 Make videos programmatically with React
Limit dragged UV coordinate decimals (#8405)
Jonny Burger921ebca88fd6
diff --git a/packages/studio/src/components/SelectedOutlineUvControls.tsx b/packages/studio/src/components/SelectedOutlineUvControls.tsxindex bb33021f97..bf4d97db56 100644--- a/packages/studio/src/components/SelectedOutlineUvControls.tsx+++ b/packages/studio/src/components/SelectedOutlineUvControls.tsx@@ -7,6 +7,7 @@ import {getUvCoordinateForPoint,getUvHandleConnectionLines,getUvHandlePosition,+ roundUvCoordinate,tuplesEqual,type SelectedOutlineUvHandle,type UvCoordinate,@@ -96,8 +97,11 @@ const SelectedUvHandleCircle: React.FC<{event: pointerEvent,rect: svgRect,});- const nextValue = constrainUv(- getUvCoordinateForPoint(outline.points, point),+ const nextValue = roundUvCoordinate(+ constrainUv(+ getUvCoordinateForPoint(outline.points, point),+ handle.fieldSchema,+ ),handle.fieldSchema,);lastValue = nextValue;diff --git a/packages/studio/src/components/selected-outline-uv.ts b/packages/studio/src/components/selected-outline-uv.tsindex e60b260c65..395c4c42a2 100644--- a/packages/studio/src/components/selected-outline-uv.ts+++ b/packages/studio/src/components/selected-outline-uv.ts@@ -16,6 +16,10 @@ import {type OutlinePoint,type SelectedOutline,} from './selected-outline-geometry';+import {+ getTimelineDisplayDecimalPlaces,+ roundToDecimalPlaces,+} from './Timeline/timeline-field-utils';export type UvCoordinate = readonly [number, number];@@ -286,6 +290,21 @@ export function constrainUv(return [clamp(value[0], min, max), clamp(value[1], min, max)];}+export function roundUvCoordinate(+ value: UvCoordinate,+ schema: UvCoordinateFieldSchema,+): UvCoordinate {+ const decimalPlaces = getTimelineDisplayDecimalPlaces({+ defaultDecimalPlaces: 3,+ step: schema.step,+ });++ return [+ roundToDecimalPlaces(value[0], decimalPlaces),+ roundToDecimalPlaces(value[1], decimalPlaces),+ ];+}+export const getSelectedUvHandles = ({propStatuses,clientId,diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex 29162c29e4..d84916fc12 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -15,6 +15,7 @@ import {getUvCoordinateForPoint,getUvHandleConnectionLines,getUvHandlePosition,+ roundUvCoordinate,} from '../components/selected-outline-uv';import {applySelectedOutlineDragAxisLock,@@ -1404,6 +1405,26 @@ test('UV coordinate constraints still clamp to schema min and max', () => {).toEqual([0, 1]);});+test('UV coordinates round to three decimals by default when dragging', () => {+ expect(+ roundUvCoordinate([0.123456, 0.987654], {+ type: 'uv-coordinate',+ default: [0.5, 0.5],+ step: 0.01,+ }),+ ).toEqual([0.123, 0.988]);+});++test('UV coordinates allow finer configured steps when dragging', () => {+ expect(+ roundUvCoordinate([0.123456, 0.987654], {+ type: 'uv-coordinate',+ default: [0.5, 0.5],+ step: 0.0001,+ }),+ ).toEqual([0.1235, 0.9877]);+});+test('SVG viewport outline points are projected through the screen CTM', () => {const points = getTransformedSvgViewportPoints({viewport: {x: 0, y: 0, width: 100, height: 50},