Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf34946

Browse files
vil02appgurueu
andcommitted
refactor: add and useisInside
Co-authored-by: appgurueu <34514239+appgurueu@users.noreply.github.com>
1 parent0e42fe0 commitcf34946

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

‎Recursive/FloodFill.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ const neighbors = [
2020
[1,1]
2121
]
2222

23+
functionisInside(rgbData,location){
24+
constx=location[0]
25+
consty=location[1]
26+
returnx>=0&&x<rgbData.length&&y>=0&&y<rgbData[0].length
27+
}
28+
2329
functioncheckLocation(rgbData,location){
24-
if(
25-
location[0]<0||
26-
location[0]>=rgbData.length||
27-
location[1]<0||
28-
location[1]>=rgbData[0].length
29-
){
30+
if(!isInside(rgbData,location)){
3031
thrownewError('location should point to a pixel within the rgbData')
3132
}
3233
}
@@ -119,10 +120,12 @@ function depthFirstFill(rgbData, location, targetColor, replacementColor) {
119120
rgbData[location[0]][location[1]]=replacementColor
120121

121122
for(leti=0;i<neighbors.length;i++){
122-
constx=location[0]+neighbors[i][0]
123-
consty=location[1]+neighbors[i][1]
124-
if(x>=0&&x<rgbData.length&&y>=0&&y<rgbData[0].length){
125-
depthFirstFill(rgbData,[x,y],targetColor,replacementColor)
123+
constnewLocation=[
124+
location[0]+neighbors[i][0],
125+
location[1]+neighbors[i][1]
126+
]
127+
if(isInside(rgbData,newLocation)){
128+
depthFirstFill(rgbData,newLocation,targetColor,replacementColor)
126129
}
127130
}
128131
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp