isOnLine static method

bool isOnLine(
  1. Coordinate p,
  2. CoordinateSequence line
)

Tests whether a point lies on the line defined by a {@link CoordinateSequence}.

@param p the point to test @param line the line coordinates @return true if the point is a vertex of the line or lies in the interior of a line segment in the line

Implementation

static bool isOnLine(Coordinate p, CoordinateSequence line) {
  LineIntersector lineIntersector = new RobustLineIntersector();
  Coordinate p0 = new Coordinate.empty2D();
  Coordinate p1 = new Coordinate.empty2D();
  int n = line.size();
  for (int i = 1; i < n; i++) {
    line.getCoordinateInto(i - 1, p0);
    line.getCoordinateInto(i, p1);
    lineIntersector.computeIntersectionPointLine(p, p0, p1);
    if (lineIntersector.hasIntersection()) {
      return true;
    }
  }
  return false;
}