mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-27 13:48:49 +08:00
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
|
||
|
}
|