* @private * @param {(LEFT|RIGHT|CENTER)} xAlign either LEFT, RIGHT or CENTER * @param {(TOP|BOTTOM|CENTER)} yAlign either TOP, BOTTOM or CENTER * @param {Number} dw * @param {Number} dh * @param {Number} sx * @param {Number} sy * @param {Number} sw * @param {Number} sh *
(xAlign, yAlign, dw, dh, sx, sy, sw, sh)
| 756 | * @returns {Object} |
| 757 | */ |
| 758 | function _imageCover(xAlign, yAlign, dw, dh, sx, sy, sw, sh) { |
| 759 | const r = Math.max(dw / sw, dh / sh); |
| 760 | const [adjusted_sw, adjusted_sh] = [dw / r, dh / r]; |
| 761 | |
| 762 | let x = sx; |
| 763 | let y = sy; |
| 764 | |
| 765 | if (xAlign === constants.CENTER) { |
| 766 | x += (sw - adjusted_sw) / 2; |
| 767 | } else if (xAlign === constants.RIGHT) { |
| 768 | x += sw - adjusted_sw; |
| 769 | } |
| 770 | |
| 771 | if (yAlign === constants.CENTER) { |
| 772 | y += (sh - adjusted_sh) / 2; |
| 773 | } else if (yAlign === constants.BOTTOM) { |
| 774 | y += sh - adjusted_sh; |
| 775 | } |
| 776 | |
| 777 | return { x, y, w: adjusted_sw, h: adjusted_sh }; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * @private |