横线直线搜索bug处理

This commit is contained in:
kercylan98 2023-06-05 19:39:32 +08:00
parent 10d9f26870
commit 540d671d8c
1 changed files with 10 additions and 12 deletions

View File

@ -250,9 +250,6 @@ func SearchNotRepeatStraightLine(minLength int, xys ...[2]int) (result [][][2]in
find[1] = true
points = append(points, [2]int{sx + left, y + top})
}
if !find[1] {
goto up
}
for sx := x + 1; sx < len(rectangleShape); sx++ {
if !rectangleShape[sx][y] {
break
@ -260,10 +257,11 @@ func SearchNotRepeatStraightLine(minLength int, xys ...[2]int) (result [][][2]in
find[2] = true
points = append(points, [2]int{sx + left, y + top})
}
if !find[2] {
if len(find) == 2 {
goto end
} else {
points = nil
}
up:
for sy := y - 1; sy >= 0; sy-- {
if !rectangleShape[x][sy] {
break
@ -271,9 +269,6 @@ func SearchNotRepeatStraightLine(minLength int, xys ...[2]int) (result [][][2]in
find[3] = true
points = append(points, [2]int{x + left, sy + top})
}
if !find[3] {
continue
}
for sy := y + 1; sy < len(rectangleShape[0]); sy++ {
if !rectangleShape[x][sy] {
break
@ -281,13 +276,16 @@ func SearchNotRepeatStraightLine(minLength int, xys ...[2]int) (result [][][2]in
find[4] = true
points = append(points, [2]int{x + left, sy + top})
}
if !find[4] {
if !find[3] && !find[4] {
continue
}
if len(find) != 2 {
continue
end:
{
if len(find) != 2 {
continue
}
result = append(result, append(points, [2]int{x + left, y + top}))
}
result = append(result, append(points, [2]int{x + left, y + top}))
}
sort.Slice(result, func(i, j int) bool {