src/main/java/org/opensha/sha/faultSurface/QuadSurface.java
private static double distanceToSurface(Vector3D p, Path2D border) {
		PathIterator pit = border.getPathIterator(null);
		double[] c = new double[6]; // coordinate array
		double[] prev_pt = new double[2];
		double minDistSq = Double.MAX_VALUE;
		while (!pit.isDone()) {
			// this puts the current location in the first two elements of c
			int type = pit.currentSegment(c);
			switch (type) {
			case PathIterator.SEG_MOVETO:
				// do nothing, this is just resetting the current location. not a line
				break;
			case PathIterator.SEG_LINETO:
				// this defines a line, check the distance
				double distSq = Line2D.ptSegDistSq(prev_pt[0], prev_pt[1], c[0], c[1],
						p.getX(), p.getY());
				minDistSq = Math.min(minDistSq, distSq);
				break;

			default:
				throw new IllegalStateException("unkown path operation: "+type);
			}
			// this will set the previous location
			prev_pt[0] = c[0];
			prev_pt[1] = c[1];
			pit.next();
		}
		return Math.sqrt(p.getZ() * p.getZ() + minDistSq);
	}
/*
	 * Iterates over surface outline path calculating distance to line segments
	 * and returning the minimum.
	 */
Iterates over surface outline path calculating distance to line segments
and returning the minimum.
Iterates over surface outline path calculating distance to line segments and returning the minimum .
private static double distanceToSurface(Vector3D p, Path2D border) {
		PathIterator pit = border.getPathIterator(null);
		double[] c = new double[6]; 
		double[] prev_pt = new double[2];
		double minDistSq = Double.MAX_VALUE;
		while (!pit.isDone()) {
			int type = pit.currentSegment(c);
			switch (type) {
			case PathIterator.SEG_MOVETO:
				break;
			case PathIterator.SEG_LINETO:
				double distSq = Line2D.ptSegDistSq(prev_pt[0], prev_pt[1], c[0], c[1],
						p.getX(), p.getY());
				minDistSq = Math.min(minDistSq, distSq);
				break;
			default:
				throw new IllegalStateException("unkown path operation: "+type);
			}
			prev_pt[0] = c[0];
			prev_pt[1] = c[1];
			pit.next();
		}
		return Math.sqrt(p.getZ() * p.getZ() + minDistSq);
	}
private static double distanceToSurface ( Vector3D p , Path2D border ) { PathIterator pit = border . getPathIterator ( null ) ; double [ ] c = new double [ 6 ] ; double [ ] prev_pt = new double [ 2 ] ; double minDistSq = Double . MAX_VALUE ; while ( ! pit . isDone ( ) ) { int type = pit . currentSegment ( c ) ; switch ( type ) { case PathIterator . SEG_MOVETO : break ; case PathIterator . SEG_LINETO : double distSq = Line2D . ptSegDistSq ( prev_pt [ 0 ] , prev_pt [ 1 ] , c [ 0 ] , c [ 1 ] , p . getX ( ) , p . getY ( ) ) ; minDistSq = Math . min ( minDistSq , distSq ) ; break ; default : throw new IllegalStateException ( "unkown path operation: " + type ) ; } prev_pt [ 0 ] = c [ 0 ] ; prev_pt [ 1 ] = c [ 1 ] ; pit . next ( ) ; } return Math . sqrt ( p . getZ ( ) * p . getZ ( ) + minDistSq ) ; }
Iterates over surface outline path calculating distance to line segments
 and returning the minimum.
Iterates over surface outline path calculating distance to line segments and returning the minimum .
// coordinate array // this puts the current location in the first two elements of c // do nothing, this is just resetting the current location. not a line // this defines a line, check the distance // this will set the previous location