From d332724ecee3536467dd8fabc2a373f8f8a4aa87 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Mon, 5 Jun 2023 14:01:59 +0800 Subject: [PATCH] =?UTF-8?q?GetRectangleFullPointsByXY=20=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E7=BB=93=E6=9D=9F=E5=9D=90=E6=A0=87=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=80=E4=B8=AA=E7=9F=A9=E5=BD=A2=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/g2d/shape.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/g2d/shape.go b/utils/g2d/shape.go index 7e393a9..8b7f013 100644 --- a/utils/g2d/shape.go +++ b/utils/g2d/shape.go @@ -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) // - 矩形尺寸由大到小