code: public Coordinate snap(Coordinate coordinate, double distance) {
  		// Some initialization:
  		calculatedDistance = distance;
  		hasSnapped = false;
  		Coordinate snappingPoint = coordinate;
  
  		// Calculate the distances for all coordinate arrays:
  		for (Coordinate[] coordinateArray : coordinates) {
  			if (coordinateArray.length > 1) {
  				for (int j = 1; j < coordinateArray.length; j++) {
  					double d = MathService.distance(coordinateArray[j], coordinateArray[j - 1], coordinate);
  					if (d < calculatedDistance || (d == calculatedDistance && !hasSnapped)) {
  						snappingPoint = MathService.nearest(coordinateArray[j], coordinateArray[j - 1], coordinate);
  						calculatedDistance = d;
  						hasSnapped = true;
  					}
  				}
  			} else if (coordinateArray.length == 1) {
  				// In the case of Points, see if we can snap to them:
  				double d = MathService.distance(coordinateArray[0], coordinate);
  				if (d < calculatedDistance) {
  					snappingPoint = coordinateArray[0];
  					calculatedDistance = d;
  					hasSnapped = true;
  				}
  			}
  		}
  
  		return snappingPoint;
  	}
docs: Execute the snap operation.
  
  @param coordinate The original location.
  @param distance   The maximum distance allowed for snapping.
  @return The new location. If no snapping target was found, this may return the original location.