Skip to content

Commit

Permalink
Ensure rect never has fractional pixel values
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyward committed Mar 11, 2023
1 parent ace7b11 commit 3ba6284
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/urlBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ describe("buildRect", () => {
)
).toThrowError()
})

it("rounds values", () => {
expect(
buildRect(
{ width: 30, height: 90 },
{ top: 0.15, left: 0.1, right: 0.25, bottom: 0.05 }
)
).toBe("3,14,20,72")
})
})

describe("buildQueryString", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/urlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ export const buildRect = (
const { width, height } = croppedImageSize(dimensions, crop)

return [
crop.left * dimensions.width,
crop.top * dimensions.height,
Math.round(crop.left * dimensions.width),
Math.round(crop.top * dimensions.height),
width,
height,
].join(",")
Expand Down

0 comments on commit 3ba6284

Please sign in to comment.