GetRectangleFullPointsByXY

通过开始结束坐标获取一个矩形包含的所有点
This commit is contained in:
kercylan98 2023-06-05 14:01:59 +08:00
parent 239d2a9140
commit d332724ece
1 changed files with 11 additions and 0 deletions

View File

@ -562,6 +562,17 @@ func GetRectangleFullPoints(width, height int) (result [][2]int) {
return
}
// GetRectangleFullPointsByXY 通过开始结束坐标获取一个矩形包含的所有点
// - 例如 1,1 到 2,2 的矩形结果为 1,1 2,1 1,2 2,2
func GetRectangleFullPointsByXY(startX, startY, endX, endY int) (result [][2]int) {
for x := startX; x <= endX; x++ {
for y := startY; y <= endY; y++ {
result = append(result, [2]int{x, y})
}
}
return
}
// GetExpressibleRectangle 获取一个宽高可表达的所有矩形形状
// - 返回值表示了每一个矩形右下角的x,y位置左上角始终为0, 0
// - 矩形尺寸由大到小