From a7b603740f9b3eb3d95a106243679d041279416d Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Mon, 24 Apr 2023 12:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Matrix.TrySwap=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/g2d/matrix/matrix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/g2d/matrix/matrix.go b/utils/g2d/matrix/matrix.go index 0b49893..4514d6b 100644 --- a/utils/g2d/matrix/matrix.go +++ b/utils/g2d/matrix/matrix.go @@ -50,10 +50,10 @@ func (slf *Matrix[T]) Swap(x1, y1, x2, y2 int) { } // TrySwap 尝试交换两个位置的内容,交换后不满足表达式时进行撤销 -func (slf *Matrix[T]) TrySwap(x1, y1, x2, y2 int, expression bool) { +func (slf *Matrix[T]) TrySwap(x1, y1, x2, y2 int, expressionHandle func(matrix *Matrix[T]) bool) { a, b := slf.Get(x1, y1), slf.Get(x2, y2) slf.m[x1][y1], slf.m[x2][y2] = b, a - if expression { + if !expressionHandle(slf) { slf.m[x1][y1], slf.m[x2][y2] = a, b } }