Get the sequence number of the path point that is closest to a
given coordinate.
@param coord The coordinate to which the closest sequence number should be found.
@return The sequence number of the path point that is closest to the given coordinate.
977937
public int getSequenceNumber(Coordinate coord) {
		int minIndex = 0;
		double minDist = Double.MAX_VALUE;
		for (int i = 0; i < this.getPositions().length; i++) {
			if (this.getPositions()[i].distance(coord) < minDist) {
				minDist = this.getPositions()[i].distance(coord);
				minIndex = i;
			}
		}
		return minIndex;
	}
292109
protected int getBinNr(double coord) {
    if (Double.isInfinite(coord) || Double.isNaN(coord)) {
      throw new UnsupportedOperationException("Encountered non-finite value in Histogram: " + coord);
    }
    if (coord == max) {
      // System.err.println("Triggered special case: "+ (Math.floor((coord -
      // base) / binsize) + offset) + " vs. " + (size - 1));
      return size - 1;
    }
    return (int) Math.floor((coord - base) / binsize) + offset;
  }
535958
@NonNull
  public static Feature nearestPointOnLine(@NonNull Point pt, @NonNull List<Point> coords) {

    if (coords.size() < 2) {
      throw new TurfException("Turf nearestPointOnLine requires a List of Points "
        + "made up of at least 2 coordinates.");
    }

    Feature closestPt = Feature.fromGeometry(
      Point.fromLngLat(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY));
    closestPt.addNumberProperty("dist", Double.POSITIVE_INFINITY);

    for (int i = 0; i < coords.size() - 1; i++) {
      Feature start = Feature.fromGeometry(coords.get(i));
      Feature stop = Feature.fromGeometry(coords.get(i + 1));
      //start
      start.addNumberProperty("dist", TurfMeasurement.distance(
        pt, (Point) start.geometry(), TurfConstants.UNIT_MILES));
      //stop
      stop.addNumberProperty("dist", TurfMeasurement.distance(
        pt, (Point) stop.geometry(), TurfConstants.UNIT_MILES));
      //perpendicular
      double heightDistance = Math.max(
        start.properties().get("dist").getAsDouble(),
        stop.properties().get("dist").getAsDouble()
      );
      double direction = TurfMeasurement.bearing((Point) start.geometry(),
        (Point) stop.geometry());
      Feature perpendicularPt1 = Feature.fromGeometry(
        TurfMeasurement.destination(pt, heightDistance, direction + 90,
          TurfConstants.UNIT_MILES));
      Feature perpendicularPt2 = Feature.fromGeometry(
        TurfMeasurement.destination(pt, heightDistance, direction - 90,
          TurfConstants.UNIT_MILES));
      LineIntersectsResult intersect = lineIntersects(
        ((Point) perpendicularPt1.geometry()).longitude(),
        ((Point) perpendicularPt1.geometry()).latitude(),
        ((Point) perpendicularPt2.geometry()).longitude(),
        ((Point) perpendicularPt2.geometry()).latitude(),
        ((Point) start.geometry()).longitude(),
        ((Point) start.geometry()).latitude(),
        ((Point) stop.geometry()).longitude(),
        ((Point) stop.geometry()).latitude()
      );

      Feature intersectPt = null;
      if (intersect != null) {
        intersectPt = Feature.fromGeometry(
          Point.fromLngLat(intersect.horizontalIntersection(), intersect.verticalIntersection()));
        intersectPt.addNumberProperty("dist", TurfMeasurement.distance(pt,
          (Point) intersectPt.geometry(), TurfConstants.UNIT_MILES));
      }

      if ((double) start.getNumberProperty("dist")
        < (double) closestPt.getNumberProperty("dist")) {
        closestPt = start;
        closestPt.addNumberProperty(INDEX_KEY, i);
      }
      if ((double) stop.getNumberProperty("dist")
        < (double) closestPt.getNumberProperty("dist")) {
        closestPt = stop;
        closestPt.addNumberProperty(INDEX_KEY, i);
      }
      if (intersectPt != null
        && (double) intersectPt.getNumberProperty("dist")
        < (double) closestPt.getNumberProperty("dist")) {
        closestPt = intersectPt;
        closestPt.addNumberProperty(INDEX_KEY, i);
      }
    }

    return closestPt;
  }
