isRing static method

bool isRing(
  1. CoordinateSequence seq
)

Tests whether a {@link CoordinateSequence} forms a valid {@link LinearRing}, by checking the sequence length and closure (whether the first and last points are identical in 2D). Self-intersection is not checked.

@param seq the sequence to test @return true if the sequence is a ring @see LinearRing

Implementation

static bool isRing(CoordinateSequence seq) {
  int n = seq.size();
  if (n == 0) return true;
  // too few points
  if (n <= 3) return false;
  // test if closed
  return seq.getOrdinate(0, CoordinateSequence.X) ==
          seq.getOrdinate(n - 1, CoordinateSequence.X) &&
      seq.getOrdinate(0, CoordinateSequence.Y) ==
          seq.getOrdinate(n - 1, CoordinateSequence.Y);
}