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.
327418
public Coordinate snap(Coordinate coordinate, double distance) {
		// Some initialization:
		calculatedDistance = distance;
		hasSnapped = false;
		Coordinate snappingPoint = coordinate;

		if (sortedX != null && sortedY != null) {
			// Calculate the distances for all candidates:
			List<Coordinate> coordinates = getPossibleCoordinates(coordinate, distance);
			for (Coordinate candidate : coordinates) {
				double d = MathService.distance(coordinate, candidate);
				if (d < calculatedDistance) {
					snappingPoint = candidate;
					calculatedDistance = d;
					hasSnapped = true;
				}
			}
		}

		return snappingPoint;
	}
1102428
public double getDistance(Coordinate coordinate) {
		double distance = Double.MAX_VALUE;
		if (!isEmpty()) {
			for (Polygon polygon : polygons) {
				double d = polygon.getDistance(coordinate);
				if (d < distance) {
					distance = d;
				}
			}
		}
		return distance;
	}
1293313
public static Point createPoint(double x, double y) throws SQLException {
        return createPoint(x, y, Coordinate.NULL_ORDINATE);
    }
1019913
@ExportConstructor
	public static org.geomajas.geometry.Coordinate constructor(double x, double y) {
		return new org.geomajas.geometry.Coordinate(x, y);
	}
1351139
public Geometry execute(Geometry geometry) {
		if (geometry == null) {
			return null;
		}
		if (geometry instanceof LinearRing) {
			if (coordIndex <= 0) {
				coordIndex = 0;
			} else if (coordIndex > geometry.getNumPoints() - 1) {
				coordIndex = geometry.getNumPoints() - 1;
			}
			Coordinate[] coordinates = new Coordinate[geometry.getNumPoints() + 1];
			int count = 0;
			for (int i = 0; i < coordinates.length; i++) {
				if (i == coordIndex) {
					coordinates[i] = coordinate;
				} else if (i == coordinates.length - 1) {
					coordinates[i] = coordinates[0];
				} else {
					coordinates[i] = geometry.getCoordinates()[count++];
				}
			}
			return geometry.getGeometryFactory().createLinearRing(coordinates);
		} else if (geometry instanceof LineString) {
			if (coordIndex <= 0) {
				coordIndex = 0;
			} else if (coordIndex > geometry.getNumPoints()) {
				coordIndex = geometry.getNumPoints();
			}
			Coordinate[] coordinates = new Coordinate[geometry.getNumPoints() + 1];
			int count = 0;
			for (int i = 0; i < coordinates.length; i++) {
				if (i == coordIndex) {
					coordinates[i] = coordinate;
				} else {
					coordinates[i] = geometry.getCoordinates()[count++];
				}
			}
			return geometry.getGeometryFactory().createLineString(coordinates);
		}
		return null;
	}
88653
public void copy(final Receiver out, final int copyOption, final int locationId) throws XPathException {
        Navigator.copy(this, out, copyOption, locationId);
    }
972037
public void addCoordinate(Coordinate coordinate) {
		Coordinate[] newCoords = new Coordinate[coordinates.length + 1];
		System.arraycopy(coordinates, 0, newCoords, 0, coordinates.length);
		newCoords[coordinates.length] = coordinate;
		setCoordinates(newCoords);
	}
267763
public void setLocation(String latitude, String longitude) {
        this.latitude = new BigDecimal(latitude);
        this.longitude = new BigDecimal(longitude);
    }
444471
public Expression withSourceLocation(SourceLocation location) {
    checkNotNull(location);
    if (location.equals(this.location)) {
      return this;
    }
    return new Expression(resultType, features, location) {
      @Override
      protected void doGen(CodeBuilder adapter) {
        Expression.this.gen(adapter);
      }
    };
  }
86323
public void setLocation(int x, int y)
    {
        screenX = UtilMath.clamp(x, minX, maxX);
        screenY = UtilMath.clamp(y, minY, maxY);
    }
325565
public double distance(Coordinate c) {
		double dx = x - c.x;
		double dy = y - c.y;

		return Math.sqrt(dx * dx + dy * dy);
	}
142732
public void setPosition(Coordinate position) {
		if (getOriginalLocation() != null) {
			Bbox oldBounds = (Bbox) getOriginalLocation();
			Bbox newBounds = (Bbox) oldBounds.clone();
			newBounds.setCenterPoint(position);
			setOriginalLocation(newBounds);
		} else {
			setOriginalLocation(new Bbox(position.getX(), position.getY(), 0, 0));
		}
	}
579364
public void update(Bbox mapBounds) {
		for (final SnappingRule condition : snappingRules) {
			condition.getSourceProvider().update(mapBounds);
			condition.getSourceProvider().getSnappingSources(new GeometryArrayFunction() {

				public void execute(Geometry[] geometries) {
					condition.getAlgorithm().setGeometries(geometries);
				}
			});
		}
	}
1177723
@Override
	@Pure
	public <OT extends MapPonctualElement> double distance(OT another_point) {
		double dist = super.distance(another_point);
		dist -= this.radius;
		return dist;
	}
495960
public void addPoint(double x, double y)
    {
        if (npoints >= xpoints.length)
        {
            final int newLength = npoints * 2;
            xpoints = Arrays.copyOf(xpoints, newLength);
            ypoints = Arrays.copyOf(ypoints, newLength);
        }
        xpoints[npoints] = x;
        ypoints[npoints] = y;
        npoints++;
        updateBounds();
    }
420042
public void setPosition(GeoLocationPoint position) {
		if ((this.position == null && position != null)
			|| (this.position != null && !this.position.equals(position))) {
			this.position = position;
			fireShapeChanged();
			checkPrimitiveValidity();
		}
	}
1120985
@Override
    public T move(String source, String target) throws IllegalArgumentException, IllegalArchivePathException {
        this.getArchive().move(source, target);
        return covarientReturn();
    }