precisionScaleFactor static method

double precisionScaleFactor(
  1. Geometry g,
  2. double distance,
  3. int maxPrecisionDigits
)

Compute a scale factor to limit the precision of a given combination of Geometry and buffer distance. The scale factor is determined by the number of digits of precision in the (geometry + buffer distance), limited by the supplied maxPrecisionDigits value.

The scale factor is based on the absolute magnitude of the (geometry + buffer distance). since this determines the number of digits of precision which must be handled.

@param g the Geometry being buffered @param distance the buffer distance @param maxPrecisionDigits the max # of digits that should be allowed by the precision determined by the computed scale factor

@return a scale factor for the buffer computation

Implementation

static double precisionScaleFactor(
    Geometry g, double distance, int maxPrecisionDigits) {
  Envelope env = g.getEnvelopeInternal();
  double envMax = MathUtils.max4(env.getMaxX().abs(), env.getMaxY().abs(),
      env.getMinX().abs(), env.getMinY().abs());

  double expandByDistance = distance > 0.0 ? distance : 0.0;
  double bufEnvMax = envMax + 2 * expandByDistance;

  // the smallest power of 10 greater than the buffer envelope
  int bufEnvPrecisionDigits =
      (math.log(bufEnvMax) / math.log(10) + 1.0).toInt();
  int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;

  double scaleFactor = math.pow(10.0, minUnitLog10).toDouble();
  return scaleFactor;
}