| 78 | }; |
| 79 | |
| 80 | const computePlotClipRect = ( |
| 81 | gridArea: GridArea |
| 82 | ): { readonly left: number; readonly right: number; readonly top: number; readonly bottom: number; readonly width: number; readonly height: number } => { |
| 83 | const { left, right, top, bottom, canvasWidth, canvasHeight, devicePixelRatio } = gridArea; |
| 84 | |
| 85 | const plotLeft = left * devicePixelRatio; |
| 86 | const plotRight = canvasWidth - right * devicePixelRatio; |
| 87 | const plotTop = top * devicePixelRatio; |
| 88 | const plotBottom = canvasHeight - bottom * devicePixelRatio; |
| 89 | |
| 90 | const plotLeftClip = (plotLeft / canvasWidth) * 2.0 - 1.0; |
| 91 | const plotRightClip = (plotRight / canvasWidth) * 2.0 - 1.0; |
| 92 | const plotTopClip = 1.0 - (plotTop / canvasHeight) * 2.0; // flip Y |
| 93 | const plotBottomClip = 1.0 - (plotBottom / canvasHeight) * 2.0; // flip Y |
| 94 | |
| 95 | return { |
| 96 | left: plotLeftClip, |
| 97 | right: plotRightClip, |
| 98 | top: plotTopClip, |
| 99 | bottom: plotBottomClip, |
| 100 | width: plotRightClip - plotLeftClip, |
| 101 | height: plotTopClip - plotBottomClip, |
| 102 | }; |
| 103 | }; |
| 104 | |
| 105 | const computePlotScissorDevicePx = ( |
| 106 | gridArea: GridArea |