refract method

V2 refract(
  1. V2 n,
  2. double r
)

Implementation

V2 refract(V2 n, double r) {
  final dot = dotProduct(n);
  double d = 1.0 - r*r*(1.0 - dot*dot);

  if (d >= 0.0) {
    d = math.sqrt(d);
    return _v2(
      r*x - (r*dot + d)*n.x,
      r*y - (r*dot + d)*n.y,
    );
  }

  return _this;
}