16 lines
299 B
Go
16 lines
299 B
Go
|
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)
|
||
|
}
|