1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-25 13:48:50 +08:00

Method that returns the underlying cell area.

This commit is contained in:
Jakub Sobon 2019-02-16 16:34:54 -05:00
parent 4981ad23e2
commit 3615294c34
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
2 changed files with 41 additions and 25 deletions

View File

@ -110,6 +110,11 @@ func (c *Canvas) Size() image.Point {
return image.Point{s.X * ColMult, s.Y * RowMult}
}
// CellArea returns the area of the underlying cell canvas in cells.
func (c *Canvas) CellArea() image.Rectangle {
return c.regular.Area()
}
// Area returns the area of the braille canvas in pixels.
// This will be zero-based area that is two times wider and four times taller
// than the area used to create the braille canvas.

View File

@ -74,11 +74,12 @@ func Example_appliedToTerminal() {
func TestNew(t *testing.T) {
tests := []struct {
desc string
ar image.Rectangle
wantSize image.Point
wantArea image.Rectangle
wantErr bool
desc string
ar image.Rectangle
wantSize image.Point
wantArea image.Rectangle
wantCellArea image.Rectangle
wantErr bool
}{
{
desc: "fails on a negative area",
@ -86,34 +87,39 @@ func TestNew(t *testing.T) {
wantErr: true,
},
{
desc: "braille from zero-based single-cell area",
ar: image.Rect(0, 0, 1, 1),
wantSize: image.Point{2, 4},
wantArea: image.Rect(0, 0, 2, 4),
desc: "braille from zero-based single-cell area",
ar: image.Rect(0, 0, 1, 1),
wantSize: image.Point{2, 4},
wantArea: image.Rect(0, 0, 2, 4),
wantCellArea: image.Rect(0, 0, 1, 1),
},
{
desc: "braille from non-zero-based single-cell area",
ar: image.Rect(3, 3, 4, 4),
wantSize: image.Point{2, 4},
wantArea: image.Rect(0, 0, 2, 4),
desc: "braille from non-zero-based single-cell area",
ar: image.Rect(3, 3, 4, 4),
wantSize: image.Point{2, 4},
wantArea: image.Rect(0, 0, 2, 4),
wantCellArea: image.Rect(0, 0, 1, 1),
},
{
desc: "braille from zero-based multi-cell area",
ar: image.Rect(0, 0, 3, 3),
wantSize: image.Point{6, 12},
wantArea: image.Rect(0, 0, 6, 12),
desc: "braille from zero-based multi-cell area",
ar: image.Rect(0, 0, 3, 3),
wantSize: image.Point{6, 12},
wantArea: image.Rect(0, 0, 6, 12),
wantCellArea: image.Rect(0, 0, 3, 3),
},
{
desc: "braille from non-zero-based multi-cell area",
ar: image.Rect(6, 6, 9, 9),
wantSize: image.Point{6, 12},
wantArea: image.Rect(0, 0, 6, 12),
desc: "braille from non-zero-based multi-cell area",
ar: image.Rect(6, 6, 9, 9),
wantSize: image.Point{6, 12},
wantArea: image.Rect(0, 0, 6, 12),
wantCellArea: image.Rect(0, 0, 3, 3),
},
{
desc: "braille from non-zero-based multi-cell rectangular area",
ar: image.Rect(6, 6, 9, 10),
wantSize: image.Point{6, 16},
wantArea: image.Rect(0, 0, 6, 16),
desc: "braille from non-zero-based multi-cell rectangular area",
ar: image.Rect(6, 6, 9, 10),
wantSize: image.Point{6, 16},
wantArea: image.Rect(0, 0, 6, 16),
wantCellArea: image.Rect(0, 0, 3, 4),
},
}
@ -136,6 +142,11 @@ func TestNew(t *testing.T) {
if diff := pretty.Compare(tc.wantArea, gotArea); diff != "" {
t.Errorf("Area => unexpected diff (-want, +got):\n%s", diff)
}
gotCellArea := got.CellArea()
if diff := pretty.Compare(tc.wantCellArea, gotCellArea); diff != "" {
t.Errorf("CellArea => unexpected diff (-want, +got):\n%s", diff)
}
})
}
}