Example #1
0
 public static DoublyConnectedEdgeList linesToDCEdgeList(LineCollection lc) {
   DoublyConnectedEdgeList p = new DoublyConnectedEdgeList();
   Vector<Line> l = lc.getAllLines();
   for (int i = 0; i < l.size(); i++) {
     p.addHalfEdge(new DCHalfEdge(l.get(i).start.copy(), l.get(i).end.copy()));
   }
   return p;
 }
Example #2
0
  public static DCHalfEdge getIntersectedEdge(
      Point focus, Point direction, DCHalfEdge parentEdge, DoublyConnectedEdgeList border) {

    DCHalfEdge edge = new DCHalfEdge(focus, direction);

    double dx = direction.getX() - focus.getX(); // direction x
    double dy = direction.getY() - focus.getY(); // direction y

    DCHalfEdge borderEdge = null; // selected border edge for intersection;

    double[] thetas = border.getBorderPoints(focus); // degrees of all points along the border

    double edgeTheta = Geom.cartToPolar(dx, dy)[1]; // degree of edge
    double selectedTheta = -1;
    // myParent.println("\n\n\n edgeTheta="+edgeTheta+"\n\n\n");

    for (int i = 0;
        i < thetas.length;
        i++) { // iterate through all edges and look for correct point of intersection
      // myParent.println("edge "+i+" theta="+thetas[i]+" x="+border.edges.get(i).start.getX()+"
      // y="+border.edges.get(i).start.getY());
      int after = i + 1;
      if (i == thetas.length - 1) {
        after = 0;
      }

      if (thetas[after]
          > thetas[
              i]) { // special case where angle of previous edge is greater than angle of current
        // edge
        // myParent.println("call special case");
        if (edgeTheta >= thetas[after]
            || edgeTheta < thetas[i]) { // detects quadrant of intersection for special case

          if (edgeTheta > thetas[i]) {
            borderEdge = border.edges.get(i - 1);

            selectedTheta = thetas[i];
          } else {
            borderEdge = border.edges.get(i);

            selectedTheta = thetas[after];
          }

          /*myParent.println("\n\n\n edgeTheta="+edgeTheta);
          myParent.println("theta i="+thetas[i]);
          myParent.println("theta after="+thetas[after]);
          myParent.println("selected theta="+selectedTheta);
          myParent.println("start x,y,="+focus.getX()+","+focus.getY());
          myParent.println("end x,y,="+direction.getX()+","+direction.getY());
          myParent.println("intersection x,y,="+intersection.getX()+","+intersection.getY()+"\n\n\n");*/

          parentEdge.infiniteEdge = 1;
          break;
        }
      } else { // otherwise all thetas should be greater than the preceeding theta

        if (edgeTheta <= thetas[i]
            && edgeTheta > thetas[after]) { // detects quadrant of intersection

          borderEdge = border.edges.get(i);
          selectedTheta = thetas[i];
          break;
        }
      }
    }

    return borderEdge;
  }