Skip to content

Commit

Permalink
add Area.String()
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 2, 2024
1 parent ec7118e commit f486032
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions area.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package types

import "fmt"

type Area struct {
Pos1 *Pos
Pos2 *Pos
Pos1 *Pos `json:"pos1"`
Pos2 *Pos `json:"pos2"`
}

func NewArea(p1, p2 *Pos) *Area {
p1, p2 = SortPos(p1, p2)
return &Area{Pos1: p1, Pos2: p2}
}

func (a *Area) String() string {
return fmt.Sprintf("Area{%v,%v}", a.Pos1, a.Pos2)
}

// the inclusive size
func (a *Area) Size() *Pos {
return a.Pos2.Subtract(a.Pos1).Add(NewPos(1, 1, 1))
Expand Down

0 comments on commit f486032

Please sign in to comment.