// first determine if this or the given geom is a multiprimitive, if so, break it
// down and loop through each of its geoms and determine the mindistance from
// those.
if (geometry instanceof MultiPrimitive) {
double minDistance = Double.POSITIVE_INFINITY;
MultiPrimitive gc1 = (MultiPrimitive) geometry;
Iterator<? extends Geometry> iter = gc1.getElements().iterator();
while (iter.hasNext()) {
GeometryImpl prim = (GeometryImpl) iter.next();
double d = prim.distance(this);
if (d < minDistance) {
minDistance = d;
// can't get smaller than 0, so exit now if that is the case
if (minDistance == 0) return 0;
}
}
return minDistance;
}
else if (this instanceof MultiPrimitive) {
double minDistance = Double.POSITIVE_INFINITY;
MultiPrimitive gc1 = (MultiPrimitive) this;
Iterator<? extends Geometry> iter = gc1.getElements().iterator();
while (iter.hasNext()) {
GeometryImpl prim = (GeometryImpl) iter.next();
double d = prim.distance(geometry);
if (d < minDistance) {
minDistance = d;