first commit

This commit is contained in:
hero920103 committed 2026-10-27 17:58:28 +08:00
commit 3553790475
27 files changed
+3839

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
package capture
import "testing"
func TestMappingRoundTrip(t *testing.T) {
// 模拟 125% 缩放的副屏:窗口左上角在 (-1920,0)
m := Mapping{OffsetX: -1920, OffsetY: 0, ScaleX: 1.25, ScaleY: 1.25}
got := m.ToPhysical(100, 100, 400, 200)
want := Region{X: -1795, Y: 125, W: 500, H: 250}
if got != want {
t.Fatalf("逻辑→物理换算错误,期望 %+v,实际 %+v", want, got)
}
x, y, w, h := m.ToLogical(got)
if x != 100 || y != 100 || w != 400 || h != 200 {
t.Fatalf("物理→逻辑逆向换算错误:%v %v %v %v", x, y, w, h)
}
}
func TestRegionValidAndInset(t *testing.T) {
if (Region{}).Valid() {
t.Fatal("零区域不应有效")
}
r := Region{X: 10, Y: 20, W: 100, H: 50}
if !r.Valid() {
t.Fatal("正常区域应有效")
}
in := r.Inset(5)
if in != (Region{X: 15, Y: 25, W: 90, H: 40}) {
t.Fatalf("Inset 结果错误: %+v", in)
}
// 收缩超过一半时保持原样,避免出现负尺寸
if r.Inset(60) != r {
t.Fatal("过度收缩应返回原区域")
}
}