private static Point2D getProjectionOnEdge(Point2D source, Point2D wayPoint, double panelWidth, double panelHeight) {
        final LineEquation eq = new LineEquation(source, wayPoint);
        double interX; // X coord of the intersection
        double interY; // Y coord of the intersection

        if (eq.a > 0) {
            // Intersection avec la droite y = y_max
            interX = -(eq.c + eq.b * panelHeight) / eq.a;
            interY = panelHeight;
        } else {
            // Intersection avec la droite y = 0
            interX = -eq.c / eq.a;
            interY = 0;
        }
        if (interX >= 0 && interX <= panelWidth) {
            // this point is in the boundaries, no need to carry on
            return new Point2D.Double(interX, interY);
        }

        if (eq.b > 0) {
            // Intersection avec la droite x = 0
            interX = 0;
            interY = -eq.c / eq.b;
        } else {
            // Intersection avec la droite x = x_max
            interX = panelWidth;
            interY = -(eq.c + eq.a * panelWidth) / eq.b;
        }
        if (interY >= 0 && interY <= panelHeight) {
            // this point is in the boundaries
            return new Point2D.Double(interX, interY);
        }

        throw new RuntimeException("No correct intersection was found");
    }