The question of whether your code is performant enough is something your profiler can better answer for you. But from looking through the code above I notice quite a bit of duplication along with some rather deeply nested if's which you should try to refactor. Take this for example:
if (li.getX1() < li.getX2()) {
Line2D l = new Line2D.Double(li.getP1(), li.getP2());
events.add(new AlgEvent(l, true));
events.add(new AlgEvent(l, false));
} else if (li.getX1() > li.getX2()) {
Line2D l = new Line2D.Double(li.getP2(), li.getP1());
events.add(new AlgEvent(l, true));
events.add(new AlgEvent(l, false));
} else {
if (li.getY1() < li.getY2()) {
Line2D l = new Line2D.Double(li.getP1(), li.getP2());
events.add(new AlgEvent(l, true));
events.add(new AlgEvent(l, false));
} else if (li.getY1() > li.getY2()) {
Line2D l = new Line2D.Double(li.getP2(), li.getP1());
events.add(new AlgEvent(l, true));
events.add(new AlgEvent(l, false));
} else
// ...
The two statements events.add(new AlgEvent(l, true));
and events.add(new AlgEvent(l, false));
are being repeated 4 times here!
Your line compare method here:
static class LineComparator implements Comparator<Line2D> {
public int compare(Line2D o1, Line2D o2) {
if (o1.getY1() < o2.getY1()) {
return -1;
} else if (o1.getY1() > o2.getY2()) {
// ...
}
can be shorted by taking advantage of logical short-circuit and the ternary operator. So something like this might be easier to read:
public int compare(Line2D o1, Line2D o2)
{
/* I'm not too familiar with java but can
the equals method be used here to check
if the lines are equal?
*/
// if( o1.equals(o2) ) return 0;
return (o1.getY1() < o2.getY1() ||
o1.getY2() < o2.getY2()) ? -1 :
(o1.getY1() > o2.getY2() ||
o1.getY2() > o2.getY2()) ? 1 : 0;
}
You can apply the same idea to AlgEvtComparator's compare method. One other thing I noticed in your line compare method, the checks' aren't exactly symmetrical. You have o1.Y1 comparing to o2.Y2 while all the others are checking Y1 to Y1 or Y2 to Y2. Was that really intended? I think this deserves a comment.
I'm guessing Line2D is a class you have defined somewhere. You might want to see if you're abstracting its usage enough or if an 'in-between' class is needed. The following code looks like it's leaking stuffing behind Line2D's interface:
if (estPath.size() != 0) {
Point2D pp = estPath.get(estPath.size() - 1).getP2();
estPath.add(new Line2D.Double(pp, new Point2D.Double(coords[0],coords[1])));
} else {
estPath.add(new Line2D.Double(new Point2D.Double(), new Point2D.Double(coords[0],coords[1])));
}