583746
public static List<LineString> getSectionsFromCoordinates( List<Coordinate> coordinates, double width ) {

        if (coordinates.size() < 3) {
            throw new IllegalArgumentException("This method works only on lines with at least 3 coordinates.");
        }
        double halfWidth = width / 2.0;
        List<LineString> linesList = new ArrayList<LineString>();
        // first section
        Coordinate centerCoordinate = coordinates.get(0);
        LineSegment l1 = new LineSegment(centerCoordinate, coordinates.get(1));
        Coordinate leftCoordinate = l1.pointAlongOffset(0.0, halfWidth);
        Coordinate rightCoordinate = l1.pointAlongOffset(0.0, -halfWidth);
        LineString lineString = geomFactory.createLineString(new Coordinate[]{leftCoordinate, centerCoordinate, rightCoordinate});
        linesList.add(lineString);

        for( int i = 1; i < coordinates.size() - 1; i++ ) {
            Coordinate previous = coordinates.get(i - 1);
            Coordinate current = coordinates.get(i);
            Coordinate after = coordinates.get(i + 1);

            double firstAngle = azimuth(current, previous);
            double secondAngle = azimuth(current, after);

            double a1 = min(firstAngle, secondAngle);
            double a2 = max(firstAngle, secondAngle);

            double centerAngle = a1 + (a2 - a1) / 2.0;

            AffineTransformation rotationInstance = AffineTransformation.rotationInstance(-toRadians(centerAngle), current.x,
                    current.y);

            LineString vertical = geomFactory.createLineString(new Coordinate[]{new Coordinate(current.x, current.y + halfWidth),
                    current, new Coordinate(current.x, current.y - halfWidth)});
            Geometry transformed = rotationInstance.transform(vertical);
            linesList.add((LineString) transformed);
        }

        // last section
        centerCoordinate = coordinates.get(coordinates.size() - 1);
        LineSegment l2 = new LineSegment(centerCoordinate, coordinates.get(coordinates.size() - 2));
        leftCoordinate = l2.pointAlongOffset(0.0, halfWidth);
        rightCoordinate = l2.pointAlongOffset(0.0, -halfWidth);
        lineString = geomFactory.createLineString(new Coordinate[]{leftCoordinate, centerCoordinate, rightCoordinate});
        linesList.add(lineString);

        return linesList;
    }
263984
public static void toGeojsonCoordinates(Coordinate[] coords, StringBuilder sb) {
        sb.append("[");
        for (int i = 0; i < coords.length; i++) {
            toGeojsonCoordinate(coords[i], sb);
            if (i < coords.length - 1) {
                sb.append(",");
            }
        }
        sb.append("]");
    }
681798
private static CoordinateArraySequence convertSequence(Coordinate[] cs,int dimension) {        
        for (int i = 0; i < cs.length; i++) { 
            Coordinate coord = cs[i];
            switch (dimension) {
                case 2:
                    coord.z = Double.NaN;
                    cs[i]=coord;
                    break;
                case 3: {
                    double z = coord.z;
                    if (Double.isNaN(z)) {
                        coord.z = 0;
                        cs[i]=coord;
                    }
                    break;
                }                
                default:
                    break;
            }
        }        
        return new CoordinateArraySequence(cs, dimension);        
    }
1339016
function (coord) {
        var extent = this._extent;
        var min = Math.min(extent[0], extent[1]);
        var max = Math.max(extent[0], extent[1]);
        return coord >= min && coord <= max;
    }
1118282
public static boolean contains3D(Coordinate[] coords, Coordinate coord) {
                for (Coordinate coordinate : coords) {
                        if (coordinate.equals3D(coord)) {
                                return true;
                        }
                }
                return false;
        }
679393
public Coordinate getCoordinateN(int n) {
		if (isEmpty()) {
			return null;
		}
		if (n >= 0 && n < coordinates.length) {
			return coordinates[n];
		}
		return null;
	}
