Skip to content

Commit

Permalink
Fix negative height and widths
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaitanLyss committed Jul 30, 2024
1 parent 740b024 commit ca8ccb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@selenite/commons",
"version": "0.16.0",
"version": "0.16.1",
"scripts": {
"dev": "npm run wasm && vite dev",
"wasm": "wasm-pack build ./selenite-commons-rs --target web",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/html.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export namespace Rect {

res.x = a.x;
res.y = a.y;
res.width = b.x - a.x;
res.height = b.y - a.y;
res.width = Math.max(b.x - a.x, 0);
res.height = Math.max(b.y - a.y, 0);
}
return res;
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/utils/html.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, assert, it } from 'vitest';
import { describe, expect, it } from 'vitest';
import { Rect } from './html.svelte';

describe('Rect', () => {
Expand All @@ -16,6 +16,12 @@ describe('Rect', () => {
const res = Rect.intersection(rect1, rect2, rect3);
expect(res).toEqual(new Rect(7, 5, 3, 5));
})
it('should handle cases with no intersection', () => {
const rect1 = new Rect(5, 5, 5, 5);
const rect2 = new Rect(-5, -5, 1, 1);
const res = Rect.intersection(rect1, rect2);
expect(res).toEqual(new Rect(5, 5, 0, 0));
})
});

describe('union', () => {
Expand Down

0 comments on commit ca8ccb8

Please sign in to comment.