/**
   * Melts in the outermost points if the points next to them already connect to the connection's
   * nodes. "Melting in" means removing them.
   */
  private void meltinNextToOuterPoints() {

    Node node1 = getConnection().getNode1();
    Node node2 = getConnection().getNode2();
    Connection c1 = getConnection().getConnection1();

    if (editpoints.size() > 2) {
      // remove last point if possible
      Point2D p = editpoints.get(editpoints.size() - 2);
      if (outcode(node2.getAbsoluteBounds(), p) == 0) {
        // see above
        removeEditPoint(editpoints.size() - 1);
      }
    }
    if (editpoints.size() > 2) {
      // remove point 0 if possible
      Point2D p = editpoints.get(1);
      if (node1 != null) {
        if (outcode(node1.getAbsoluteBounds(), p) == 0) {
          removeEditPoint(0);
        }
      } else {
        if (outcode(c1.getAbsoluteBounds(), p) == 0) {
          removeEditPoint(0);
        }
      }
    }
  }
  /**
   * If the drag operations resulted in the control point being dragged off the node, restore the
   * contact by inserting a new point which connects to the node again.
   */
  private void restoreConnectionToNode() {
    Point2D p0 = editpoints.get(0);
    Point2D pn = editpoints.get(editpoints.size() - 1);
    Node node1 = getConnection().getNode1();
    Node node2 = getConnection().getNode2();
    Connection c1 = getConnection().getConnection1();
    if (node1 != null && node2 != null) {
      int outcode1 = outcode(node1.getAbsoluteBounds(), p0);
      int outcode2 = outcode(node2.getAbsoluteBounds(), pn);
      if (outcode1 != 0) {
        insertConnectionPointToNode(node1, outcode1, 0);
      }
      if (outcode2 != 0) {
        insertConnectionPointToNode(node2, outcode2, getConnection().getPoints().size() - 1);
      }

    } else if (node1 == null && node2 != null) {
      int outcode1 = outcode(c1.getAbsoluteBounds(), p0);
      int outcode2 = outcode(node2.getAbsoluteBounds(), pn);
      if (outcode1 != 0) {
        insertConnectionPointToNode(c1, outcode1, 0);
      }
      if (outcode2 != 0) {
        insertConnectionPointToNode(node2, outcode2, getConnection().getPoints().size() - 1);
      }
    }
  }