Example #1
0
  private static List<IVector2> removeLastIfRepeated(final List<IVector2> points) {
    if (points.size() < 2) {
      return points;
    }

    final IVector2 first = points.get(0);
    final int lastIndex = points.size() - 1;
    final IVector2 last = points.get(lastIndex);
    if (first.closeTo(last)) {
      return points.subList(0, lastIndex - 1);
    }

    return points;
  }
Example #2
0
  private static List<IVector2> removeConsecutiveEqualsPoints(final List<IVector2> points) {
    final int pointsCount = points.size();
    final ArrayList<IVector2> result = new ArrayList<IVector2>(pointsCount);

    for (int i = 0; i < pointsCount; i++) {
      final IVector2 current = points.get(i);
      final IVector2 next = points.get((i + 1) % pointsCount);
      if (!current.closeTo(next)) {
        result.add(current);
      }
    }

    result.trimToSize();
    return result;
  }