Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,14 @@ export class CanvasGradientToolModule extends CanvasModuleBase {
};

if (settings.gradientType === 'linear') {
const bboxCenter = {
x: bboxInLayer.x + bboxInLayer.width / 2,
y: bboxInLayer.y + bboxInLayer.height / 2,
};
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const halfWidth = (Math.abs(bboxInLayer.width * cos) + Math.abs(bboxInLayer.height * sin)) / 2;
const halfHeight = (Math.abs(bboxInLayer.width * sin) + Math.abs(bboxInLayer.height * cos)) / 2;
// Always render linear gradients on a rect that fully covers the bbox.
// Angle-dependent rect sizing can undershoot on non-square bboxes (e.g. 90deg on tall bboxes),
// leaving uncovered bands when the result is clipped back to bbox.
rect = {
x: bboxCenter.x - halfWidth,
y: bboxCenter.y - halfHeight,
width: Math.max(halfWidth * 2, 1),
height: Math.max(halfHeight * 2, 1),
x: bboxInLayer.x,
y: bboxInLayer.y,
width: Math.max(bboxInLayer.width, 1),
height: Math.max(bboxInLayer.height, 1),
};
}

Expand Down