@pixi/graphics-extras
Advanced tools
Comparing version 7.2.4 to 7.3.0-rc
/*! | ||
* @pixi/graphics-extras - v7.2.4 | ||
* Compiled Thu, 06 Apr 2023 19:36:45 UTC | ||
* @pixi/graphics-extras - v7.3.0-rc | ||
* Compiled Wed, 12 Jul 2023 19:26:10 UTC | ||
* | ||
@@ -8,131 +8,173 @@ * @pixi/graphics-extras is licensed under the MIT License. | ||
*/ | ||
(function (graphics, core) { | ||
'use strict'; | ||
function drawChamferRect(x, y, width, height, chamfer) { | ||
if (chamfer <= 0) { | ||
return this.drawRect(x, y, width, height); | ||
} | ||
const inset = Math.min(chamfer, Math.min(width, height) / 2); | ||
const right = x + width; | ||
const bottom = y + height; | ||
const points = [ | ||
x + inset, | ||
y, | ||
right - inset, | ||
y, | ||
right, | ||
y + inset, | ||
right, | ||
bottom - inset, | ||
right - inset, | ||
bottom, | ||
x + inset, | ||
bottom, | ||
x, | ||
bottom - inset, | ||
x, | ||
y + inset | ||
]; | ||
for (let i = points.length - 1; i >= 2; i -= 2) { | ||
if (points[i] === points[i - 2] && points[i - 1] === points[i - 3]) { | ||
points.splice(i - 1, 2); | ||
} | ||
} | ||
return this.drawPolygon(points); | ||
(function(graphics, core) { | ||
"use strict"; | ||
function drawChamferRect(x, y, width, height, chamfer) { | ||
if (chamfer <= 0) | ||
return this.drawRect(x, y, width, height); | ||
const inset = Math.min(chamfer, Math.min(width, height) / 2), right = x + width, bottom = y + height, points = [ | ||
x + inset, | ||
y, | ||
right - inset, | ||
y, | ||
right, | ||
y + inset, | ||
right, | ||
bottom - inset, | ||
right - inset, | ||
bottom, | ||
x + inset, | ||
bottom, | ||
x, | ||
bottom - inset, | ||
x, | ||
y + inset | ||
]; | ||
for (let i = points.length - 1; i >= 2; i -= 2) | ||
points[i] === points[i - 2] && points[i - 1] === points[i - 3] && points.splice(i - 1, 2); | ||
return this.drawPolygon(points); | ||
} | ||
function drawFilletRect(x, y, width, height, fillet) { | ||
if (fillet === 0) | ||
return this.drawRect(x, y, width, height); | ||
const maxFillet = Math.min(width, height) / 2, inset = Math.min(maxFillet, Math.max(-maxFillet, fillet)), right = x + width, bottom = y + height, dir = inset < 0 ? -inset : 0, size = Math.abs(inset); | ||
return this.moveTo(x, y + size).arcTo(x + dir, y + dir, x + size, y, size).lineTo(right - size, y).arcTo(right - dir, y + dir, right, y + size, size).lineTo(right, bottom - size).arcTo(right - dir, bottom - dir, x + width - size, bottom, size).lineTo(x + size, bottom).arcTo(x + dir, bottom - dir, x, bottom - size, size).closePath(); | ||
} | ||
function drawRegularPolygon(x, y, radius, sides, rotation = 0) { | ||
sides = Math.max(sides | 0, 3); | ||
const startAngle = -1 * Math.PI / 2 + rotation, delta = Math.PI * 2 / sides, polygon = []; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle; | ||
polygon.push( | ||
x + radius * Math.cos(angle), | ||
y + radius * Math.sin(angle) | ||
); | ||
} | ||
function drawFilletRect(x, y, width, height, fillet) { | ||
if (fillet === 0) { | ||
return this.drawRect(x, y, width, height); | ||
} | ||
const maxFillet = Math.min(width, height) / 2; | ||
const inset = Math.min(maxFillet, Math.max(-maxFillet, fillet)); | ||
const right = x + width; | ||
const bottom = y + height; | ||
const dir = inset < 0 ? -inset : 0; | ||
const size = Math.abs(inset); | ||
return this.moveTo(x, y + size).arcTo(x + dir, y + dir, x + size, y, size).lineTo(right - size, y).arcTo(right - dir, y + dir, right, y + size, size).lineTo(right, bottom - size).arcTo(right - dir, bottom - dir, x + width - size, bottom, size).lineTo(x + size, bottom).arcTo(x + dir, bottom - dir, x, bottom - size, size).closePath(); | ||
return this.drawPolygon(polygon); | ||
} | ||
function drawRoundedPolygon(x, y, radius, sides, corner, rotation = 0) { | ||
if (sides = Math.max(sides | 0, 3), corner <= 0) | ||
return this.drawRegularPolygon(x, y, radius, sides, rotation); | ||
const sideLength = radius * Math.sin(Math.PI / sides) - 1e-3; | ||
corner = Math.min(corner, sideLength); | ||
const startAngle = -1 * Math.PI / 2 + rotation, delta = Math.PI * 2 / sides, internalAngle = (sides - 2) * Math.PI / sides / 2; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle, x0 = x + radius * Math.cos(angle), y0 = y + radius * Math.sin(angle), a1 = angle + Math.PI + internalAngle, a2 = angle - Math.PI - internalAngle, x1 = x0 + corner * Math.cos(a1), y1 = y0 + corner * Math.sin(a1), x3 = x0 + corner * Math.cos(a2), y3 = y0 + corner * Math.sin(a2); | ||
i === 0 ? this.moveTo(x1, y1) : this.lineTo(x1, y1), this.quadraticCurveTo(x0, y0, x3, y3); | ||
} | ||
function drawRegularPolygon(x, y, radius, sides, rotation = 0) { | ||
sides = Math.max(sides | 0, 3); | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const delta = Math.PI * 2 / sides; | ||
const polygon = []; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle; | ||
polygon.push(x + radius * Math.cos(angle), y + radius * Math.sin(angle)); | ||
return this.closePath(); | ||
} | ||
function roundedShapeArc(g, points, radius) { | ||
var _a; | ||
const vecFrom = (p, pp) => { | ||
const x = pp.x - p.x, y = pp.y - p.y, len = Math.sqrt(x * x + y * y), nx = x / len, ny = y / len; | ||
return { len, nx, ny }; | ||
}, sharpCorner = (i, p) => { | ||
i === 0 ? g.moveTo(p.x, p.y) : g.lineTo(p.x, p.y); | ||
}; | ||
let p1 = points[points.length - 1]; | ||
for (let i = 0; i < points.length; i++) { | ||
const p2 = points[i % points.length], pRadius = (_a = p2.radius) != null ? _a : radius; | ||
if (pRadius <= 0) { | ||
sharpCorner(i, p2), p1 = p2; | ||
continue; | ||
} | ||
return this.drawPolygon(polygon); | ||
const p3 = points[(i + 1) % points.length], v1 = vecFrom(p2, p1), v2 = vecFrom(p2, p3); | ||
if (v1.len < 1e-4 || v2.len < 1e-4) { | ||
sharpCorner(i, p2), p1 = p2; | ||
continue; | ||
} | ||
let angle = Math.asin(v1.nx * v2.ny - v1.ny * v2.nx), radDirection = 1, drawDirection = !1; | ||
v1.nx * v2.nx - v1.ny * -v2.ny < 0 ? angle < 0 ? angle = Math.PI + angle : (angle = Math.PI - angle, radDirection = -1, drawDirection = !0) : angle > 0 && (radDirection = -1, drawDirection = !0); | ||
const halfAngle = angle / 2; | ||
let cRadius, lenOut = Math.abs( | ||
Math.cos(halfAngle) * pRadius / Math.sin(halfAngle) | ||
); | ||
lenOut > Math.min(v1.len / 2, v2.len / 2) ? (lenOut = Math.min(v1.len / 2, v2.len / 2), cRadius = Math.abs(lenOut * Math.sin(halfAngle) / Math.cos(halfAngle))) : cRadius = pRadius; | ||
const cX = p2.x + v2.nx * lenOut + -v2.ny * cRadius * radDirection, cY = p2.y + v2.ny * lenOut + v2.nx * cRadius * radDirection, startAngle = Math.atan2(v1.ny, v1.nx) + Math.PI / 2 * radDirection, endAngle = Math.atan2(v2.ny, v2.nx) - Math.PI / 2 * radDirection; | ||
i === 0 && g.moveTo( | ||
cX + Math.cos(startAngle) * cRadius, | ||
cY + Math.sin(startAngle) * cRadius | ||
), g.arc(cX, cY, cRadius, startAngle, endAngle, drawDirection), p1 = p2; | ||
} | ||
function drawRoundedPolygon(x, y, radius, sides, corner, rotation = 0) { | ||
sides = Math.max(sides | 0, 3); | ||
if (corner <= 0) { | ||
return this.drawRegularPolygon(x, y, radius, sides, rotation); | ||
} | ||
function roundedShapeQuadraticCurve(g, points, radius) { | ||
var _a; | ||
const distance = (p1, p2) => Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2), pointLerp = (p1, p2, t) => ({ | ||
x: p1.x + (p2.x - p1.x) * t, | ||
y: p1.y + (p2.y - p1.y) * t | ||
}), numPoints = points.length; | ||
for (let i = 0; i < numPoints; i++) { | ||
const thisPoint = points[(i + 1) % numPoints], pRadius = (_a = thisPoint.radius) != null ? _a : radius; | ||
if (pRadius <= 0) { | ||
i === 0 ? g.moveTo(thisPoint.x, thisPoint.y) : g.lineTo(thisPoint.x, thisPoint.y); | ||
continue; | ||
} | ||
const sideLength = radius * Math.sin(Math.PI / sides) - 1e-3; | ||
corner = Math.min(corner, sideLength); | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const delta = Math.PI * 2 / sides; | ||
const internalAngle = (sides - 2) * Math.PI / sides / 2; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle; | ||
const x0 = x + radius * Math.cos(angle); | ||
const y0 = y + radius * Math.sin(angle); | ||
const a1 = angle + Math.PI + internalAngle; | ||
const a2 = angle - Math.PI - internalAngle; | ||
const x1 = x0 + corner * Math.cos(a1); | ||
const y1 = y0 + corner * Math.sin(a1); | ||
const x3 = x0 + corner * Math.cos(a2); | ||
const y3 = y0 + corner * Math.sin(a2); | ||
if (i === 0) { | ||
this.moveTo(x1, y1); | ||
} else { | ||
this.lineTo(x1, y1); | ||
} | ||
this.quadraticCurveTo(x0, y0, x3, y3); | ||
const lastPoint = points[i], nextPoint = points[(i + 2) % numPoints], lastEdgeLength = distance(lastPoint, thisPoint); | ||
let start; | ||
if (lastEdgeLength < 1e-4) | ||
start = thisPoint; | ||
else { | ||
const lastOffsetDistance = Math.min(lastEdgeLength / 2, pRadius); | ||
start = pointLerp( | ||
thisPoint, | ||
lastPoint, | ||
lastOffsetDistance / lastEdgeLength | ||
); | ||
} | ||
return this.closePath(); | ||
} | ||
class Star extends core.Polygon { | ||
constructor(x, y, points, radius, innerRadius, rotation = 0) { | ||
innerRadius = innerRadius || radius / 2; | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const len = points * 2; | ||
const delta = core.PI_2 / len; | ||
const polygon = []; | ||
for (let i = 0; i < len; i++) { | ||
const r = i % 2 ? innerRadius : radius; | ||
const angle = i * delta + startAngle; | ||
polygon.push(x + r * Math.cos(angle), y + r * Math.sin(angle)); | ||
} | ||
super(polygon); | ||
const nextEdgeLength = distance(nextPoint, thisPoint); | ||
let end; | ||
if (nextEdgeLength < 1e-4) | ||
end = thisPoint; | ||
else { | ||
const nextOffsetDistance = Math.min(nextEdgeLength / 2, pRadius); | ||
end = pointLerp( | ||
thisPoint, | ||
nextPoint, | ||
nextOffsetDistance / nextEdgeLength | ||
); | ||
} | ||
i === 0 ? g.moveTo(start.x, start.y) : g.lineTo(start.x, start.y), g.quadraticCurveTo(thisPoint.x, thisPoint.y, end.x, end.y); | ||
} | ||
function drawStar(x, y, points, radius, innerRadius, rotation = 0) { | ||
return this.drawPolygon(new Star(x, y, points, radius, innerRadius, rotation)); | ||
} | ||
function drawTorus(x, y, innerRadius, outerRadius, startArc = 0, endArc = Math.PI * 2) { | ||
if (Math.abs(endArc - startArc) >= Math.PI * 2) { | ||
return this.drawCircle(x, y, outerRadius).beginHole().drawCircle(x, y, innerRadius).endHole(); | ||
} | ||
function drawRoundedShape(points, radius, useQuadraticCurve) { | ||
return points.length < 3 ? this : (useQuadraticCurve ? roundedShapeQuadraticCurve(this, points, radius) : roundedShapeArc(this, points, radius), this.closePath()); | ||
} | ||
class Star extends core.Polygon { | ||
/** | ||
* @param x - Center X position of the star | ||
* @param y - Center Y position of the star | ||
* @param points - The number of points of the star, must be > 1 | ||
* @param radius - The outer radius of the star | ||
* @param innerRadius - The inner radius between points, default half `radius` | ||
* @param rotation - The rotation of the star in radians, where 0 is vertical | ||
*/ | ||
constructor(x, y, points, radius, innerRadius, rotation = 0) { | ||
innerRadius = innerRadius || radius / 2; | ||
const startAngle = -1 * Math.PI / 2 + rotation, len = points * 2, delta = core.PI_2 / len, polygon = []; | ||
for (let i = 0; i < len; i++) { | ||
const r = i % 2 ? innerRadius : radius, angle = i * delta + startAngle; | ||
polygon.push( | ||
x + r * Math.cos(angle), | ||
y + r * Math.sin(angle) | ||
); | ||
} | ||
this.finishPoly(); | ||
this.arc(x, y, innerRadius, endArc, startArc, true).arc(x, y, outerRadius, startArc, endArc, false).finishPoly(); | ||
return this; | ||
super(polygon); | ||
} | ||
Object.defineProperties(graphics.Graphics.prototype, { | ||
drawTorus: { value: drawTorus }, | ||
drawChamferRect: { value: drawChamferRect }, | ||
drawFilletRect: { value: drawFilletRect }, | ||
drawRegularPolygon: { value: drawRegularPolygon }, | ||
drawRoundedPolygon: { value: drawRoundedPolygon }, | ||
drawStar: { value: drawStar } | ||
}); | ||
} | ||
function drawStar(x, y, points, radius, innerRadius, rotation = 0) { | ||
return this.drawPolygon(new Star(x, y, points, radius, innerRadius, rotation)); | ||
} | ||
function drawTorus(x, y, innerRadius, outerRadius, startArc = 0, endArc = Math.PI * 2) { | ||
return Math.abs(endArc - startArc) >= Math.PI * 2 ? this.drawCircle(x, y, outerRadius).beginHole().drawCircle(x, y, innerRadius).endHole() : (this.finishPoly(), this.arc(x, y, innerRadius, endArc, startArc, !0).arc(x, y, outerRadius, startArc, endArc, !1).finishPoly(), this); | ||
} | ||
Object.defineProperties(graphics.Graphics.prototype, { | ||
drawTorus: { value: drawTorus }, | ||
drawChamferRect: { value: drawChamferRect }, | ||
drawFilletRect: { value: drawFilletRect }, | ||
drawRegularPolygon: { value: drawRegularPolygon }, | ||
drawRoundedPolygon: { value: drawRoundedPolygon }, | ||
drawRoundedShape: { value: drawRoundedShape }, | ||
drawStar: { value: drawStar } | ||
}); | ||
})(PIXI, PIXI); | ||
//# sourceMappingURL=graphics-extras.js.map |
/*! | ||
* @pixi/graphics-extras - v7.2.4 | ||
* Compiled Thu, 06 Apr 2023 19:36:45 UTC | ||
* @pixi/graphics-extras - v7.3.0-rc | ||
* Compiled Wed, 12 Jul 2023 19:26:10 UTC | ||
* | ||
* @pixi/graphics-extras is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/(function(y,d){"use strict";function T(t,a,h,r,o){if(o<=0)return this.drawRect(t,a,h,r);const n=Math.min(o,Math.min(h,r)/2),l=t+h,c=a+r,s=[t+n,a,l-n,a,l,a+n,l,c-n,l-n,c,t+n,c,t,c-n,t,a+n];for(let e=s.length-1;e>=2;e-=2)s[e]===s[e-2]&&s[e-1]===s[e-3]&&s.splice(e-1,2);return this.drawPolygon(s)}function m(t,a,h,r,o){if(o===0)return this.drawRect(t,a,h,r);const n=Math.min(h,r)/2,l=Math.min(n,Math.max(-n,o)),c=t+h,s=a+r,e=l<0?-l:0,i=Math.abs(l);return this.moveTo(t,a+i).arcTo(t+e,a+e,t+i,a,i).lineTo(c-i,a).arcTo(c-e,a+e,c,a+i,i).lineTo(c,s-i).arcTo(c-e,s-e,t+h-i,s,i).lineTo(t+i,s).arcTo(t+e,s-e,t,s-i,i).closePath()}function R(t,a,h,r,o=0){r=Math.max(r|0,3);const n=-1*Math.PI/2+o,l=Math.PI*2/r,c=[];for(let s=0;s<r;s++){const e=s*l+n;c.push(t+h*Math.cos(e),a+h*Math.sin(e))}return this.drawPolygon(c)}function p(t,a,h,r,o,n=0){if(r=Math.max(r|0,3),o<=0)return this.drawRegularPolygon(t,a,h,r,n);const l=h*Math.sin(Math.PI/r)-.001;o=Math.min(o,l);const c=-1*Math.PI/2+n,s=Math.PI*2/r,e=(r-2)*Math.PI/r/2;for(let i=0;i<r;i++){const u=i*s+c,M=t+h*Math.cos(u),P=a+h*Math.sin(u),w=u+Math.PI+e,f=u-Math.PI-e,I=M+o*Math.cos(w),g=P+o*Math.sin(w),x=M+o*Math.cos(f),F=P+o*Math.sin(f);i===0?this.moveTo(I,g):this.lineTo(I,g),this.quadraticCurveTo(M,P,x,F)}return this.closePath()}class v extends d.Polygon{constructor(a,h,r,o,n,l=0){n=n||o/2;const c=-1*Math.PI/2+l,s=r*2,e=d.PI_2/s,i=[];for(let u=0;u<s;u++){const M=u%2?n:o,P=u*e+c;i.push(a+M*Math.cos(P),h+M*Math.sin(P))}super(i)}}function b(t,a,h,r,o,n=0){return this.drawPolygon(new v(t,a,h,r,o,n))}function C(t,a,h,r,o=0,n=Math.PI*2){return Math.abs(n-o)>=Math.PI*2?this.drawCircle(t,a,r).beginHole().drawCircle(t,a,h).endHole():(this.finishPoly(),this.arc(t,a,h,n,o,!0).arc(t,a,r,o,n,!1).finishPoly(),this)}Object.defineProperties(y.Graphics.prototype,{drawTorus:{value:C},drawChamferRect:{value:T},drawFilletRect:{value:m},drawRegularPolygon:{value:R},drawRoundedPolygon:{value:p},drawStar:{value:b}})})(PIXI,PIXI); | ||
*/(function(v,T){"use strict";function R(e,a,i,o,s){if(s<=0)return this.drawRect(e,a,i,o);const r=Math.min(s,Math.min(i,o)/2),M=e+i,n=a+o,t=[e+r,a,M-r,a,M,a+r,M,n-r,M-r,n,e+r,n,e,n-r,e,a+r];for(let h=t.length-1;h>=2;h-=2)t[h]===t[h-2]&&t[h-1]===t[h-3]&&t.splice(h-1,2);return this.drawPolygon(t)}function p(e,a,i,o,s){if(s===0)return this.drawRect(e,a,i,o);const r=Math.min(i,o)/2,M=Math.min(r,Math.max(-r,s)),n=e+i,t=a+o,h=M<0?-M:0,l=Math.abs(M);return this.moveTo(e,a+l).arcTo(e+h,a+h,e+l,a,l).lineTo(n-l,a).arcTo(n-h,a+h,n,a+l,l).lineTo(n,t-l).arcTo(n-h,t-h,e+i-l,t,l).lineTo(e+l,t).arcTo(e+h,t-h,e,t-l,l).closePath()}function b(e,a,i,o,s=0){o=Math.max(o|0,3);const r=-1*Math.PI/2+s,M=Math.PI*2/o,n=[];for(let t=0;t<o;t++){const h=t*M+r;n.push(e+i*Math.cos(h),a+i*Math.sin(h))}return this.drawPolygon(n)}function C(e,a,i,o,s,r=0){if(o=Math.max(o|0,3),s<=0)return this.drawRegularPolygon(e,a,i,o,r);const M=i*Math.sin(Math.PI/o)-.001;s=Math.min(s,M);const n=-1*Math.PI/2+r,t=Math.PI*2/o,h=(o-2)*Math.PI/o/2;for(let l=0;l<o;l++){const c=l*t+n,u=e+i*Math.cos(c),y=a+i*Math.sin(c),d=c+Math.PI+h,P=c-Math.PI-h,x=u+s*Math.cos(d),f=y+s*Math.sin(d),w=u+s*Math.cos(P),g=y+s*Math.sin(P);l===0?this.moveTo(x,f):this.lineTo(x,f),this.quadraticCurveTo(u,y,w,g)}return this.closePath()}function q(e,a,i){var o;const s=(n,t)=>{const h=t.x-n.x,l=t.y-n.y,c=Math.sqrt(h*h+l*l),u=h/c,y=l/c;return{len:c,nx:u,ny:y}},r=(n,t)=>{n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)};let M=a[a.length-1];for(let n=0;n<a.length;n++){const t=a[n%a.length],h=(o=t.radius)!=null?o:i;if(h<=0){r(n,t),M=t;continue}const l=a[(n+1)%a.length],c=s(t,M),u=s(t,l);if(c.len<1e-4||u.len<1e-4){r(n,t),M=t;continue}let y=Math.asin(c.nx*u.ny-c.ny*u.nx),d=1,P=!1;c.nx*u.nx-c.ny*-u.ny<0?y<0?y=Math.PI+y:(y=Math.PI-y,d=-1,P=!0):y>0&&(d=-1,P=!0);const x=y/2;let f,w=Math.abs(Math.cos(x)*h/Math.sin(x));w>Math.min(c.len/2,u.len/2)?(w=Math.min(c.len/2,u.len/2),f=Math.abs(w*Math.sin(x)/Math.cos(x))):f=h;const g=t.x+u.nx*w+-u.ny*f*d,m=t.y+u.ny*w+u.nx*f*d,I=Math.atan2(c.ny,c.nx)+Math.PI/2*d,D=Math.atan2(u.ny,u.nx)-Math.PI/2*d;n===0&&e.moveTo(g+Math.cos(I)*f,m+Math.sin(I)*f),e.arc(g,m,f,I,D,P),M=t}}function S(e,a,i){var o;const s=(n,t)=>Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2),r=(n,t,h)=>({x:n.x+(t.x-n.x)*h,y:n.y+(t.y-n.y)*h}),M=a.length;for(let n=0;n<M;n++){const t=a[(n+1)%M],h=(o=t.radius)!=null?o:i;if(h<=0){n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y);continue}const l=a[n],c=a[(n+2)%M],u=s(l,t);let y;if(u<1e-4)y=t;else{const x=Math.min(u/2,h);y=r(t,l,x/u)}const d=s(c,t);let P;if(d<1e-4)P=t;else{const x=Math.min(d/2,h);P=r(t,c,x/d)}n===0?e.moveTo(y.x,y.y):e.lineTo(y.x,y.y),e.quadraticCurveTo(t.x,t.y,P.x,P.y)}}function F(e,a,i){return e.length<3?this:(i?S(this,e,a):q(this,e,a),this.closePath())}class H extends T.Polygon{constructor(a,i,o,s,r,M=0){r=r||s/2;const n=-1*Math.PI/2+M,t=o*2,h=T.PI_2/t,l=[];for(let c=0;c<t;c++){const u=c%2?r:s,y=c*h+n;l.push(a+u*Math.cos(y),i+u*Math.sin(y))}super(l)}}function X(e,a,i,o,s,r=0){return this.drawPolygon(new H(e,a,i,o,s,r))}function j(e,a,i,o,s=0,r=Math.PI*2){return Math.abs(r-s)>=Math.PI*2?this.drawCircle(e,a,o).beginHole().drawCircle(e,a,i).endHole():(this.finishPoly(),this.arc(e,a,i,r,s,!0).arc(e,a,o,s,r,!1).finishPoly(),this)}Object.defineProperties(v.Graphics.prototype,{drawTorus:{value:j},drawChamferRect:{value:R},drawFilletRect:{value:p},drawRegularPolygon:{value:b},drawRoundedPolygon:{value:C},drawRoundedShape:{value:F},drawStar:{value:X}})})(PIXI,PIXI); | ||
//# sourceMappingURL=graphics-extras.min.js.map |
@@ -1,13 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
function drawChamferRect(x, y, width, height, chamfer) { | ||
if (chamfer <= 0) { | ||
if (chamfer <= 0) | ||
return this.drawRect(x, y, width, height); | ||
} | ||
const inset = Math.min(chamfer, Math.min(width, height) / 2); | ||
const right = x + width; | ||
const bottom = y + height; | ||
const points = [ | ||
const inset = Math.min(chamfer, Math.min(width, height) / 2), right = x + width, bottom = y + height, points = [ | ||
x + inset, | ||
@@ -30,11 +23,7 @@ y, | ||
]; | ||
for (let i = points.length - 1; i >= 2; i -= 2) { | ||
if (points[i] === points[i - 2] && points[i - 1] === points[i - 3]) { | ||
points.splice(i - 1, 2); | ||
} | ||
} | ||
for (let i = points.length - 1; i >= 2; i -= 2) | ||
points[i] === points[i - 2] && points[i - 1] === points[i - 3] && points.splice(i - 1, 2); | ||
return this.drawPolygon(points); | ||
} | ||
exports.drawChamferRect = drawChamferRect; | ||
//# sourceMappingURL=drawChamferRect.js.map |
@@ -1,19 +0,9 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
function drawFilletRect(x, y, width, height, fillet) { | ||
if (fillet === 0) { | ||
if (fillet === 0) | ||
return this.drawRect(x, y, width, height); | ||
} | ||
const maxFillet = Math.min(width, height) / 2; | ||
const inset = Math.min(maxFillet, Math.max(-maxFillet, fillet)); | ||
const right = x + width; | ||
const bottom = y + height; | ||
const dir = inset < 0 ? -inset : 0; | ||
const size = Math.abs(inset); | ||
const maxFillet = Math.min(width, height) / 2, inset = Math.min(maxFillet, Math.max(-maxFillet, fillet)), right = x + width, bottom = y + height, dir = inset < 0 ? -inset : 0, size = Math.abs(inset); | ||
return this.moveTo(x, y + size).arcTo(x + dir, y + dir, x + size, y, size).lineTo(right - size, y).arcTo(right - dir, y + dir, right, y + size, size).lineTo(right, bottom - size).arcTo(right - dir, bottom - dir, x + width - size, bottom, size).lineTo(x + size, bottom).arcTo(x + dir, bottom - dir, x, bottom - size, size).closePath(); | ||
} | ||
exports.drawFilletRect = drawFilletRect; | ||
//# sourceMappingURL=drawFilletRect.js.map |
@@ -1,18 +0,15 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
function drawRegularPolygon(x, y, radius, sides, rotation = 0) { | ||
sides = Math.max(sides | 0, 3); | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const delta = Math.PI * 2 / sides; | ||
const polygon = []; | ||
const startAngle = -1 * Math.PI / 2 + rotation, delta = Math.PI * 2 / sides, polygon = []; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle; | ||
polygon.push(x + radius * Math.cos(angle), y + radius * Math.sin(angle)); | ||
polygon.push( | ||
x + radius * Math.cos(angle), | ||
y + radius * Math.sin(angle) | ||
); | ||
} | ||
return this.drawPolygon(polygon); | ||
} | ||
exports.drawRegularPolygon = drawRegularPolygon; | ||
//# sourceMappingURL=drawRegularPolygon.js.map |
@@ -1,36 +0,15 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
function drawRoundedPolygon(x, y, radius, sides, corner, rotation = 0) { | ||
sides = Math.max(sides | 0, 3); | ||
if (corner <= 0) { | ||
if (sides = Math.max(sides | 0, 3), corner <= 0) | ||
return this.drawRegularPolygon(x, y, radius, sides, rotation); | ||
} | ||
const sideLength = radius * Math.sin(Math.PI / sides) - 1e-3; | ||
corner = Math.min(corner, sideLength); | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const delta = Math.PI * 2 / sides; | ||
const internalAngle = (sides - 2) * Math.PI / sides / 2; | ||
const startAngle = -1 * Math.PI / 2 + rotation, delta = Math.PI * 2 / sides, internalAngle = (sides - 2) * Math.PI / sides / 2; | ||
for (let i = 0; i < sides; i++) { | ||
const angle = i * delta + startAngle; | ||
const x0 = x + radius * Math.cos(angle); | ||
const y0 = y + radius * Math.sin(angle); | ||
const a1 = angle + Math.PI + internalAngle; | ||
const a2 = angle - Math.PI - internalAngle; | ||
const x1 = x0 + corner * Math.cos(a1); | ||
const y1 = y0 + corner * Math.sin(a1); | ||
const x3 = x0 + corner * Math.cos(a2); | ||
const y3 = y0 + corner * Math.sin(a2); | ||
if (i === 0) { | ||
this.moveTo(x1, y1); | ||
} else { | ||
this.lineTo(x1, y1); | ||
} | ||
this.quadraticCurveTo(x0, y0, x3, y3); | ||
const angle = i * delta + startAngle, x0 = x + radius * Math.cos(angle), y0 = y + radius * Math.sin(angle), a1 = angle + Math.PI + internalAngle, a2 = angle - Math.PI - internalAngle, x1 = x0 + corner * Math.cos(a1), y1 = y0 + corner * Math.sin(a1), x3 = x0 + corner * Math.cos(a2), y3 = y0 + corner * Math.sin(a2); | ||
i === 0 ? this.moveTo(x1, y1) : this.lineTo(x1, y1), this.quadraticCurveTo(x0, y0, x3, y3); | ||
} | ||
return this.closePath(); | ||
} | ||
exports.drawRoundedPolygon = drawRoundedPolygon; | ||
//# sourceMappingURL=drawRoundedPolygon.js.map |
@@ -1,18 +0,21 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var core = require('@pixi/core'); | ||
"use strict"; | ||
var core = require("@pixi/core"); | ||
class Star extends core.Polygon { | ||
/** | ||
* @param x - Center X position of the star | ||
* @param y - Center Y position of the star | ||
* @param points - The number of points of the star, must be > 1 | ||
* @param radius - The outer radius of the star | ||
* @param innerRadius - The inner radius between points, default half `radius` | ||
* @param rotation - The rotation of the star in radians, where 0 is vertical | ||
*/ | ||
constructor(x, y, points, radius, innerRadius, rotation = 0) { | ||
innerRadius = innerRadius || radius / 2; | ||
const startAngle = -1 * Math.PI / 2 + rotation; | ||
const len = points * 2; | ||
const delta = core.PI_2 / len; | ||
const polygon = []; | ||
const startAngle = -1 * Math.PI / 2 + rotation, len = points * 2, delta = core.PI_2 / len, polygon = []; | ||
for (let i = 0; i < len; i++) { | ||
const r = i % 2 ? innerRadius : radius; | ||
const angle = i * delta + startAngle; | ||
polygon.push(x + r * Math.cos(angle), y + r * Math.sin(angle)); | ||
const r = i % 2 ? innerRadius : radius, angle = i * delta + startAngle; | ||
polygon.push( | ||
x + r * Math.cos(angle), | ||
y + r * Math.sin(angle) | ||
); | ||
} | ||
@@ -25,4 +28,3 @@ super(polygon); | ||
} | ||
exports.drawStar = drawStar; | ||
//# sourceMappingURL=drawStar.js.map |
@@ -1,15 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
function drawTorus(x, y, innerRadius, outerRadius, startArc = 0, endArc = Math.PI * 2) { | ||
if (Math.abs(endArc - startArc) >= Math.PI * 2) { | ||
return this.drawCircle(x, y, outerRadius).beginHole().drawCircle(x, y, innerRadius).endHole(); | ||
} | ||
this.finishPoly(); | ||
this.arc(x, y, innerRadius, endArc, startArc, true).arc(x, y, outerRadius, startArc, endArc, false).finishPoly(); | ||
return this; | ||
return Math.abs(endArc - startArc) >= Math.PI * 2 ? this.drawCircle(x, y, outerRadius).beginHole().drawCircle(x, y, innerRadius).endHole() : (this.finishPoly(), this.arc(x, y, innerRadius, endArc, startArc, !0).arc(x, y, outerRadius, startArc, endArc, !1).finishPoly(), this); | ||
} | ||
exports.drawTorus = drawTorus; | ||
//# sourceMappingURL=drawTorus.js.map |
@@ -6,2 +6,3 @@ /// <reference path="../global.d.ts" /> | ||
import { drawRoundedPolygon } from './drawRoundedPolygon'; | ||
import { drawRoundedShape } from './drawRoundedShape'; | ||
import { drawStar } from './drawStar'; | ||
@@ -15,3 +16,4 @@ import { drawTorus } from './drawTorus'; | ||
drawRoundedPolygon: typeof drawRoundedPolygon; | ||
drawRoundedShape: typeof drawRoundedShape; | ||
drawStar: typeof drawStar; | ||
} |
@@ -1,11 +0,3 @@ | ||
'use strict'; | ||
var graphics = require('@pixi/graphics'); | ||
var drawChamferRect = require('./drawChamferRect.js'); | ||
var drawFilletRect = require('./drawFilletRect.js'); | ||
var drawRegularPolygon = require('./drawRegularPolygon.js'); | ||
var drawRoundedPolygon = require('./drawRoundedPolygon.js'); | ||
var drawStar = require('./drawStar.js'); | ||
var drawTorus = require('./drawTorus.js'); | ||
"use strict"; | ||
var graphics = require("@pixi/graphics"), drawChamferRect = require("./drawChamferRect.js"), drawFilletRect = require("./drawFilletRect.js"), drawRegularPolygon = require("./drawRegularPolygon.js"), drawRoundedPolygon = require("./drawRoundedPolygon.js"), drawRoundedShape = require("./drawRoundedShape.js"), drawStar = require("./drawStar.js"), drawTorus = require("./drawTorus.js"); | ||
Object.defineProperties(graphics.Graphics.prototype, { | ||
@@ -17,4 +9,5 @@ drawTorus: { value: drawTorus.drawTorus }, | ||
drawRoundedPolygon: { value: drawRoundedPolygon.drawRoundedPolygon }, | ||
drawRoundedShape: { value: drawRoundedShape.drawRoundedShape }, | ||
drawStar: { value: drawStar.drawStar } | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pixi/graphics-extras", | ||
"version": "7.2.4", | ||
"version": "7.3.0-rc", | ||
"main": "lib/index.js", | ||
@@ -39,5 +39,5 @@ "module": "lib/index.mjs", | ||
"peerDependencies": { | ||
"@pixi/core": "7.2.4", | ||
"@pixi/graphics": "7.2.4" | ||
"@pixi/core": "7.3.0-rc", | ||
"@pixi/graphics": "7.3.0-rc" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140079
48
734
1