gitstack

grindlemire/go-tui code browser

498 B Go 21 lines 2026-01-31 · d1f6635 raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package layout

// Point represents an (X, Y) coordinate.
type Point struct {
	X, Y int
}

// Add returns a new Point offset by other.
func (p Point) Add(other Point) Point {
	return Point{X: p.X + other.X, Y: p.Y + other.Y}
}

// Sub returns a new Point with other subtracted.
func (p Point) Sub(other Point) Point {
	return Point{X: p.X - other.X, Y: p.Y - other.Y}
}

// In returns true if the point is inside the given rectangle.
func (p Point) In(r Rect) bool {
	return r.Contains(p.X, p.Y)
}