Example #1
0
/*private*/
bool
OffsetCurveSetBuilder::isErodedCompletely(CoordinateSequence *ringCoord,
	double bufferDistance)
{
	double minDiam=0.0;
	// degenerate ring has no area
	if (ringCoord->getSize() < 4)
		return bufferDistance < 0;
	// important test to eliminate inverted triangle bug
	// also optimizes erosion test for triangles
	if (ringCoord->getSize() == 4)
		return isTriangleErodedCompletely(ringCoord, bufferDistance);

	/**
	 * The following is a heuristic test to determine whether an
	 * inside buffer will be eroded completely->
	 * It is based on the fact that the minimum diameter of the ring
	 * pointset
	 * provides an upper bound on the buffer distance which would erode the
	 * ring->
	 * If the buffer distance is less than the minimum diameter, the ring
	 * may still be eroded, but this will be determined by
	 * a full topological computation->
	 *
	 */
	LinearRing *ring=inputGeom.getFactory()->createLinearRing(*ringCoord);
	MinimumDiameter md(ring); //=new MinimumDiameter(ring);
	minDiam=md.getLength();
	delete ring;

	//delete md;
	//System->out->println(md->getDiameter());
	return minDiam < (2 * fabs(bufferDistance));
}
/*private*/
bool
OffsetCurveSetBuilder::isErodedCompletely(const LinearRing *ring,
	double bufferDistance)
{
	const CoordinateSequence *ringCoord = ring->getCoordinatesRO();

	// degenerate ring has no area
	if (ringCoord->getSize() < 4)
		return bufferDistance < 0;

	// important test to eliminate inverted triangle bug
	// also optimizes erosion test for triangles
	if (ringCoord->getSize() == 4)
		return isTriangleErodedCompletely(ringCoord, bufferDistance);

  const Envelope* env = ring->getEnvelopeInternal();
  double envMinDimension = std::min(env->getHeight(), env->getWidth());
  if (bufferDistance < 0.0 && 2 * std::abs(bufferDistance) > envMinDimension)
      return true;

	/**
	 * The following is a heuristic test to determine whether an
	 * inside buffer will be eroded completely->
	 * It is based on the fact that the minimum diameter of the ring
	 * pointset
	 * provides an upper bound on the buffer distance which would erode the
	 * ring->
	 * If the buffer distance is less than the minimum diameter, the ring
	 * may still be eroded, but this will be determined by
	 * a full topological computation->
	 *
	 */

/* MD  7 Feb 2005 - there's an unknown bug in the MD code,
 so disable this for now */
#if 0
	MinimumDiameter md(ring); //=new MinimumDiameter(ring);
	double minDiam = md.getLength();
	return minDiam < (2 * std::fabs(bufferDistance));
#endif

  return false;
}