冷冷的冰雨在臉上胡亂的拍,冷冷冰雨臉上
package test;public class TestSizeMatch { public static void main(String[] args) { int []a ={1280,720}; int []b ={800,1200}; System.out.println(TestSizeMatch.calAdSizeSimilarRatio(a,b)); } public static double calAdSizeSimilarRatio(int[] reqAdsize, int[] adSize) { if (null == reqAdsize || null == adSize) return 0; double rateRate, lenRate; // 比例差別,長度差別 double dLenVal = reqAdsize[0]*reqAdsize[0] + reqAdsize[1]*reqAdsize[1]; double dRateVal = ((double) reqAdsize[1]) / reqAdsize[0]; final int RATE_WEIGHT = 3; //2為比率放大倍數,為經驗值 final int LEN_WEIGHT = 1; double dVal = adSize[0]*adSize[0] + adSize[1]*adSize[1]; lenRate = Math.sqrt(dVal / dLenVal); if (lenRate > 1) lenRate = 1 / lenRate; rateRate =(((double) adSize[1]) / adSize[0]) / dRateVal; //2個尺寸的寬高比 if (rateRate > 1) rateRate = 1 / rateRate; return ((RATE_WEIGHT * rateRate + LEN_WEIGHT * lenRate)/(RATE_WEIGHT + LEN_WEIGHT)); }}