diff options
Diffstat (limited to 'geometry.go')
| -rw-r--r-- | geometry.go | 19 |
1 files changed, 17 insertions, 2 deletions
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))) +} |
