private void splitBendPoints(
     FreeFormConnection startConnection, Connection endConnection, int x, int y) {
   List<Point> points = new ArrayList<Point>();
   GraphicsAlgorithm startGa = startConnection.getStart().getGraphicsAlgorithm();
   if (startGa != null) {
     Point p = StylesFactory.eINSTANCE.createPoint();
     p.setX(startGa.getX());
     p.setY(startGa.getY());
     points.add(p);
   }
   points.addAll(startConnection.getBendpoints());
   GraphicsAlgorithm endGa = startConnection.getEnd().getGraphicsAlgorithm();
   if (endGa != null) {
     Point p = StylesFactory.eINSTANCE.createPoint();
     p.setX(endGa.getX());
     p.setY(endGa.getY());
     points.add(p);
   }
   Point p0 = null;
   int min = -1, minDistance2 = -1;
   for (int i = 0; i < points.size(); i++) {
     Point p1 = points.get(i);
     if (p0 == null) {
       p0 = p1;
     } else {
       int distance2 =
           distance2(x, p0.getX(), y, p0.getX()) + distance2(x, p1.getX(), y, p1.getY());
       if (min < 0 || distance2 < minDistance2) {
         min = i;
         minDistance2 = distance2;
       }
       p0 = p1;
     }
   }
   for (int i = min; i > 0 && i < points.size(); i++) {
     Point p = points.get(i);
     if (p.eContainer() != null) {
       ((List<?>) p.eContainer().eGet(p.eContainingFeature())).remove(p);
     }
     if (endConnection instanceof FreeFormConnection) {
       ((FreeFormConnection) endConnection).getBendpoints().add(p);
     }
   }
 }