Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/core/interaction/clip-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import type { Size, Vector } from "@layouts/geometry";
export const INTERACTION_CONSTANTS = {
/** Minimum clip dimension in pixels */
MIN_DIMENSION: 50,
/** Maximum clip dimension in pixels */
MAX_DIMENSION: 3840
/** Maximum clip width in pixels */
MAX_WIDTH: 3840,
/** Maximum clip height in pixels */
MAX_HEIGHT: 2160
} as const;

// ─── Types ────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -222,8 +224,8 @@ export function calculateEdgeResize(direction: EdgeDirection, delta: Vector, ori
*/
export function clampDimensions(width: number, height: number): { width: number; height: number } {
return {
width: Math.max(INTERACTION_CONSTANTS.MIN_DIMENSION, Math.min(width, INTERACTION_CONSTANTS.MAX_DIMENSION)),
height: Math.max(INTERACTION_CONSTANTS.MIN_DIMENSION, Math.min(height, INTERACTION_CONSTANTS.MAX_DIMENSION))
width: Math.max(INTERACTION_CONSTANTS.MIN_DIMENSION, Math.min(width, INTERACTION_CONSTANTS.MAX_WIDTH)),
height: Math.max(INTERACTION_CONSTANTS.MIN_DIMENSION, Math.min(height, INTERACTION_CONSTANTS.MAX_HEIGHT))
};
}

Expand Down
15 changes: 8 additions & 7 deletions tests/clip-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ describe("ClipInteractionSystem", () => {
expect(INTERACTION_CONSTANTS.MIN_DIMENSION).toBe(50);
});

it("has correct maximum dimension", () => {
expect(INTERACTION_CONSTANTS.MAX_DIMENSION).toBe(3840);
it("has correct maximum dimensions", () => {
expect(INTERACTION_CONSTANTS.MAX_WIDTH).toBe(3840);
expect(INTERACTION_CONSTANTS.MAX_HEIGHT).toBe(2160);
});
});

Expand Down Expand Up @@ -425,15 +426,15 @@ describe("ClipInteractionSystem", () => {
it("clamps width above maximum", () => {
const result = clampDimensions(5000, 100);

expect(result.width).toBe(INTERACTION_CONSTANTS.MAX_DIMENSION);
expect(result.width).toBe(INTERACTION_CONSTANTS.MAX_WIDTH);
expect(result.height).toBe(100);
});

it("clamps height above maximum", () => {
const result = clampDimensions(100, 5000);

expect(result.width).toBe(100);
expect(result.height).toBe(INTERACTION_CONSTANTS.MAX_DIMENSION);
expect(result.height).toBe(INTERACTION_CONSTANTS.MAX_HEIGHT);
});

it("preserves valid dimensions", () => {
Expand All @@ -447,17 +448,17 @@ describe("ClipInteractionSystem", () => {
const result = clampDimensions(30, 5000);

expect(result.width).toBe(INTERACTION_CONSTANTS.MIN_DIMENSION);
expect(result.height).toBe(INTERACTION_CONSTANTS.MAX_DIMENSION);
expect(result.height).toBe(INTERACTION_CONSTANTS.MAX_HEIGHT);
});

it("handles boundary values", () => {
const minResult = clampDimensions(50, 50);
expect(minResult.width).toBe(50);
expect(minResult.height).toBe(50);

const maxResult = clampDimensions(3840, 3840);
const maxResult = clampDimensions(3840, 2160);
expect(maxResult.width).toBe(3840);
expect(maxResult.height).toBe(3840);
expect(maxResult.height).toBe(2160);
});
});

Expand Down
Loading