1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-05-10 19:29:15 +08:00
termdash/area/area.go
Jakub Sobon dc1f2c5a29
Implementing canvas functionality.
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.
2018-03-29 03:28:36 +03:00

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
}