public double NextPropagationTime(double time) {
	double tbase = delay;
	double toffset = 0;
	if (time > delay) {
	    tbase = Math.floor((time - delay)/period)*period + delay;
	    toffset = time - tbase + 1e-13;
	}

	if (tp1 == -1) {
	    if (tp2 == -1) return -1;
	    return (toffset < tp2) ? tbase + tp2 : tbase + period + tp2;
	} else if (tp2 == -1)
	    return (toffset < tp1) ? tbase + tp1 : tbase + period + tp1;
	else if (toffset < tp1) return tbase + tp1;
	else if (toffset < tp2) return tbase + tp2;
	else return tbase + period + tp1;
    }