コード例 #1
0
  private void processSiteEvent(final Event newSite) {
    HalfEdge lBnd = coast.getHalfEdgeToTheLeftOf((newSite));
    HalfEdge rBnd = coast.getHalfEdgeToTheRightOf(lBnd);

    // if this half-edge has no edge,bot = bottom site (whatever that is)
    Site bot = lBnd.getRightReg(bottomSite);
    Edge e = edgeBisector.newEdgeThatBisects(bot, newSite);
    HalfEdge bisector1 = new HalfEdge(e, Edge.LE);
    // insert this new bisector edge between the left and right bounds
    coast.insert(lBnd, bisector1);

    // if the new bisector intersects with the left edge,
    // remove the left edge's vertex, and put in the new one
    Site p = lBnd.intersect(bisector1);
    if (p != null) {
      events.delete(lBnd);
      events.insert(lBnd, p, p.distTo(newSite));
    }

    HalfEdge bisector2 = new HalfEdge(e, Edge.RE);
    // insert the new HE to the right of the original bisector
    coast.insert(bisector1, bisector2);

    // if this new bisector intersects with the new HalfEdge
    p = bisector2.intersect(rBnd);
    if (p != null) {
      // push the HE into the ordered linked list of vertices
      events.insert(bisector2, p, p.distTo(newSite));
    }
  }
コード例 #2
0
  private void processCircleEvent() {

    // pop the HalfEdge with the lowest vector off the ordered list
    // of vectors
    HalfEdge lBnd = events.extractMin();
    // get the HalfEdge to the left of the above HE
    HalfEdge llBnd = coast.getHalfEdgeToTheLeftOf(lBnd);
    // get the HalfEdge to the right of the above HE
    HalfEdge rBnd = coast.getHalfEdgeToTheRightOf(lBnd);
    // get the HalfEdge to the right of the HE to the right of the
    // lowest HE
    HalfEdge rrBnd = coast.getHalfEdgeToTheRightOf(rBnd);
    // get the Site to the left of the left HE which it bisects
    Site bot = lBnd.getLeftReg(bottomSite);
    // get the Site to the right of the right HE which it bisects
    Site top = rBnd.getRightReg(bottomSite);

    Site v = lBnd.vertex; // get the vertex that caused this event
    // set the vertex number - couldn't do this
    // earlier since we didn't know when it would be processed
    v.sitenbr = nextVertexNbr++;

    endpoint(lBnd.edge, lBnd.side, v);
    // set the endpoint of
    // the left HalfEdge to be this vector
    endpoint(rBnd.edge, rBnd.side, v);
    // set the endpoint of the right HalfEdge to be this vector
    coast.delete(lBnd);
    events.delete(rBnd);
    // remove all vertex events to do with the right HE
    coast.delete(rBnd); // mark the right HE for
    // deletion - can't delete yet because there might be pointers
    // to it in Hash Map
    int pm = Edge.LE; // set the pm variable to zero

    if (bot.y > top.y) {
      // if the site to the left of the event is higher than the
      // Site
      // to the right of it, then swap them and set the 'pm'
      // variable to 1
      Site temp = bot;
      bot = top;
      top = temp;
      pm = Edge.RE;
    }
    Edge e = edgeBisector.newEdgeThatBisects(bot, top); // create an Edge (or
    // line)
    // that is between the two Sites. This creates the formula of
    // the line, and assigns a line number to it
    HalfEdge bisector = new HalfEdge(e, pm); // create a HE from the Edge
    // 'e',
    // and make it point to that edge
    // with its ELedge field
    coast.insert(llBnd, bisector); // insert the new bisector to the
    // right of the left HE
    endpoint(e, Edge.RE - pm, v); // set one endpoint to the new edge
    // to be the vector point 'v'.
    // If the site to the left of this bisector is higher than the
    // right Site, then this endpoint
    // is put in position 0; otherwise in pos 1

    // if left HE and the new bisector intersect, then delete
    // the left HE, and reinsert it
    Site p = llBnd.intersect(bisector);
    if (p != null) {
      events.delete(llBnd);
      events.insert(llBnd, p, p.distTo(bot));
    }

    // if right HE and the new bisector intersect, then
    // reinsert it
    p = bisector.intersect(rrBnd);
    if (p != null) {
      events.insert(bisector, p, p.distTo(bot));
    }
  }