mirror of
https://github.com/mum4k/termdash.git
synced 2025-05-10 19:29:15 +08:00

Done here: - adding helper library which determines area from size and vice versa. - fixing an off-by-one bug related to area sizes. - allowing overwrite of cell options by passing an existing cell.Options instance. - implementing canvas and its tests.
24 lines
562 B
Go
24 lines
562 B
Go
// Package area provides functions working with image areas.
|
|
package area
|
|
|
|
import (
|
|
"fmt"
|
|
"image"
|
|
)
|
|
|
|
// Size returns the size of the provided area.
|
|
func Size(area image.Rectangle) image.Point {
|
|
return image.Point{
|
|
area.Dx(),
|
|
area.Dy(),
|
|
}
|
|
}
|
|
|
|
// FromSize returns the corresponding area for the provided size.
|
|
func FromSize(size image.Point) (image.Rectangle, error) {
|
|
if size.X < 0 || size.Y < 0 {
|
|
return image.Rectangle{}, fmt.Errorf("cannot convert zero or negative size to an area, got: %+v", size)
|
|
}
|
|
return image.Rect(0, 0, size.X, size.Y), nil
|
|
}
|