| 637 | }; |
| 638 | |
| 639 | const computePlotScissorDevicePx = ( |
| 640 | gridArea: GridArea |
| 641 | ): { readonly x: number; readonly y: number; readonly w: number; readonly h: number } => { |
| 642 | const { canvasWidth, canvasHeight, devicePixelRatio } = gridArea; |
| 643 | |
| 644 | const plotLeftDevice = gridArea.left * devicePixelRatio; |
| 645 | const plotRightDevice = canvasWidth - gridArea.right * devicePixelRatio; |
| 646 | const plotTopDevice = gridArea.top * devicePixelRatio; |
| 647 | const plotBottomDevice = canvasHeight - gridArea.bottom * devicePixelRatio; |
| 648 | |
| 649 | const scissorX = clampInt(Math.floor(plotLeftDevice), 0, Math.max(0, canvasWidth)); |
| 650 | const scissorY = clampInt(Math.floor(plotTopDevice), 0, Math.max(0, canvasHeight)); |
| 651 | const scissorR = clampInt(Math.ceil(plotRightDevice), 0, Math.max(0, canvasWidth)); |
| 652 | const scissorB = clampInt(Math.ceil(plotBottomDevice), 0, Math.max(0, canvasHeight)); |
| 653 | const scissorW = Math.max(0, scissorR - scissorX); |
| 654 | const scissorH = Math.max(0, scissorB - scissorY); |
| 655 | |
| 656 | return { x: scissorX, y: scissorY, w: scissorW, h: scissorH }; |
| 657 | }; |
| 658 | |
| 659 | const clipXToCanvasCssPx = (xClip: number, canvasCssWidth: number): number => ((xClip + 1) / 2) * canvasCssWidth; |
| 660 | const clipYToCanvasCssPx = (yClip: number, canvasCssHeight: number): number => ((1 - yClip) / 2) * canvasCssHeight; |