class Line2d {

    public List<? extends Vector2d> getSegmentIntersection(Vector2d ptA, Vector2d ptB)
    {
        List<Vector2d> intersections;

        Vector2d aDir = ptA.subtract(myPoint);
        Vector2d bDir = ptB.subtract(myPoint);

        double aDot = aDir.dot(myNormal);
        double bDot = bDir.dot(myNormal);

        // When the line passes through one or both vertices, add them.
        if (MathUtil.isZero(aDot))
        {
            if (ptA.equals(ptB))
            {
                throw new IllegalArgumentException("Line segment has zero length.");
            }
            else if (MathUtil.isZero(bDot))
            {
                intersections = Arrays.asList(ptA, ptB);
            }
            else
            {
                intersections = Collections.singletonList(ptA);
            }
        }

        else if (MathUtil.isZero(bDot))
        {
            intersections = Collections.singletonList(ptB);
        }

        // When the line does not pass through either vertex, it can intersect
        // the line segment only when the points are on opposite sides of the
        // plane.
        else if (!MathUtil.sameSign(aDot, bDot))
        {
            Vector2d intersection = getIntersection(ptA, ptB);
            intersections = intersection == null ? Collections.<Vector2d>emptyList() : Collections.singletonList(intersection);
        }
        else
        {
            intersections = Collections.emptyList();
        }

        return intersections;
    }

    public  Line2d(Vector2d point, Vector2d normal);

}