d += segLength;
    public byte getDirectionAtDistance(Point p, int distance) {	double d = 0.0;	ListIterator li = segments.listIterator(0);	while (li.hasNext()) {	    IntLine l = (IntLine) li.next();	    double segLength = l.getLength();	    if (d + segLength >= distance) {		// locus is within this segment.		p.x = l.x1 + (int) ((l.x2 - l.x1) * (distance - d) / segLength);		p.y = l.y1 + (int) ((l.y2 - l.y1) * (distance - d) / segLength);		return l.getDirection();	    }	    d += segLength;	}	// distance was bigger than length of the TrainPath	throw new IllegalArgumentException();    }