code: public static float pointLineDistSq (float px, float py,
                                           float x1, float y1, float x2, float y2) {
          x2 -= x1;
          y2 -= y1;
          px -= x1;
          py -= y1;
          float s = px * y2 - py * x2;
          return (s * s) / (x2 * x2 + y2 * y2);
      }
docs: Returns the square of the distance from the specified point to the specified line.