Merge master.
[dcpomatic.git] / src / lib / ratio.cc
index bb69636584167d12b19d358e99d5a25193394d76..fc36415c50638e161e73c8bd1df1ed19d3e01e99 100644 (file)
@@ -56,3 +56,20 @@ Ratio::from_id (string i)
 
        return *j;
 }
+
+/** @return Ratio corresponding to a given fractional ratio (+/- 0.01), or 0 */
+Ratio const *
+Ratio::from_ratio (float r)
+{
+       vector<Ratio const *>::iterator j = _ratios.begin ();
+       while (j != _ratios.end() && fabs ((*j)->ratio() - r) > 0.01) {
+               ++j;
+       }
+
+       if (j == _ratios.end ()) {
+               return 0;
+       }
+
+       return *j;
+}
+