API Reference › Math › Math.dist2
method

Math.dist2

Math.dist2(x0, y0, x1, y1) -> fixed

Returns the squared distance between (x0, y0) and (x1, y1) — dx*dx + dy*dy, with no square root. Comparing squared distances gives the same ordering as comparing real distances, so this is the cheaper choice for "nearest" and "within radius" tests: compare against radius * radius instead of calling Math.dist.

Example

program Demo {
  handler Step phase Update {
    let r2 = radius * radius
    if Math.dist2(px, py, ex, ey) < r2 { in_range() }
  }
}
← All symbols