Tin

Examples · learn/05-structs · 112 of 339

task-2.solution

examples/learn/05-structs/task-2.solution.tintin run examples/learn/05-structs/task-2.solution.tin
type 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))
}