modern-canvas 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5131,20 +5131,17 @@ class GradientTexture extends Texture2D {
5131
5131
  const h = height;
5132
5132
  const cx = w / 2;
5133
5133
  const cy = h / 2;
5134
- const canAng = angle * Math.PI / 180;
5135
- const hypt = cy / Math.cos(canAng);
5136
- const fromTopRight = cx - Math.sqrt(hypt * hypt - cy * cy);
5137
- const diag = Math.sin(canAng) * fromTopRight;
5138
- const len = hypt + diag;
5139
- const x0 = cx + Math.cos(-Math.PI / 2 + canAng) * len;
5140
- const y0 = cy + Math.sin(-Math.PI / 2 + canAng) * len;
5141
- const x1 = cx + Math.cos(Math.PI / 2 + canAng) * len;
5142
- const y1 = cy + Math.sin(Math.PI / 2 + canAng) * len;
5143
- const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
5144
- stops.forEach((stop) => {
5145
- gradient.addColorStop(stop.offset, stop.color);
5146
- });
5147
- ctx.fillStyle = gradient;
5134
+ const A = (angle + 90) * Math.PI / 180;
5135
+ const dx = Math.sin(A);
5136
+ const dy = -Math.cos(A);
5137
+ const L = Math.abs(w * Math.sin(A)) + Math.abs(h * Math.cos(A));
5138
+ const x0 = cx - dx * (L / 2);
5139
+ const y0 = cy - dy * (L / 2);
5140
+ const x1 = cx + dx * (L / 2);
5141
+ const y1 = cy + dy * (L / 2);
5142
+ const g = ctx.createLinearGradient(x0, y0, x1, y1);
5143
+ for (const s of stops) g.addColorStop(s.offset, s.color);
5144
+ ctx.fillStyle = g;
5148
5145
  ctx.fillRect(0, 0, w, h);
5149
5146
  const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
5150
5147
  return {