From 7dad068ea30ad24baa1bc3359ef830a7a9fbfcbd Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Sat, 22 Jan 2022 20:14:33 +0100 Subject: [PATCH] waveshare2in13v2: Unexport drawSpec members The members of the "drawSpec" structure are only for internal use, so rename them to start with a lower-case letter. --- waveshare2in13v2/drawing.go | 26 +++++++++++++------------- waveshare2in13v2/drawing_test.go | 10 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/waveshare2in13v2/drawing.go b/waveshare2in13v2/drawing.go index ffdbfe9..f73192c 100644 --- a/waveshare2in13v2/drawing.go +++ b/waveshare2in13v2/drawing.go @@ -52,21 +52,21 @@ type drawOpts struct { type drawSpec struct { // Destination on display in pixels, normalized to fit into actual size. - DstRect image.Rectangle + dstRect image.Rectangle // Area to send to device; horizontally in bytes (thus aligned to // 8 pixels), vertically in pixels. - MemRect image.Rectangle + memRect image.Rectangle } func (o *drawOpts) spec() drawSpec { s := drawSpec{ - DstRect: image.Rectangle{Max: o.devSize}.Intersect(o.dstRect), + dstRect: image.Rectangle{Max: o.devSize}.Intersect(o.dstRect), } - s.MemRect = image.Rect( - s.DstRect.Min.X/8, s.DstRect.Min.Y, - (s.DstRect.Max.X+7)/8, s.DstRect.Max.Y, + s.memRect = image.Rect( + s.dstRect.Min.X/8, s.dstRect.Min.Y, + (s.dstRect.Max.X+7)/8, s.dstRect.Max.Y, ) return s @@ -74,22 +74,22 @@ func (o *drawOpts) spec() drawSpec { // sendImage sends an image to the controller after setting up the registers. func (o *drawOpts) sendImage(ctrl controller, cmd byte, spec *drawSpec) { - if spec.MemRect.Empty() { + if spec.memRect.Empty() { return } - setMemoryArea(ctrl, spec.MemRect) + setMemoryArea(ctrl, spec.memRect) ctrl.sendCommand(cmd) - rowData := make([]byte, spec.MemRect.Dx()) + rowData := make([]byte, spec.memRect.Dx()) - for y := spec.MemRect.Min.Y; y < spec.MemRect.Max.Y; y++ { + for y := spec.memRect.Min.Y; y < spec.memRect.Max.Y; y++ { for x := 0; x < len(rowData); x++ { rowData[x] = 0 for bit := 0; bit < 8; bit++ { - if o.buffer.BitAt(((spec.MemRect.Min.X+x)*8)+bit, y) { + if o.buffer.BitAt(((spec.memRect.Min.X+x)*8)+bit, y) { rowData[x] |= 0x80 >> bit } } @@ -102,11 +102,11 @@ func (o *drawOpts) sendImage(ctrl controller, cmd byte, spec *drawSpec) { func drawImage(ctrl controller, opts *drawOpts) { s := opts.spec() - if s.MemRect.Empty() { + if s.memRect.Empty() { return } - draw.Src.Draw(opts.buffer, s.DstRect, opts.src, opts.srcPts) + draw.Src.Draw(opts.buffer, s.dstRect, opts.src, opts.srcPts) commands := opts.commands diff --git a/waveshare2in13v2/drawing_test.go b/waveshare2in13v2/drawing_test.go index da0051c..da1c3e0 100644 --- a/waveshare2in13v2/drawing_test.go +++ b/waveshare2in13v2/drawing_test.go @@ -32,8 +32,8 @@ func TestDrawSpec(t *testing.T) { dstRect: image.Rect(17, 4, 25, 8), }, want: drawSpec{ - DstRect: image.Rect(17, 4, 25, 8), - MemRect: image.Rect(2, 4, 4, 8), + dstRect: image.Rect(17, 4, 25, 8), + memRect: image.Rect(2, 4, 4, 8), }, }, { @@ -44,15 +44,15 @@ func TestDrawSpec(t *testing.T) { dstRect: image.Rect(-20, 50, 125, 300), }, want: drawSpec{ - DstRect: image.Rect(0, 50, 100, 200), - MemRect: image.Rect(0, 50, 13, 200), + dstRect: image.Rect(0, 50, 100, 200), + memRect: image.Rect(0, 50, 13, 200), }, }, } { t.Run(tc.name, func(t *testing.T) { got := tc.opts.spec() - if diff := cmp.Diff(got, tc.want, cmpopts.EquateEmpty()); diff != "" { + if diff := cmp.Diff(got, tc.want, cmp.AllowUnexported(drawSpec{})); diff != "" { t.Errorf("spec() difference (-got +want):\n%s", diff) } })