test(tests): pin the bubble's vertex rung
This commit is contained in:
1 parent
aecc2b468e
commit
98156643eb
2 files changed
+17
-11
No files matched your search
@@ -88,6 +88,7 @@ export function visibleBounds(
|
|||||||
frame.y + frame.h,
|
frame.y + frame.h,
|
||||||
toDrawing((box.h - framing.y) / framing.scale, oy, frame.y),
|
toDrawing((box.h - framing.y) / framing.scale, oy, frame.y),
|
||||||
)
|
)
|
||||||
|
if (x1 <= x0 || y1 <= y0) return null
|
||||||
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 }
|
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ describe('visibleBounds', () => {
|
|||||||
h: 50,
|
h: 50,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
it('is null when the framing shows none of the frame', () => {
|
||||||
|
expect(visibleBounds(frame, box, { x: -500, y: 0, scale: 2 })).toBeNull()
|
||||||
|
})
|
||||||
it('is null for an empty box', () => {
|
it('is null for an empty box', () => {
|
||||||
expect(
|
expect(
|
||||||
visibleBounds(frame, { w: 0, h: 10 }, { x: 0, y: 0, scale: 1 }),
|
visibleBounds(frame, { w: 0, h: 10 }, { x: 0, y: 0, scale: 1 }),
|
||||||
@@ -180,23 +183,25 @@ describe('removeBubbleCentre', () => {
|
|||||||
).toBe(true)
|
).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('vertex rung: keeps clear of another vertex straight ahead', () => {
|
it('vertex rung: keeps clear of another vertex on the open ray', () => {
|
||||||
const sizes = deviceSizes()
|
const sizes = deviceSizes()
|
||||||
// vertex 0 opens up-left (towards -y); another vertex sits 40 px straight above it.
|
// Vertex 0 has both neighbours below: it opens straight up. Vertex 2 lies 40 px up.
|
||||||
const points: Point[] = [
|
const points: Point[] = [
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[60, 20],
|
[50, 80],
|
||||||
[60, 80],
|
|
||||||
[0, 80],
|
|
||||||
[0, -40],
|
[0, -40],
|
||||||
|
[-60, 40],
|
||||||
|
[-50, 80],
|
||||||
]
|
]
|
||||||
const scene = sceneOf(points, 1, sizes, null)
|
const base: XY = { x: 0, y: -(sizes.hit + sizes.bubble.h / 2 + 2) }
|
||||||
const [bx, by] = removeBubbleCentre(scene, 0)
|
const other: XY = { x: 0, y: -40 }
|
||||||
|
expect(bubbleClearance(base, other, sizes)).toBeLessThan(0)
|
||||||
|
const [bx, by] = removeBubbleCentre(sceneOf(points, 1, sizes, null), 0)
|
||||||
|
const centre: XY = { x: bx, y: by }
|
||||||
|
expect(centre).not.toEqual(base)
|
||||||
|
expect(bubbleClearance(centre, other, sizes)).toBeGreaterThanOrEqual(0)
|
||||||
expect(
|
expect(
|
||||||
bubbleClearance({ x: bx, y: by }, { x: 0, y: -40 }, sizes),
|
bubbleClearance(centre, { x: 0, y: 0 }, sizes),
|
||||||
).toBeGreaterThanOrEqual(0)
|
|
||||||
expect(
|
|
||||||
bubbleClearance({ x: bx, y: by }, { x: 0, y: 0 }, sizes),
|
|
||||||
).toBeGreaterThanOrEqual(0)
|
).toBeGreaterThanOrEqual(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user