Ejemplo n.º 1
0
  /**
   * Check if another polygon intersects with this polygon
   *
   * @param polygon
   * @return true if intersects, false otherwise
   */
  public boolean intersects(Polygon2D polygon) {

    if (!polygon.getBounds().intersects(getBounds())) {
      return false;
    }

    for (Enumeration e1 = edges(); e1.hasMoreElements(); ) {
      Line2D current = (Line2D) e1.nextElement();
      for (Enumeration e2 = polygon.edges(); e2.hasMoreElements(); ) {
        Line2D test = (Line2D) e2.nextElement();
        if (current.intersects(test)) {
          return true;
        }
      }
    }

    return false;
  }
Ejemplo n.º 2
0
 /**
  * Creates a new instance of Polygon2D with vertices with the same values as the {@code p}
  * parameter.
  *
  * @param polygon The polygon to copy
  */
 public Polygon2D(Polygon2D polygon) {
   for (Enumeration e = polygon.vertices(); e.hasMoreElements(); ) {
     addVertex(new Vector2D((Vector2D) e.nextElement()));
   }
 }