aboutsummaryrefslogtreecommitdiff
path: root/geometry.go
blob: 0d90c6fda24a97e1f140d9f5edb6aff4dcb8307f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

package main

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{0, 0})
}

func Normalize(p Point) Point {
	return p.Div(int(Length(p)))
}