gg/point.go

26 lines
378 B
Go
Raw Permalink Normal View History

package gg
2016-02-23 03:00:39 +01:00
import (
"math"
"golang.org/x/image/math/fixed"
)
type Point struct {
X, Y float64
}
2016-02-23 03:00:39 +01:00
func (a Point) Fixed() fixed.Point26_6 {
2016-02-23 04:33:22 +01:00
return fixp(a.X, a.Y)
2016-02-23 03:00:39 +01:00
}
func (a Point) Distance(b Point) float64 {
return math.Hypot(a.X-b.X, a.Y-b.Y)
}
func (a Point) Interpolate(b Point, t float64) Point {
x := a.X + (b.X-a.X)*t
y := a.Y + (b.Y-a.Y)*t
return Point{x, y}
}