⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rect.java

📁 移动对象空间数据库中索引r树源码,能在eclipse下直接运行.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    if((rect.getMinY() >= minY) || (rect.getMaxY() <= maxY))      return false;    return ret;  }  /**     This method also gives whether one point is over another, if you do not     want that much precision then comment the line.This will improve performance.     @return true if both the rectangle overlap/intresect else false.     <br><b>Note:-</b>This method is not precisely according to Egenhofer.  */  public boolean overlaps(Rect rect)    throws IllegalValueException  {    if(rect == null)      throw new IllegalValueException("Rect.overlaps: null argument");    int rectMinX = rect.getMinX();    int rectMinY = rect.getMinY();    int rectMaxX = rect.getMaxX();    int rectMaxY = rect.getMaxY();    boolean ret = false;    //if one point object is over another then.....    if((minX == rectMinX) && (minY == rectMinY) && (maxX == rectMaxX) && (maxY == rectMaxY))      return true;    //if you do not want this much precision then comment above written line.            //X dim.    if((minX < rectMaxX) && (maxX > rectMinX))      ret = true;    else      return false;    //Y dim.    if((minY < rectMaxY) && (maxY > rectMinY))      ret = true;    else      return false;    return ret;  }//overlaps  /**     Saperate or not(Egenhofer).     <br>To check if two rectangles intersect in any way then call '!disjoint()'.  */  public boolean disjoint(Rect rect)    throws IllegalValueException  {     if(rect == null)      throw new IllegalValueException("rtree.Rect.disjoint: null argument");    boolean ret = true;    //m12 = false && m22 = false    //X dim.    if((minX <= rect.getMaxX()) && (maxX >= rect.getMinX()))      ret = false;    else      return ret;    //Y dim.    if((minY <= rect.getMaxY()) && (maxY >= rect.getMinY()))      ret = false;    else       ret = true;    return ret;  }//disjoint - over  /**     Checks if both the rectangles meet or not.  */  public boolean meet(Rect rect)    throws IllegalValueException  {     if(rect == null)      throw new IllegalValueException("rtree.Rect.meet: null argument");    boolean ret = true;    //m11 = false    if(disjoint(rect))      return false;    //if both have common area then exit with false.    if((minX < rect.getMaxX()) && (maxX > rect.getMinX()))      if((minY < rect.getMaxY()) && (maxY > rect.getMinY()))        return false;    System.out.println("Raj!");    //m22 = true    if((minX == rect.getMaxX()) || (maxX == rect.getMinX()))      return true;    else      ret = false;    if((minY == rect.getMaxY()) || (maxY == rect.getMinY()))      ret = true;    return ret;  }//meet  /**     Checks if this rectangle contains 'rect'. This method is incomplete. It can      be finished if required.(Depends on query requirements)       <pre>     ---------------     |             |     |      |------|     |      |'rect'|     |      |------|     |             |     ---------------     </pre>  */  public boolean covers(Rect rect)    throws IllegalValueException  {     if(rect == null)      throw new IllegalValueException("rtree.Rect.covers: null argument");    boolean ret = true;    //m12 = true    if((minX > rect.getMaxX()) || (maxX < rect.getMinX()))      return false;    if((minY > rect.getMaxY()) || (maxY < rect.getMinY()))      return false;    //m21 = false    if((minX < rect.getMinX()) && (maxX < rect.getMaxX()))      return false;    if((minY < rect.getMinY()) && (maxY < rect.getMaxY()))      return false;    //m22 = true    if((minX != rect.getMinX()) && (maxX != rect.getMaxX()))      return false;    if((minY != rect.getMinY()) && (maxY != rect.getMaxY()))      return false;    return ret;  }  /**     Checks if this rectangle is equal to 'rect'  */  public boolean equals(Rect rect)    throws IllegalValueException  {     if(rect == null)      throw new IllegalValueException("rtree.Rect.equals: null argument");    //m21=false && m23=false    if((minX != rect.getMinX()) || (maxX != rect.getMaxX()))      return false;    if((minY != rect.getMinY()) || (maxY != rect.getMaxY()))      return false;    return true;  }  public String toString()  {    String ret;    ret = "\nThe Rectangle:-";    ret += "\n\tminX: " + minX;    ret += "\n\tminY: " + minY;    ret += "\n\tmaxX: " + maxX;    ret += "\n\tmaxY: " + maxY;    return ret;  }  /**     Calculate the Euclidean distance between the point and the MBR.     To calculate the distance(MINDIST) betn. a Point and Rectangle in      n dimension. In our case we consider only 2 dimensions.     <br><b>Note:-</b> The distance is the square of the actual distance. To find the actual      distance, square root the returned value.  */  public static long minDist(Point p, Rect rect)  {    long minDist;    int ri;//see Roussopoulos for notations    int pX = p.getX();    int pY = p.getY();    int minX = rect.getMinX();    int minY = rect.getMinY();    int maxX = rect.getMaxX();    int maxY = rect.getMaxY();    //for X dim.    if(pX < minX)      ri = minX;    else if(pX > maxX)      ri = maxX;    else      ri = pX;    Long temp = new Long(Math.abs(pX - ri));    minDist = (new Double(Math.pow(temp.doubleValue(),2))).longValue();    //for Y dim.    if(pY < minY)      ri = minY;    else if(pY > maxY)      ri = maxY;    else      ri = pY;    temp = new Long(Math.abs(pY - ri));    minDist += (new Double(Math.pow(temp.doubleValue(),2))).longValue();    return minDist;  }  /**     To find the minimum of the maximum distances from a point to a Rectangle     <b>(Not implemeneted yet).</b>     For further details see Roussopoulos.     If we apply Cheung then it will not be used.  */  public static int minMaxDist(Point p, Rect rect)  {    return(0);  }  /**   * Will return the intersection of the <code>this</code> and <code>rect</code>.   * @param rect The other <code>Rect</code>   */  public Rect intersection(Rect rect)  {    if(rect == null)      throw new IllegalArgumentException("Rect.instersection : Argument Rect is null");    int x1;// = 0    int y1;// = 0;    int x2;// = -1;    int y2;// = -1;    //minX    if(minX < rect.minX)      x1 = rect.minX;    else      x1 = minX;    //minY    if(minY < rect.minY)      y1 = rect.minY;    else      y1 = minY;    //maxX    if(maxX > rect.maxX)      x2 = rect.maxX;    else      x2 = maxX;    //maxY    if(maxY > rect.maxY)      y2 = rect.maxY;    else      y2 = maxY;    try{      if(x1 > x2 || y1 > y2)        return new Rect();      else        return new Rect(x1, y1, x2, y2);    }catch(Exception e){      e.printStackTrace();      return new Rect();    }  }}//TODO/*  New disjunctions of topological relations can be derived from the  minimal subset algorithm(Egenhofer)  <br> To do so first make a method for each of the matrix element. Then  using the algo. find the conditions of the matrix to satisfy and call  the desired methods.  Although this is possible through the combinations of the eight methods  directly but it would need a lot of processing.*//*  The diif. bet. this function and 'overlap' is that the latter returns  false if the two rects have only a side(s) in common but no area.  This method returns true if both the rects have either or both  area and side(s) common.  <br><b>returns true if ((meet=true)||(overlap=true)||(covers=true)||  (equal=true)) or it can be said not disjoint.  @return true if this rect. touches or overlaps with 'rect'*//*  public boolean intersect(Rect rect)  throws IllegalValueException  {  if(rect == null)  throw new IllegalValueException("rtree.Rect.overlaps: null argument");  boolean ret = true;  //X dim.  if((minX > rect.getMaxX()) || (maxX < rect.getMinX()))  return false;  //Y dim.  if((minY > rect.getMaxY()) || (maxY < rect.getMinY()))  return false;  return ret;  }*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -