mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-30 13:48:54 +08:00
Method that returns the underlying cell area.
This commit is contained in:
parent
4981ad23e2
commit
3615294c34
@ -110,6 +110,11 @@ func (c *Canvas) Size() image.Point {
|
|||||||
return image.Point{s.X * ColMult, s.Y * RowMult}
|
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.
|
// 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
|
// This will be zero-based area that is two times wider and four times taller
|
||||||
// than the area used to create the braille canvas.
|
// than the area used to create the braille canvas.
|
||||||
|
@ -74,11 +74,12 @@ func Example_appliedToTerminal() {
|
|||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
ar image.Rectangle
|
ar image.Rectangle
|
||||||
wantSize image.Point
|
wantSize image.Point
|
||||||
wantArea image.Rectangle
|
wantArea image.Rectangle
|
||||||
wantErr bool
|
wantCellArea image.Rectangle
|
||||||
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "fails on a negative area",
|
desc: "fails on a negative area",
|
||||||
@ -86,34 +87,39 @@ func TestNew(t *testing.T) {
|
|||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "braille from zero-based single-cell area",
|
desc: "braille from zero-based single-cell area",
|
||||||
ar: image.Rect(0, 0, 1, 1),
|
ar: image.Rect(0, 0, 1, 1),
|
||||||
wantSize: image.Point{2, 4},
|
wantSize: image.Point{2, 4},
|
||||||
wantArea: image.Rect(0, 0, 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",
|
desc: "braille from non-zero-based single-cell area",
|
||||||
ar: image.Rect(3, 3, 4, 4),
|
ar: image.Rect(3, 3, 4, 4),
|
||||||
wantSize: image.Point{2, 4},
|
wantSize: image.Point{2, 4},
|
||||||
wantArea: image.Rect(0, 0, 2, 4),
|
wantArea: image.Rect(0, 0, 2, 4),
|
||||||
|
wantCellArea: image.Rect(0, 0, 1, 1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "braille from zero-based multi-cell area",
|
desc: "braille from zero-based multi-cell area",
|
||||||
ar: image.Rect(0, 0, 3, 3),
|
ar: image.Rect(0, 0, 3, 3),
|
||||||
wantSize: image.Point{6, 12},
|
wantSize: image.Point{6, 12},
|
||||||
wantArea: image.Rect(0, 0, 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",
|
desc: "braille from non-zero-based multi-cell area",
|
||||||
ar: image.Rect(6, 6, 9, 9),
|
ar: image.Rect(6, 6, 9, 9),
|
||||||
wantSize: image.Point{6, 12},
|
wantSize: image.Point{6, 12},
|
||||||
wantArea: image.Rect(0, 0, 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",
|
desc: "braille from non-zero-based multi-cell rectangular area",
|
||||||
ar: image.Rect(6, 6, 9, 10),
|
ar: image.Rect(6, 6, 9, 10),
|
||||||
wantSize: image.Point{6, 16},
|
wantSize: image.Point{6, 16},
|
||||||
wantArea: image.Rect(0, 0, 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 != "" {
|
if diff := pretty.Compare(tc.wantArea, gotArea); diff != "" {
|
||||||
t.Errorf("Area => unexpected diff (-want, +got):\n%s", 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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user