diff --git a/render/loadsheet.go b/render/loadsheet.go index 1db88a37..2d23313e 100644 --- a/render/loadsheet.go +++ b/render/loadsheet.go @@ -51,8 +51,15 @@ func MakeSheet(rgba *image.RGBA, cellSize intgeom.Point2) (*Sheet, error) { bounds := rgba.Bounds() sheetW := bounds.Max.X / w + wMod := bounds.Max.X % w + if wMod != 0 { + return nil, oakerr.InvalidInput{InputName: "cellSize.X"} + } sheetH := bounds.Max.Y / h - + hMod := bounds.Max.Y % h + if hMod != 0 { + return nil, oakerr.InvalidInput{InputName: "cellSize.Y"} + } if sheetW < 1 || sheetH < 1 { return nil, oakerr.InvalidInput{InputName: "cellSize"} } diff --git a/render/loadsheet_test.go b/render/loadsheet_test.go index 1a079522..40079927 100644 --- a/render/loadsheet_test.go +++ b/render/loadsheet_test.go @@ -2,6 +2,7 @@ package render import ( "errors" + "image" "os" "path/filepath" "testing" @@ -72,3 +73,26 @@ func TestMakeSheet_BadDimensions(t *testing.T) { t.Fatalf("expected invalid height, got %v", expected.InputName) } } + +func TestMakeSheet_BadMod(t *testing.T) { + rgba := &image.RGBA{ + Rect: image.Rect(0, 0, 10, 10), + } + _, err := MakeSheet(rgba, intgeom.Point2{4, 5}) + expected := &oakerr.InvalidInput{} + if !errors.As(err, expected) { + t.Fatalf("expected invalid input error, got %v", err) + } + if expected.InputName != "cellSize.X" { + t.Fatalf("expected invalid width, got %v", expected.InputName) + } + + _, err = MakeSheet(rgba, intgeom.Point2{5, 4}) + expected = &oakerr.InvalidInput{} + if !errors.As(err, expected) { + t.Fatalf("expected invalid input error, got %v", err) + } + if expected.InputName != "cellSize.Y" { + t.Fatalf("expected invalid height, got %v", expected.InputName) + } +}