class Centroid {
  mean;
  weight;
  constructor(mean, weight) {
    this.mean = mean;
    this.weight = weight;
  }
  add(r) {
    if (r.weight < 0) {
      throw new Error("centroid weight cannot be less than zero");
    }
    if (this.weight !== 0) {
      this.weight += r.weight;
      this.mean += r.weight * (r.mean - this.mean) / this.weight;
    } else {
      this.weight = r.weight;
      this.mean = r.mean;
    }
  }
}
function sortCentroidList(centroids) {
  centroids.sort((a, b) => a.mean - b.mean);
}
export {
  Centroid,
  sortCentroidList
};
//# sourceMappingURL=centroid.js.map
