This repository has been archived on 2022-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
spectator/exhibit/block.go

38 lines
652 B
Go
Raw Normal View History

2017-12-28 19:21:01 -07:00
package exhibit
import (
"image"
)
type Block struct {
Rect image.Rectangle
2017-12-28 19:21:01 -07:00
Cells map[image.Point]Cell
}
func NewBlock(originx, originy, sizex, sizey int) Block {
2017-12-28 19:21:01 -07:00
b := Block{}
b.Rect = image.Rect(originx, originy, originx+sizex, originy+sizey)
b.Cells = make(map[image.Point]Cell)
2017-12-28 19:21:01 -07:00
return b
}
func (b Block) Size() image.Point {
return b.Rect.Size()
}
func (b *Block) SetSize(p image.Point) {
dx := b.Rect.Min.X
dy := b.Rect.Min.Y
b.Rect.Max.X = p.X + dx
b.Rect.Max.Y = p.Y + dy
}
func (b Block) Origin() image.Point {
return b.Rect.Min
}
func (b *Block) SetOrigin(p image.Point) {
d := p.Sub(b.Rect.Min)
b.Rect = b.Rect.Add(d)
}