获取一个宽高可表达的所有特定尺寸以上的矩形形状bug处理

This commit is contained in:
kercylan98 2023-06-07 16:03:57 +08:00
parent b51f0d65d3
commit aac9d8a9fc
1 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package g2d package g2d
import ( import (
"fmt"
"github.com/kercylan98/minotaur/utils/g2d/shape" "github.com/kercylan98/minotaur/utils/g2d/shape"
"sort" "sort"
) )
@ -529,6 +530,10 @@ func SearchNotRepeatFullRectangle(minWidth, minHeight int, xys ...[2]int) (resul
for _, point := range points { for _, point := range points {
px, py := PositionArrayToXY(point) px, py := PositionArrayToXY(point)
ox, oy := px+x, py+y ox, oy := px+x, py+y
if ox >= len(rectangleShape) || oy >= len(rectangleShape[0]) {
rectangleShape := GenerateShape(xys...)
fmt.Println(rectangleShape)
}
if record[ox][oy] || !rectangleShape[ox][oy] { if record[ox][oy] || !rectangleShape[ox][oy] {
find = 0 find = 0
break break
@ -584,6 +589,7 @@ func GetExpressibleRectangle(width, height int) (result [][2]int) {
// - 返回值表示了每一个矩形右下角的x,y位置左上角始终为0, 0 // - 返回值表示了每一个矩形右下角的x,y位置左上角始终为0, 0
// - 矩形尺寸由大到小 // - 矩形尺寸由大到小
func GetExpressibleRectangleBySize(width, height, minWidth, minHeight int) (result [][2]int) { func GetExpressibleRectangleBySize(width, height, minWidth, minHeight int) (result [][2]int) {
sourceWidth := width
if width == 0 || height == 0 { if width == 0 || height == 0 {
return nil return nil
} }
@ -601,8 +607,12 @@ func GetExpressibleRectangleBySize(width, height, minWidth, minHeight int) (resu
if width == height { if width == height {
width-- width--
} else if width < height { } else if width < height {
if width+1 == sourceWidth {
height--
} else {
width++ width++
height-- height--
}
} else if width > height { } else if width > height {
width-- width--
} }