point.go 378 B

12345678910111213141516171819202122232425
  1. package gg
  2. import (
  3. "math"
  4. "golang.org/x/image/math/fixed"
  5. )
  6. type Point struct {
  7. X, Y float64
  8. }
  9. func (a Point) Fixed() fixed.Point26_6 {
  10. return fixp(a.X, a.Y)
  11. }
  12. func (a Point) Distance(b Point) float64 {
  13. return math.Hypot(a.X-b.X, a.Y-b.Y)
  14. }
  15. func (a Point) Interpolate(b Point, t float64) Point {
  16. x := a.X + (b.X-a.X)*t
  17. y := a.Y + (b.Y-a.Y)*t
  18. return Point{x, y}
  19. }