Skip to content

Commit 2469e0c

Browse files
committed
fix: resolve conversations
1 parent 8feea4d commit 2469e0c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/geometry/__tests__/getPerspectiveWarp.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ describe('error testing', () => {
226226
],
227227
{ width: 10 },
228228
);
229-
}).toThrow('Height is not defined');
229+
}).toThrow(
230+
'Invalid dimensions: `height` is missing. Either provide both width and height, or omit both to auto-calculate dimensions.',
231+
);
230232
});
231233
});

src/geometry/getPerspectiveWarp.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export type GetPerspectiveWarpData = Required<GetPerspectiveWarpOptions> & {
2323
};
2424

2525
// REFERENCES :
26-
// https://stackoverflow.com/questions/38285229/calculating-aspect-ratio-of-perspective-transform-destination-image/38402378#38402378
27-
// http://www.corrmap.com/features/homography_transformation.php
28-
// https://ags.cs.uni-kl.de/fileadmin/inf_ags/3dcv-ws11-12/3DCV_WS11-12_lec04.pdf
2926
// http://graphics.cs.cmu.edu/courses/15-463/2011_fall/Lectures/morphing.pdf
3027
/**
31-
* Returns perspective warp matrix from 4 points.
28+
* Computes a perspective transformation matrix to rectify a quadrilateral region into a rectangle.
29+
*
30+
* This function takes four corner points of a distorted quadrilateral (e.g., a document photographed at an angle) and calculates the transformation matrix needed to "unwarp" it into a rectangular image.
31+
* The output dimensions can be specified or calculated automatically based on the input geometry.
3232
* @param pts - 4 reference corners of the new image.
33-
* @param options - PerspectiveWarpOptions
33+
* @param options - PerspectiveWarpOptions.
3434
* @returns - Matrix from 4 points.
3535
*/
3636
export function getPerspectiveWarp(
@@ -58,7 +58,10 @@ export function getPerspectiveWarp(
5858
Math.max(distance2Points(tl, bl), distance2Points(tr, br)),
5959
);
6060
} else {
61-
throw new Error(`${width ? 'Height' : 'Width'} is not defined.`);
61+
throw new Error(
62+
`Invalid dimensions: ${width ? '`height`' : '`width`'} is missing. ` +
63+
`Either provide both width and height, or omit both to auto-calculate dimensions.`,
64+
);
6265
}
6366

6467
const [x1, y1] = [0, 0];

0 commit comments

Comments
 (0)