HV draws a horizontal or a vertical display segment, filling the provided area. The segment will have slopes on both of its ends.
(bc *braille.Canvas, ar image.Rectangle, st Type, opts ...Option)
| 127 | // HV draws a horizontal or a vertical display segment, filling the provided area. |
| 128 | // The segment will have slopes on both of its ends. |
| 129 | func HV(bc *braille.Canvas, ar image.Rectangle, st Type, opts ...Option) error { |
| 130 | if err := validArea(ar); err != nil { |
| 131 | return err |
| 132 | } |
| 133 | |
| 134 | opt := &options{} |
| 135 | for _, o := range opts { |
| 136 | o.set(opt) |
| 137 | } |
| 138 | |
| 139 | var nextLine nextHVLineFn |
| 140 | var lines int |
| 141 | switch st { |
| 142 | case Horizontal: |
| 143 | lines = ar.Dy() |
| 144 | nextLine = nextHorizLine |
| 145 | |
| 146 | case Vertical: |
| 147 | lines = ar.Dx() |
| 148 | nextLine = nextVertLine |
| 149 | |
| 150 | default: |
| 151 | return fmt.Errorf("unsupported segment type %v(%d)", st, st) |
| 152 | } |
| 153 | |
| 154 | for i := 0; i < lines; i++ { |
| 155 | start, end := nextLine(i, ar, opt) |
| 156 | if err := draw.BrailleLine(bc, start, end, draw.BrailleLineCellOpts(opt.cellOpts...)); err != nil { |
| 157 | return err |
| 158 | } |
| 159 | |
| 160 | } |
| 161 | return nil |
| 162 | } |
| 163 | |
| 164 | // nextHVLineFn is a function that determines the start and end points of a line |
| 165 | // number num in a horizontal or a vertical segment. |