Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- "math"
- )
- type Point struct {
- x float64
- y float64
- }
- func NewPoint(x float64, y float64) *Point {
- p := new(Point)
- p.SetX(x)
- p.SetY(y)
- return p
- }
- func (p *Point) X() float64 {
- return p.x
- }
- func (p *Point) Y() float64 {
- return p.y
- }
- func (p *Point) SetX(x float64) {
- p.x = x
- }
- func (p *Point) SetY(y float64) {
- p.y = y
- }
- func Dist(p1 *Point, p2 *Point) float64 {
- xSqr := math.Pow(p1.X()-p2.X(), 2)
- ySqr := math.Pow(p1.Y()-p2.Y(), 2)
- return math.Sqrt(xSqr + ySqr)
- }
- func main() {
- p1 := NewPoint(0, 0)
- p2 := NewPoint(3.0, 4.0)
- if !(Dist(p1, p2) == 5.0) {
- log.Fatal("Wrong value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement