( prev: Screen, next: Screen, cb: DiffCallback, )
| 1487 | * Returns true if the callback ever returned true (early exit signal). |
| 1488 | */ |
| 1489 | export function diffEach( |
| 1490 | prev: Screen, |
| 1491 | next: Screen, |
| 1492 | cb: DiffCallback, |
| 1493 | ): boolean { |
| 1494 | const prevWidth = prev.width |
| 1495 | const nextWidth = next.width |
| 1496 | const prevHeight = prev.height |
| 1497 | const nextHeight = next.height |
| 1498 | |
| 1499 | let region: Rectangle |
| 1500 | if (prevWidth === 0 && prevHeight === 0) { |
| 1501 | region = { x: 0, y: 0, width: nextWidth, height: nextHeight } |
| 1502 | } else if (next.damage) { |
| 1503 | region = next.damage |
| 1504 | if (prev.damage) { |
| 1505 | region = unionRect(region, prev.damage) |
| 1506 | } |
| 1507 | } else if (prev.damage) { |
| 1508 | region = prev.damage |
| 1509 | } else { |
| 1510 | region = { x: 0, y: 0, width: 0, height: 0 } |
| 1511 | } |
| 1512 | |
| 1513 | const contentEndRegion = contentEndDamageRegion(prev, next) |
| 1514 | if (contentEndRegion) { |
| 1515 | region = |
| 1516 | region.width === 0 || region.height === 0 |
| 1517 | ? contentEndRegion |
| 1518 | : unionRect(region, contentEndRegion) |
| 1519 | } |
| 1520 | |
| 1521 | if (prevHeight > nextHeight) { |
| 1522 | region = unionRect(region, { |
| 1523 | x: 0, |
| 1524 | y: nextHeight, |
| 1525 | width: prevWidth, |
| 1526 | height: prevHeight - nextHeight, |
| 1527 | }) |
| 1528 | } |
| 1529 | if (prevWidth > nextWidth) { |
| 1530 | region = unionRect(region, { |
| 1531 | x: nextWidth, |
| 1532 | y: 0, |
| 1533 | width: prevWidth - nextWidth, |
| 1534 | height: prevHeight, |
| 1535 | }) |
| 1536 | } |
| 1537 | |
| 1538 | const maxHeight = Math.max(prevHeight, nextHeight) |
| 1539 | const maxWidth = Math.max(prevWidth, nextWidth) |
| 1540 | const endY = Math.min(region.y + region.height, maxHeight) |
| 1541 | const endX = Math.min(region.x + region.width, maxWidth) |
| 1542 | |
| 1543 | if (prevWidth === nextWidth) { |
| 1544 | return diffSameWidth(prev, next, region.x, endX, region.y, endY, cb) |
| 1545 | } |
| 1546 | return diffDifferentWidth(prev, next, region.x, endX, region.y, endY, cb) |
no test coverage detected