Make flood fill use shape bounds to instead of stage

This commit is contained in:
Skyler Lehmkuhl 2025-01-10 18:28:21 -05:00
parent 596dd9501c
commit cf90cc183c
1 changed files with 20 additions and 7 deletions

View File

@ -178,13 +178,7 @@ function floodFillRegion(
context, context,
debugPoints, debugPoints,
debugPaintbucket) { debugPaintbucket) {
// Helper function to check if the point is at the boundary of the region
function isBoundaryPoint(point) {
return point.x <= 0 || point.x >= fileWidth ||
point.y <= 0 || point.y >= fileHeight;
return point.x <= offset.x || point.x >= offset.x + fileWidth ||
point.y <= offset.y || point.y >= offset.y + fileHeight;
}
let halfEpsilon = epsilon/2 let halfEpsilon = epsilon/2
// Helper function to check if a point is near any curve in the shape // Helper function to check if a point is near any curve in the shape
@ -212,6 +206,24 @@ function floodFillRegion(
const visited = new Set(); const visited = new Set();
const stack = [startPoint]; const stack = [startPoint];
const regionPoints = []; const regionPoints = [];
let bbox;
if (shapes.length>0) {
bbox = shapes[0].boundingBox
} else {
throw new Error("No shapes in layer")
}
for (const shape of shapes) {
growBoundingBox(bbox, shape.boundingBox)
}
console.log(bbox)
console.log(startPoint)
// Helper function to check if the point is at the boundary of the region
function isBoundaryPoint(point) {
return point.x <= bbox.x.min - 100 || point.x >= bbox.x.max + 100 ||
point.y <= bbox.y.min - 100 || point.y >= bbox.y.max + 100;
return point.x <= offset.x || point.x >= offset.x + fileWidth ||
point.y <= offset.y || point.y >= offset.y + fileHeight;
}
// Begin the flood fill process // Begin the flood fill process
while (stack.length > 0) { while (stack.length > 0) {
@ -898,6 +910,7 @@ export {
lerpColor, lerpColor,
camelToWords, camelToWords,
generateWaveform, generateWaveform,
growBoundingBox,
floodFillRegion, floodFillRegion,
multiplyMatrices, multiplyMatrices,
getShapeAtPoint, getShapeAtPoint,