diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 17:55:53 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 23:02:21 +0200 |
| commit | a5fef758107888853c14a592696b45768ef56df8 (patch) | |
| tree | 9d1fd0b0abb49ce6814b8868926bf7af83611303 /physics/geometry.go | |
| parent | e3f14fc0b375b4b7c2204a669d058ac124b78e92 (diff) | |
Refactor into packages
Diffstat (limited to 'physics/geometry.go')
| -rw-r--r-- | physics/geometry.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/physics/geometry.go b/physics/geometry.go new file mode 100644 index 0000000..1902fdf --- /dev/null +++ b/physics/geometry.go @@ -0,0 +1,30 @@ +package physics + +import ( + "image" + "math" +) + +type Point = image.Point +type Rectangle = image.Rectangle + +func Distance(p1, p2 Point) float64 { + return math.Sqrt(math.Pow(float64(p1.X-p2.X), 2) + math.Pow(float64(p1.Y-p2.Y), 2)) +} + +func Length(p Point) float64 { + return Distance(p, Point{X:0,Y:0}) +} + +func Normalize(p Point) Point { + return p.Div(int(Length(p))) +} + +func AdjacentPoints(from Point) []Point { + return []Point{ + from.Add(Point{X: 0, Y: -100}), + from.Add(Point{X: 0, Y: 100}), + from.Add(Point{X: -100, Y: 0}), + from.Add(Point{X: 100, Y: 0}), + } +} |
