diff --git a/internal/segdisp/dotseg/attributes.go b/internal/segdisp/dotseg/attributes.go index eeb81f0..3ab2148 100644 --- a/internal/segdisp/dotseg/attributes.go +++ b/internal/segdisp/dotseg/attributes.go @@ -29,22 +29,6 @@ import ( "github.com/mum4k/termdash/internal/segdisp/sixteen" ) -// segmentSize given an area for the display determines the size of individual -// segments, i.e. the width of a vertical or the height of a horizontal -// segment. -func segmentSize(ar image.Rectangle) int { - // widthPerc is the relative width of a segment to the width of the canvas. - const widthPerc = 9 - s := int(math.Round(float64(ar.Dx()) * widthPerc / 100)) - if s > 3 && s%2 == 0 { - // Segments with odd number of pixels in their width/height look - // better, since the spike at the top of their slopes has only one - // pixel. - s++ - } - return s -} - // attributes contains attributes needed to draw the segment display. // Refer to doc/segment_placement.svg for a visual aid and explanation of the // usage of the square roots. diff --git a/internal/segdisp/dotseg/dotseg_test.go b/internal/segdisp/dotseg/dotseg_test.go index 63d57cf..47d1b2d 100644 --- a/internal/segdisp/dotseg/dotseg_test.go +++ b/internal/segdisp/dotseg/dotseg_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/kylelemons/godebug/pretty" + "github.com/mum4k/termdash/cell" "github.com/mum4k/termdash/internal/area" "github.com/mum4k/termdash/internal/canvas" "github.com/mum4k/termdash/internal/canvas/braille/testbraille" @@ -127,6 +128,85 @@ func TestDraw(t *testing.T) { return ft }, }, + { + desc: "smallest valid display 6x5, all segments, sets cell options", + opts: []Option{ + CellOpts( + cell.FgColor(cell.ColorRed), + cell.BgColor(cell.ColorGreen), + ), + }, + cellCanvas: image.Rect(0, 0, segdisp.MinCols, segdisp.MinRows), + update: func(d *Display) error { + for _, seg := range AllSegments() { + if err := d.SetSegment(seg); err != nil { + return err + } + } + return nil + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + bc := testbraille.MustNew(ft.Area()) + + opts := []segment.Option{ + segment.CellOpts( + cell.FgColor(cell.ColorRed), + cell.BgColor(cell.ColorGreen), + ), + } + testsegment.MustHV(bc, image.Rect(5, 6, 7, 8), segment.Horizontal, opts...) // D1 + testsegment.MustHV(bc, image.Rect(5, 12, 7, 14), segment.Horizontal, opts...) // D2 + testsegment.MustHV(bc, image.Rect(5, 15, 7, 17), segment.Horizontal, opts...) // D5 + testbraille.MustApply(bc, ft) + return ft + }, + }, + { + desc: "smallest valid display 6x5, D1", + cellCanvas: image.Rect(0, 0, segdisp.MinCols, segdisp.MinRows), + update: func(d *Display) error { + return d.SetSegment(D1) + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + bc := testbraille.MustNew(ft.Area()) + + testsegment.MustHV(bc, image.Rect(5, 6, 7, 8), segment.Horizontal) // D1 + testbraille.MustApply(bc, ft) + return ft + }, + }, + { + desc: "smallest valid display 6x5, D2", + cellCanvas: image.Rect(0, 0, segdisp.MinCols, segdisp.MinRows), + update: func(d *Display) error { + return d.SetSegment(D2) + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + bc := testbraille.MustNew(ft.Area()) + + testsegment.MustHV(bc, image.Rect(5, 12, 7, 14), segment.Horizontal) // D2 + testbraille.MustApply(bc, ft) + return ft + }, + }, + { + desc: "smallest valid display 6x5, D3", + cellCanvas: image.Rect(0, 0, segdisp.MinCols, segdisp.MinRows), + update: func(d *Display) error { + return d.SetSegment(D3) + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + bc := testbraille.MustNew(ft.Area()) + + testsegment.MustHV(bc, image.Rect(5, 15, 7, 17), segment.Horizontal) // D3 + testbraille.MustApply(bc, ft) + return ft + }, + }, } for _, tc := range tests {