From d35d1d082ce6205ca3178f24406d4c1472b75217 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Thu, 28 Jun 2018 16:20:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=20?= =?UTF-8?q?=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B1=D0=BE=D1=80=D0=B0=20=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D0=B6=D0=B0=D0=B9=D1=88=D0=B5=D0=B3=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20fb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/tools.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pym/calculate/lib/utils/tools.py b/pym/calculate/lib/utils/tools.py index 8028fac..373dee2 100644 --- a/pym/calculate/lib/utils/tools.py +++ b/pym/calculate/lib/utils/tools.py @@ -607,16 +607,22 @@ class Brokenable(object): def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False): """ Получить наилучшее ближайшее к preferred_res разрешенение из support_res. + + Разрешение берётся ближайшее по размеру диагонали, с применением "штрафного" + коэфициента по разнице аспектов """ width, height = map(int, preferred_res.split('x')) gep = sqrt(height ** 2 + width ** 2) k = float(width) / float(height) + s = float(width) * float(height) support_res_int = (tuple(map(int, x.split("x"))) for x in support_res) + support_res_int = ((x, y, sqrt(y*y + x*x), abs(x/float(y)-k)) + for x, y in support_res_int) if not aspect_only: - support_res_int = [(x,y) for x,y in support_res_int if x <= width and y <= height] + support_res_int = [(x,y,g,dasp) + for x,y,g,dasp in support_res_int if x <= width and y <= height] if not support_res_int: return None - bestRes = min(support_res_int, - key=lambda x: (abs(x[0] / float(x[1]) - k), - abs(gep - sqrt(x[0] ** 2 + x[1] ** 2)))) - return "%sx%s" % bestRes + keyfunc = lambda x,y,g, dasp: g -g * dasp + bestRes = max(support_res_int, key=lambda x:keyfunc(*x) ) + return "%sx%s" % bestRes[0:2]