-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition.go
More file actions
31 lines (25 loc) · 808 Bytes
/
position.go
File metadata and controls
31 lines (25 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2025 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package pi
// Position represents a 2D integer coordinate.
//
// It stores X and Y values in a 2D grid.
type Position struct{ X, Y int }
// Add returns a new Position after adding coordinates with other
func (p Position) Add(other Position) Position {
return Position{p.X + other.X, p.Y + other.Y}
}
// Subtract returns a new Position after subtracting coordinates with other
func (p Position) Subtract(other Position) Position {
return Position{p.X - other.X, p.Y - other.Y}
}
// WithX returns a new Position with updated X.
func (p Position) WithX(x int) Position {
p.X = x
return p
}
// WithY returns a new Position with updated Y.
func (p Position) WithY(y int) Position {
p.Y = y
return p
}