package main
import (
"fmt"
)
type Point struct {
x, y float64
}
type Rectangle struct {
topLeft, bottomRight Point
}
func getCenter(rect Rectangle) Point {
centerX := (rect.topLeft.x + rect.bottomRight.x) / 2.0
centerY := (rect.topLeft.y + rect.bottomRight.y) / 2.0
return Point{centerX, centerY}
}
func main() {
rect := Rectangle{
topLeft: Point{10.0, 20.0},
bottomRight: Point{110.0, 70.0},
}
center := getCenter(rect)
fmt.Printf("Center of the rectangle: (%.2f, %.2f)\n", center.x, center.y)
}
/*
run:
Center of the rectangle: (60.00, 45.00)
*/