addLineSegments method

void addLineSegments(
  1. List<Coordinate> pts
)

Adds the line segments defined by an array of coordinates to the linear centroid accumulators.

@param pts an array of {@link Coordinate}s

Implementation

void addLineSegments(List<Coordinate> pts) {
  double lineLen = 0.0;
  for (int i = 0; i < pts.length - 1; i++) {
    double segmentLen = pts[i].distance(pts[i + 1]);
    if (segmentLen == 0.0) continue;

    lineLen += segmentLen;

    double midx = (pts[i].x + pts[i + 1].x) / 2;
    lineCentSum.x += segmentLen * midx;
    double midy = (pts[i].y + pts[i + 1].y) / 2;
    lineCentSum.y += segmentLen * midy;
  }
  totalLength += lineLen;
  if (lineLen == 0.0 && pts.length > 0) addPoint(pts[0]);
}