private void adjustDateLineCrossingPoints() {
      ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne));
      if (!LatLon.locationsCrossDateLine(corners)) return;

      double lonSign = 0;
      for (LatLon corner : corners) {
        if (Math.abs(corner.getLongitude().degrees) != 180)
          lonSign = Math.signum(corner.getLongitude().degrees);
      }

      if (lonSign == 0) return;

      if (Math.abs(sw.getLongitude().degrees) == 180
          && Math.signum(sw.getLongitude().degrees) != lonSign)
        sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation());
      if (Math.abs(se.getLongitude().degrees) == 180
          && Math.signum(se.getLongitude().degrees) != lonSign)
        se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation());
      if (Math.abs(nw.getLongitude().degrees) == 180
          && Math.signum(nw.getLongitude().degrees) != lonSign)
        nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation());
      if (Math.abs(ne.getLongitude().degrees) == 180
          && Math.signum(ne.getLongitude().degrees) != lonSign)
        ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation());
    }
  @SuppressWarnings({"UnnecessaryLocalVariable"})
  public double[] getBilinearCoords(double alpha, double beta) {
    // TODO: this method isn't always finding the correct -- or any -- roots
    double eps = 1e-9;
    double u, v;

    double alpha11 = this.w11[1];
    double beta11 = this.w11[2];

    if (Math.abs(alpha11 - 1) < eps) // if alpha11 == 1
    {
      u = alpha;
      if (Math.abs(beta11 - 1) < eps) // if beta == 1
      v = beta;
      else v = beta / (u * (beta11 - 1) + 1);
    } else if (Math.abs(beta11 - 1) < eps) // if beta = 1
    {
      v = beta;
      u = alpha / (v * (alpha11 - 1) + 1);
    } else {
      double a = 1d - beta11;
      double b = alpha * (beta11 - 1) - beta * (alpha11 - 1) - 1;
      double c = alpha;
      double b24ac = b * b - 4 * a * c;

      if (a == 0 || b24ac < 0) return new double[] {-1, -1}; // TODO: Warn.

      double q = -0.5 * (b + (b != 0 ? Math.signum(b) : 1) * Math.sqrt(b24ac));
      u = q / a;
      double ualt = c / q;
      u = Math.abs(u) <= Math.abs(ualt) ? u : ualt;
      if (u < 0 || u > 1) u = c / q;

      v = u * (beta11 - 1) + 1;
      v = Math.abs(v) >= eps ? beta / v : -1;
    }

    return new double[] {u, v};
  }