2015-09-06 72 views
2

我的屏幕绝对点列表像波纹管:如何比较绝对坐标

355.2599 : 408.4894 
353.31705 : 409.43512 
341.44516 : 418.35184 
329.3344 : 427.5607 
314.9433 : 435.21622 
304.6277 : 440.36212 
292.61746 : 444.36887 

,我有一些其他的点象下面这样:

160.66528 : 513.35834 
319.33472 : 230.71161 
304.3659 : 479.40076 

我怎么能知道第二点是在第一点? 例如,当不同的点数小于10 dp时,应该返回found;

private boolean checkValidate(List<Point> first, List<Point> second) 
{ 
    int accuracy = Helper.dpToPixel(this, 10); 
    int pointSize = first.size(); 
    int pointFlag = 0; 
    List<Boolean> poinsValidation = new ArrayList<>(); 
    for(Point line : second) 
    { 
     if(pointSize != 0 && pointFlag < pointSize) 
     { 
      if(Math.abs(first.get(pointFlag).x - line.x) <= accuracy && Math.abs(first.get(pointFlag).y - line.y) <= accuracy) 
      { 
       poinsValidation.add(true); 
       pointFlag++; 
      } 
     } 

    } 
    if(poinsValidation.size() == first.size()) 
    { 
     return true; 
    } 
    return false; 
} 
+0

您的相关代码在哪里? –

+1

我已经添加了。谢谢 –

+0

因为我想知道所有的第一点是否被识别或者没有 –

回答

0

我会建议通过这两个数组嵌套循环。虽然嵌套循环并不是首选,但在这个阶段,我想不出另一种方式来做到这一点。

private boolean checkValidate(List<Point> first, List<Point> second) 
{ 
    int accuracy = Helper.dpToPixel(this, 10); 
    int pointSize = first.size(); 
    int pointSize2 = second.size(); 
    int pointFlag = 0; 

    List<Boolean> poinsValidation = new ArrayList<>(); 
    for(Point line : second) 
    { 
     for(Point points: first){ 
      if(pointSize != 0 && pointSize2 != 0 && pointFlag < pointSize) 
      { 
       if(Math.abs(points.x - line.x) <= accuracy && Math.abs(points.y - line.y) <= accuracy) 
       { 
        poinsValidation.add(true); 
        pointFlag++; 
       } 
      } 
     } 

    } 
    if(poinsValidation.size() == first.size()) 
    { 
     return true; 
    } 
    return false; 
} 

让我知道这是否有帮助。