codec_support/vq: do not move empty group centroid
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 15 Jun 2020 16:45:11 +0000 (18:45 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 15 Jun 2020 16:45:11 +0000 (18:45 +0200)
nihav-codec-support/src/vq/generic_elbg.rs

index b2c838dc24236cfc15b30e13e4888ffd5b535ef9..3c3e3c075f480043b3834e88e24ba6eb7bbc89fc 100644 (file)
@@ -51,7 +51,9 @@ impl<T: VQElement, TS: VQElementSum<T>> Cluster<T, TS> {
         self.dist += u64::from(self.centroid.dist(entry.val)) * entry.count;
     }
     fn calc_centroid(&mut self) {
-        self.centroid = self.sum.get_centroid();
+        if self.count > 0 {
+            self.centroid = self.sum.get_centroid();
+        }
     }
     fn calc_dist(&mut self) {
         if self.count != 0 {