102252
public Coordinate getCoordinate(Geometry geometry) {
		LineString lineString = getLineString(geometry);
		if (lineString != null && coordinateIndex >= 0) {
			return lineString.getCoordinateN(coordinateIndex);
		}
		return null;
	}
1069641
protected boolean sendLeaveReqToCoord(final Address coord) {
        if(coord == null) {
            log.warn("%s: cannot send LEAVE request to null coord", gms.getLocalAddress());
            return false;
        }
        Promise<Address> leave_promise=gms.getLeavePromise();
        gms.setLeaving(true);
        log.trace("%s: sending LEAVE request to %s", gms.local_addr, coord);
        long start=System.currentTimeMillis();
        sendLeaveMessage(coord, gms.local_addr);
        Address sender=leave_promise.getResult(gms.leave_timeout);
        if(!Objects.equals(coord, sender))
            return false;

        long time=System.currentTimeMillis()-start;
        if(sender != null)
            log.trace("%s: got LEAVE response from %s in %d ms", gms.local_addr, coord, time);
        else
            log.trace("%s: timed out waiting for LEAVE response from %s (after %d ms)", gms.local_addr, coord, time);
        return true;
    }
518838
private final int getNextPathNum()
	{
		final int next = this.nextPath;
		final int newNext = next + 1;
		this.nextPath = newNext >= this.paths.length ? 0 : newNext;
		return next;
	}
1092386
def coords(self):
        
        x, y = ("lat", "lng") if self.order == "lat" else ("lng", "lat")
        try:
            return (self["location"][x], self["location"][y])

        except KeyError:
            return None
217922
public static Coordinate[] removeDuplicatedCoordinates(Coordinate[] coords, boolean closeRing) {
        LinkedHashSet<Coordinate> finalCoords = new LinkedHashSet<Coordinate>();
        Coordinate prevCoord = coords[0];
        finalCoords.add(prevCoord);
        Coordinate firstCoord = prevCoord;
        int nbCoords = coords.length;
        for (int i = 1; i < nbCoords; i++) {
            Coordinate currentCoord = coords[i];
            if (currentCoord.equals2D(prevCoord)) {
                continue;
            }
            finalCoords.add(currentCoord);
            prevCoord = currentCoord;
        }
        if (closeRing) {
            Coordinate[] coordsFinal = finalCoords.toArray(new Coordinate[0]);
            Coordinate[] closedCoords = Arrays.copyOf(coordsFinal, coordsFinal.length + 1);
            closedCoords[closedCoords.length-1] = firstCoord;
            return closedCoords;
        }
        return finalCoords.toArray(new Coordinate[0]);

    }
1054062
public int getIsTouchingAmOrPm(float xCoord, float yCoord) {
        if (!mDrawValuesReady) {
            return -1;
        }

        int squaredYDistance = (int) ((yCoord - mAmPmYCenter)*(yCoord - mAmPmYCenter));

        int distanceToAmCenter =
                (int) Math.sqrt((xCoord - mAmXCenter)*(xCoord - mAmXCenter) + squaredYDistance);
        if (distanceToAmCenter <= mAmPmCircleRadius && !mAmDisabled) {
            return AM;
        }

        int distanceToPmCenter =
                (int) Math.sqrt((xCoord - mPmXCenter)*(xCoord - mPmXCenter) + squaredYDistance);
        if (distanceToPmCenter <= mAmPmCircleRadius && !mPmDisabled) {
            return PM;
        }

        // Neither was close enough.
        return -1;
    }
785783
public java.lang.String getCoords() {
        return (java.lang.String) getStateHelper().eval(PropertyKeys.coords);

    }
759911
static int findCornerSeed(List<Point2D_I32> contour ) {
		Point2D_I32 a = contour.get(0);

		int best = -1;
		double bestDistance = -Double.MAX_VALUE;

		for (int i = 1; i < contour.size(); i++) {
			Point2D_I32 b = contour.get(i);

			double d = distanceSq(a,b);
			if( d > bestDistance ) {
				bestDistance = d;
				best = i;
			}
		}

		return best;
	}