Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const context = this.renderer.context;
const len = graphics.graphicsData.length;
if (len === 0)
{
return;
}
context.beginPath();
for (let i = 0; i < len; i++)
{
const data = graphics.graphicsData[i];
const shape = data.shape;
if (data.type === SHAPES.POLY)
{
const points = shape.points;
context.moveTo(points[0], points[1]);
for (let j = 1; j < points.length / 2; j++)
{
context.lineTo(points[j * 2], points[(j * 2) + 1]);
}
// if the first and last point are the same close the path - much neater :)
if (points[0] === points[points.length - 2] && points[1] === points[points.length - 1])
{
context.closePath();
}
}
const context = this.renderer.context;
const graphicsData = graphics.geometry.graphicsData;
const len = graphicsData.length;
if (len === 0)
{
return;
}
for (let i = 0; i < len; i++)
{
const data = graphicsData[i];
const shape = data.shape;
if (data.type === SHAPES.POLY)
{
const points = shape.points;
context.moveTo(points[0], points[1]);
for (let j = 1; j < points.length / 2; j++)
{
context.lineTo(points[j * 2], points[(j * 2) + 1]);
}
// if the first and last point are the same close the path - much neater :)
if (points[0] === points[points.length - 2] && points[1] === points[points.length - 1])
{
context.closePath();
}
}
// if the object is a complex fill then the new stencil buffer technique will be used
// other wise graphics objects will be pushed into a batch..
for (let i = webGL.lastIndex; i < graphics.graphicsData.length; i++)
{
const data = graphics.graphicsData[i];
// TODO - this can be simplified
webGLData = this.getWebGLData(webGL, 0);
if (data.nativeLines && data.lineWidth)
{
webGLDataNativeLines = this.getWebGLData(webGL, 0, true);
webGL.lastIndex++;
}
if (data.type === SHAPES.POLY)
{
buildPoly(data, webGLData, webGLDataNativeLines);
}
if (data.type === SHAPES.RECT)
{
buildRectangle(data, webGLData, webGLDataNativeLines);
}
else if (data.type === SHAPES.CIRC || data.type === SHAPES.ELIP)
{
buildCircle(data, webGLData, webGLDataNativeLines);
}
else if (data.type === SHAPES.RREC)
{
buildRoundedRectangle(data, webGLData, webGLDataNativeLines);
}
for (let i = 0; i < this.graphicsData.length; i++)
{
const data = this.graphicsData[i];
const shape = data.shape;
const type = data.type;
const lineStyle = data.lineStyle;
const nextMatrix = data.matrix || Matrix.IDENTITY;
let lineWidth = 0.0;
if (lineStyle && lineStyle.visible)
{
const alignment = lineStyle.alignment;
lineWidth = lineStyle.width;
if (type === SHAPES.POLY)
{
lineWidth = lineWidth * (0.5 + Math.abs(0.5 - alignment));
}
else
{
lineWidth = lineWidth * Math.max(0, alignment);
}
}
if (curMatrix !== nextMatrix)
{
if (!sequenceBounds.isEmpty())
{
bounds.addBoundsMatrix(sequenceBounds, curMatrix);
sequenceBounds.clear();
}
export * from './Star';
export * from './ArcUtils';
export * from './BezierUtils';
export * from './QuadraticUtils';
export * from './BatchPart';
import { SHAPES } from '@pixi/math';
/**
* Map of fill commands for each shape type.
*
* @memberof PIXI.graphicsUtils
* @member {Object}
*/
export const FILL_COMMANDS = {
[SHAPES.POLY]: buildPoly,
[SHAPES.CIRC]: buildCircle,
[SHAPES.ELIP]: buildCircle,
[SHAPES.RECT]: buildRectangle,
[SHAPES.RREC]: buildRoundedRectangle,
};
/**
* Batch pool, stores unused batches for preventing allocations.
*
* @memberof PIXI.graphicsUtils
* @type {Array}
*/
export const BATCH_POOL = [];
/**
* Draw call pool, stores unused draw calls for preventing allocations.
const graphicsData = graphics.geometry.graphicsData;
for (let i = 0; i < graphicsData.length; i++)
{
const data = graphicsData[i];
const shape = data.shape;
const fillStyle = data.fillStyle;
const lineStyle = data.lineStyle;
const fillColor = data._fillTint;
const lineColor = data._lineTint;
context.lineWidth = lineStyle.width;
if (data.type === SHAPES.POLY)
{
context.beginPath();
let points = shape.points;
const holes = data.holes;
let outerArea;
let innerArea;
let px;
let py;
context.moveTo(points[0], points[1]);
for (let j = 2; j < points.length; j += 2)
{
context.lineTo(points[j], points[j + 1]);
}
const data = new GraphicsData(
this.lineWidth,
this.lineColor,
this.lineAlpha,
this.fillColor,
this.fillAlpha,
this.filling,
this.nativeLines,
shape,
this.lineAlignment
);
this.graphicsData.push(data);
if (data.type === SHAPES.POLY)
{
data.shape.closed = data.shape.closed;
this.currentPath = data;
}
this.dirty++;
return data;
}
function buildNativeLine(graphicsData, graphicsGeometry)
{
let i = 0;
const shape = graphicsData.shape;
const points = graphicsData.points || shape.points;
const closedShape = shape.type !== SHAPES.POLY || shape.closeStroke;
if (points.length === 0) return;
const verts = graphicsGeometry.points;
const indices = graphicsGeometry.indices;
const length = points.length / 2;
const startIndex = verts.length / 2;
let currentIndex = startIndex;
verts.push(points[0], points[1]);
for (i = 1; i < length; i++)
{
verts.push(points[i * 2], points[(i * 2) + 1]);
indices.push(currentIndex, currentIndex + 1);