From d4283a02e30348e73bce786e67e2b1a17955c679 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sat, 26 Aug 2023 11:34:03 +0200 Subject: feat: Move to destination --- geometry.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'geometry.go') diff --git a/geometry.go b/geometry.go index 89eb1ed..0d90c6f 100644 --- a/geometry.go +++ b/geometry.go @@ -1,6 +1,21 @@ package main -import "image" +import ( + "image" + "math" +) -type Rectangle = image.Rectangle 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{0, 0}) +} + +func Normalize(p Point) Point { + return p.Div(int(Length(p))) +} -- cgit v1.3