Dist

Gets the distance between points.

(module
  (func (export "dist") (param $x1 f32) (param $y1 f32) (param $x2 f32) (param $y2 f32) (result f32)
    (local $x0 f32)
    (local $y0 f32)

    (f32.sub (get_local $x1) (get_local $x2))
    set_local $x0
    (f32.sub (get_local $y1) (get_local $y2))
    set_local $y0

    (f32.add
      (f32.mul (get_local $x0) (get_local $x0))
      (f32.mul (get_local $y0) (get_local $y0))
    )

    f32.sqrt
  )
)

Last updated