|
| 1 | +import { expect } from '@open-wc/testing'; |
| 2 | +import { isWithinRect } from './math.js'; |
| 3 | + |
| 4 | +describe('isWithinRect', () => { |
| 5 | + const rect = new DOMRect(0, 0, 100, 100); |
| 6 | + |
| 7 | + it('should return true if the point is within the rectangle', () => { |
| 8 | + expect(isWithinRect(50, 50, rect)).to.be.true; |
| 9 | + expect(isWithinRect(1, 1, rect)).to.be.true; |
| 10 | + expect(isWithinRect(99, 99, rect)).to.be.true; |
| 11 | + }); |
| 12 | + |
| 13 | + it('should return false if the point is outside the rectangle', () => { |
| 14 | + expect(isWithinRect(0, 0, rect)).to.be.false; |
| 15 | + expect(isWithinRect(100, 100, rect)).to.be.false; |
| 16 | + expect(isWithinRect(101, 50, rect)).to.be.false; |
| 17 | + expect(isWithinRect(50, 101, rect)).to.be.false; |
| 18 | + expect(isWithinRect(-1, 50, rect)).to.be.false; |
| 19 | + expect(isWithinRect(50, -1, rect)).to.be.false; |
| 20 | + }); |
| 21 | + |
| 22 | + it('should return false if the point is on the "border" of the rectangle', () => { |
| 23 | + expect(isWithinRect(0, 0, rect)).to.be.false; |
| 24 | + expect(isWithinRect(100, 100, rect)).to.be.false; |
| 25 | + expect(isWithinRect(100, 0, rect)).to.be.false; |
| 26 | + expect(isWithinRect(0, 100, rect)).to.be.false; |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return true if the point is within the expanded rectangle', () => { |
| 30 | + expect(isWithinRect(110, 80, rect, 20)).to.be.true; |
| 31 | + expect(isWithinRect(80, 110, rect, 20)).to.be.true; |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return false if the point is outside the expanded rectangle', () => { |
| 35 | + expect(isWithinRect(130, 80, rect, 20)).to.be.false; |
| 36 | + expect(isWithinRect(80, 130, rect, 20)).to.be.false; |
| 37 | + }); |
| 38 | +}); |
0 commit comments