|
|
|
@ -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]
|
|
|
|
|