Examples · learn/05-structs · 112 of 339
task-2.solution
tin run examples/learn/05-structs/task-2.solution.tintype Point = { x: float, y: float }
fn Point.distanceTo(a: Point, b: Point): float {
let dx = b.x - a.x
let dy = b.y - a.y
sqrt(dx * dx + dy * dy)
}
fn main() {
let home = Point { x: 1.0, y: 1.0 }
let shop = Point { x: 4.0, y: 5.0 }
print(home.distanceTo(shop))
}