Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/v8/hole bounds check #9890

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/scene/graphics/shared/GraphicsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,23 +418,40 @@ export class GraphicsContext extends EventEmitter<{
*/
public cut(): this
{
for (let i = 0; i < 2; i++)
for (let i = 0; i < this.instructions.length; i++)
{
const lastInstruction = this.instructions[this.instructions.length - 1 - i];
const instruction = this.instructions[i];

const holePath = this._activePath.clone();

if (lastInstruction)
// make sure the hole is inside the shape
const data = instruction.data as FillInstruction['data'];
const path = data.path;

const shapes = path.shapePath.shapePrimitives;
const [x, y] = (holePath.shapePath.shapePrimitives[0].shape as any).points;

let inside = false;

shapes.forEach((shapePrimitive) =>
{
if (shapePrimitive.shape.contains(x, y))
{
inside = true;
}
});

if (instruction && inside)
{
if (lastInstruction.action === 'stroke' || lastInstruction.action === 'fill')
if (instruction.action === 'stroke' || instruction.action === 'fill')
{
if (lastInstruction.data.hole)
if (instruction.data.hole)
{
lastInstruction.data.hole.addPath(holePath);
instruction.data.hole.addPath(holePath);
}
else
{
lastInstruction.data.hole = holePath;
instruction.data.hole = holePath;
break;
}
}
Expand Down