Returns the 2D point on geometry A that is closest to geometry B.

@param geomA Geometry A
@param geomB Geometry B
@return The 2D point on geometry A that is closest to geometry B
969402
public static Point closestPoint(Geometry geomA, Geometry geomB) {
        if (geomA == null || geomB == null) {
            return null;
        }
        // Return the closest point on geomA. (We would have used index
        // 1 to return the closest point on geomB.)
        return geomA.getFactory().createPoint(DistanceOp.nearestPoints(geomA, geomB)[0]);
    }
75043
def subpoint(query_point, a=A, b=B):
    """"""
    x, y, z = query_point

    lat = geodetic_lat(query_point)
    lon = np.arctan2(y, x)
    e2_ = (a * a - b * b) / (a * a)
    n__ = a / np.sqrt(1 - e2_ * np.sin(lat)**2)
    nx_ = n__ * np.cos(lat) * np.cos(lon)
    ny_ = n__ * np.cos(lat) * np.sin(lon)
    nz_ = (1 - e2_) * n__ * np.sin(lat)

    return np.stack([nx_, ny_, nz_], axis=0)
644905
public static double euclidean(TupleDesc_F64 a, TupleDesc_F64 b) {
		final int N = a.value.length;
		double total = 0;
		for( int i = 0; i < N; i++ ) {
			double d = a.value[i]-b.value[i];
			total += d*d;
		}

		return Math.sqrt(total);
	}
1339440
@Override
	public double execute(Geometry geom1, Geometry geom2,
			ProgressTracker progressTracker) {
		if (null == geom1 || null == geom2) {
			throw new IllegalArgumentException();
		}

		Geometry geometryA = geom1;
		Geometry geometryB = geom2;

		if (geometryA.isEmpty() || geometryB.isEmpty())
			return NumberUtils.TheNaN;		

		Polygon polygonA;
		Polygon polygonB;
		MultiPoint multiPointA;
		MultiPoint multiPointB;

		// if geometryA is an envelope use a polygon instead (if geom1 was
		// folded, then geometryA will already be a polygon)
		// if geometryA is a point use a multipoint instead
		Geometry.Type gtA = geometryA.getType();
		Geometry.Type gtB = geometryB.getType();
		if (gtA == Geometry.Type.Point) {
			if (gtB == Geometry.Type.Point) {
				return Point2D.distance(((Point)geometryA).getXY(), ((Point)geometryB).getXY());
			}
			else if (gtB == Geometry.Type.Envelope) {
				Envelope2D envB = new Envelope2D();
				geometryB.queryEnvelope2D(envB);
				return envB.distance(((Point)geometryA).getXY());
			}
			
			multiPointA = new MultiPoint();
			multiPointA.add((Point) geometryA);
			geometryA = multiPointA;
		} else if (gtA == Geometry.Type.Envelope) {
			if (gtB == Geometry.Type.Envelope) {
				Envelope2D envA = new Envelope2D();
				geometryA.queryEnvelope2D(envA);
				Envelope2D envB = new Envelope2D();
				geometryB.queryEnvelope2D(envB);
				return envB.distance(envA);
			}
			polygonA = new Polygon();
			polygonA.addEnvelope((Envelope) geometryA, false);
			geometryA = polygonA;
		}

		// if geom_2 is an envelope use a polygon instead
		// if geom_2 is a point use a multipoint instead
		if (gtB == Geometry.Type.Point) {
			multiPointB = new MultiPoint();
			multiPointB.add((Point) geometryB);
			geometryB = multiPointB;
		} else if (gtB == Geometry.Type.Envelope) {
			polygonB = new Polygon();
			polygonB.addEnvelope((Envelope) geometryB, false);
			geometryB = polygonB;
		}

		DistanceCalculator distanceCalculator = new DistanceCalculator(
				progressTracker);
		double distance = distanceCalculator.calculate(geometryA, geometryB);
		return distance;
	}
365646
function( pointA, pointB ) {

	        return { x: pointB.x - pointA.x, y: -( pointB.y - pointA.y ) };
	    }
1122474
public static Boolean covers(Geometry geomA, Geometry geomB) {
        if(geomA == null||geomB == null){
            return null;
        }
        return geomA.covers(geomB);
    }
419594
int QueryCoordinates(Point3D[] dst, int dstSize, int beginIndex,
			int endIndex) {
		int endIndexC = endIndex < 0 ? m_pointCount : endIndex;
		endIndexC = Math.min(endIndexC, beginIndex + dstSize);

		if (beginIndex < 0 || beginIndex >= m_pointCount
				|| endIndexC < beginIndex)
			// TODO replace geometry exc
			throw new IllegalArgumentException();

		AttributeStreamOfDbl xy = (AttributeStreamOfDbl) getAttributeStreamRef(VertexDescription.Semantics.POSITION);
		AttributeStreamOfDbl z = null;
		double v = VertexDescription
				.getDefaultValue(VertexDescription.Semantics.Z);
		boolean bHasZ = hasAttribute(VertexDescription.Semantics.Z);
		if (bHasZ)
			z = (AttributeStreamOfDbl) getAttributeStreamRef(VertexDescription.Semantics.Z);
		int j = 0;
		for (int i = beginIndex; i < endIndexC; i++, j++) {
			dst[j].x = xy.read(2 * i);
			dst[j].y = xy.read(2 * i + 1);
			dst[j].z = bHasZ ? z.read(i) : v;

			dst[j] = getXYZ(i);
		}

		return endIndexC;
	}
