X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fratio.cc;h=fc36415c50638e161e73c8bd1df1ed19d3e01e99;hb=39029279954b1f346d3ba28ec12c58211bfa7436;hp=fbd7022322c5b0e9e02d8e94785baaa54e23c4c5;hpb=4616b19fb5241a54c9d57f7a91bb975f41aed14b;p=dcpomatic.git diff --git a/src/lib/ratio.cc b/src/lib/ratio.cc index fbd702232..fc36415c5 100644 --- a/src/lib/ratio.cc +++ b/src/lib/ratio.cc @@ -24,7 +24,6 @@ #include "i18n.h" using std::string; -using std::stringstream; using std::vector; vector Ratio::_ratios; @@ -57,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::iterator j = _ratios.begin (); + while (j != _ratios.end() && fabs ((*j)->ratio() - r) > 0.01) { + ++j; + } + + if (j == _ratios.end ()) { + return 0; + } + + return *j; +} +