diff data/model/SparseModel.h @ 1113:ed207f89aaef

Fix assignment of values to regions on import, in case where region model contains duplicate points
author Chris Cannam
date Fri, 03 Jul 2015 16:09:14 +0100
parents 882d448c8a6d
children 39019ce29178
line wrap: on
line diff
--- a/data/model/SparseModel.h	Wed Jul 01 15:53:54 2015 +0100
+++ b/data/model/SparseModel.h	Fri Jul 03 16:09:14 2015 +0100
@@ -133,6 +133,12 @@
      */
     virtual void deletePoint(const PointType &point);
 
+    /**
+     * Return true if the given point is found in this model, false
+     * otherwise.
+     */
+    virtual bool containsPoint(const PointType &point);
+    
     virtual bool isReady(int *completion = 0) const {
         bool ready = isOK() && (m_completion == 100);
         if (completion) *completion = m_completion;
@@ -774,6 +780,27 @@
 }
 
 template <typename PointType>
+bool
+SparseModel<PointType>::containsPoint(const PointType &point)
+{
+    {
+	QMutexLocker locker(&m_mutex);
+
+	PointListIterator i = m_points.lower_bound(point);
+	typename PointType::Comparator comparator;
+	while (i != m_points.end()) {
+	    if (i->frame > point.frame) break;
+	    if (!comparator(*i, point) && !comparator(point, *i)) {
+                return true;
+	    }
+	    ++i;
+	}
+    }
+
+    return false;
+}
+
+template <typename PointType>
 void
 SparseModel<PointType>::deletePoint(const PointType &point)
 {