shad-go/lectures/02-interfaces/geometry/point.go

16 lines
299 B
Go
Raw Normal View History

2020-02-27 14:43:12 +00:00
package geometry
import "math"
type Point struct{ X, Y float64 }
// traditional function
func Distance(p, q Point) float64 {
return math.Hypot(q.X-p.X, q.Y-p.Y)
}
// same thing, but as a method of the Point type
func (p Point) Distance(q Point) float64 {
return math.Hypot(q.X-p.X, q.Y-p.Y)
}