final double x2, final double y2, final int mask2,
final double xmin, final double xmax,
final double ymin, final double ymax)
{
final int mask = mask1 ^ mask2;
Point2D p1 = null;
if (mask1 == INSIDE)
{
// point 1 is internal
p1 = new Point2D.Double(x1, y1);
if (mask == 0)
{
// both masks are the same, so the second point is inside, too
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = new Point2D.Double(x2, y2);
return ret;
}
}
else if (mask2 == INSIDE)
{
// point 2 is internal
p1 = new Point2D.Double(x2, y2);
}
if ((mask & LEFT) != 0)
{
// System.out.println("Trying left");
// try to calculate intersection with left line
final Point2D p = intersect(x1, y1, x2, y2, xmin, ymin, xmin, ymax);
if (p != null)
{
if (p1 == null)
{
p1 = p;
}
else
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;
return ret;
}
}
}
if ((mask & RIGHT) != 0)
{
// System.out.println("Trying right");
// try to calculate intersection with left line
final Point2D p = intersect(x1, y1, x2, y2, xmax, ymin, xmax, ymax);
if (p != null)
{
if (p1 == null)
{
p1 = p;
}
else
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;
return ret;
}
}
}
if (mask1 == (LEFT | BELOW) || mask1 == (RIGHT | BELOW))
{
// for exactly these two special cases use different sequence!
if ((mask & ABOVE) != 0)
{
// System.out.println("Trying top");
// try to calculate intersection with lower line
final Point2D p = intersect(x1, y1, x2, y2, xmin, ymax, xmax, ymax);
if (p != null)
{
if (p1 == null)
{
p1 = p;
}
else
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;
return ret;
}
}
}
if ((mask & BELOW) != 0)
{
// System.out.println("Trying bottom");
// try to calculate intersection with lower line
final Point2D p = intersect(x1, y1, x2, y2, xmin, ymin, xmax, ymin);
if (p != null && p1 != null)
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;
return ret;
}
}
}
else
{
if ((mask & BELOW) != 0)
{
// System.out.println("Trying bottom");
// try to calculate intersection with lower line
final Point2D p = intersect(x1, y1, x2, y2, xmin, ymin, xmax, ymin);
if (p != null)
{
if (p1 == null)
{
p1 = p;
}
else
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;
return ret;
}
}
}
if ((mask & ABOVE) != 0)
{
// System.out.println("Trying top");
// try to calculate intersection with lower line
final Point2D p = intersect(x1, y1, x2, y2, xmin, ymax, xmax, ymax);
if (p != null && p1 != null)
{
final Point2D[] ret = new Point2D[2];
ret[0] = p1;
ret[1] = p;