vectorFromPosition method

Vector vectorFromPosition(
  1. Vector position
)

Returns vector with the shortest distance from position to this edge

Implementation

Vector vectorFromPosition(Vector position) {
  double scale = shadowScale(position);

  if (scale <= 0) {
    return source.point.toVector() - position;
  } else if (scale >= 1) {
    return target.point.toVector() - position;
  } else {
    Vector shadow = source.point.toVector() + toVector() * scale;
    return shadow - position;
  }
}