1025023
private boolean generatedPositionAfter(Mapping mappingA, Mapping mappingB) {
        // Optimized for most common case
        int lineA = mappingA.generated.line;
        int lineB = mappingB.generated.line;
        int columnA = mappingA.generated.column;
        int columnB = mappingB.generated.column;
        return lineB > lineA || lineB == lineA && columnB >= columnA || Util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
    }
1371629
public static Geometry snap(Geometry geometryA, Geometry geometryB, double distance) {
        if(geometryA == null||geometryB == null){
            return null;
        }
        Geometry[] snapped = GeometrySnapper.snap(geometryA, geometryB, distance);
        return snapped[0];
    }
339923
public boolean intersects(Geometry geometry) {
		if (geometry == null) {
			return false;
		}
		Coordinate[] arr1 = getCoordinates();
		Coordinate[] arr2 = geometry.getCoordinates();
		for (int i = 0; i < arr1.length - 1; i++) {
			for (int j = 0; j < arr2.length - 1; j++) {
				if (Mathlib.lineIntersects(arr1[i], arr1[i + 1], arr2[j], arr2[j + 1])) {
					return true;
				}
			}
		}
		return false;
	}
440388
public CloseableIterator<GeometryIndex> query(BoundingBox boundingBox,
			Projection projection) {

		BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox,
				projection);

		CloseableIterator<GeometryIndex> geometryIndices = query(featureBoundingBox);

		return geometryIndices;
	}
1165484
static Vector2d getNearestVector(final Vector2d reference, final List<Vector2d> vectors) {

        if (vectors.isEmpty()) throw new IllegalArgumentException("No vectors provided");

        // to find the closest vector we find use the dot product,
        // for the general case (non-unit vectors) one can use the
        // cosine similarity
        Vector2d closest = vectors.get(0);
        double maxProd = reference.dot(closest);

        for (int i = 1; i < vectors.size(); i++) {
            double newProd = reference.dot(vectors.get(i));
            if (newProd > maxProd) {
                maxProd = newProd;
                closest = vectors.get(i);
            }
        }

        return closest;
    }
268846
public Triangle setPoints(final Point2D a, final Point2D b, final Point2D c)
    {
        return setPoint2DArray(new Point2DArray(a, b, c));
    }
1244216
private static Point getLinesIntersection(Line2D a,
                                              Line2D b) {
        double d = (a.getX1() - a.getX2()) * (b.getY2() - b.getY1()) - (a.getY1() - a.getY2()) * (b.getX2() - b.getX1());
        double da = (a.getX1() - b.getX1()) * (b.getY2() - b.getY1()) - (a.getY1() - b.getY1()) * (b.getX2() - b.getX1());
        double ta = da / d;
        Point p = new Point();
        p.setLocation(a.getX1() + ta * (a.getX2() - a.getX1()),
                      a.getY1() + ta * (a.getY2() - a.getY1()));
        return p;
    }
1240865
public static Double getMinZ(Geometry geom) {
        if (geom != null) {
            return CoordinateUtils.zMinMax(geom.getCoordinates())[0];
        } else {
            return null;
        }
    }
1106222
public static double[] bbox(Geometry geometry) {
    if (geometry instanceof Point) {
      return bbox((Point) geometry);
    } else if (geometry instanceof MultiPoint) {
      return bbox((MultiPoint) geometry);
    } else if (geometry instanceof LineString) {
      return bbox((LineString) geometry);
    } else if (geometry instanceof MultiLineString) {
      return bbox((MultiLineString) geometry);
    } else if (geometry instanceof Polygon) {
      return bbox((Polygon) geometry);
    } else if (geometry instanceof MultiPolygon) {
      return bbox((MultiPolygon) geometry);
    } else if (geometry instanceof GeometryCollection) {
      List<Point> points = new ArrayList<>();
      for (Geometry geo : ((GeometryCollection) geometry).geometries()) {
        // recursive
        double[] bbox = bbox(geo);
        points.add(Point.fromLngLat(bbox[0], bbox[1]));
        points.add(Point.fromLngLat(bbox[2], bbox[1]));
        points.add(Point.fromLngLat(bbox[2], bbox[3]));
        points.add(Point.fromLngLat(bbox[0], bbox[3]));
      }
      return TurfMeasurement.bbox(MultiPoint.fromLngLats(points));
    } else {
      throw new RuntimeException(("Unknown geometry class: " + geometry.getClass()));
    }
  }
1239471
def relate(geom)
      check_geometry(geom)
      FFIGeos.GEOSRelate_r(Geos.current_handle_pointer, ptr, geom.ptr)
    end