package ec.gp.semantic.geometry;

import ec.gp.semantic.*;

public class UnbiasedDoubleMidpointProvider implements IMidpointProvider<Double> {

	@Override
	public DesiredSemanticsBase<Double> getMidpoint(ISemantics semantics1, ISemantics semantics2) {
		double[] s1 = (double[]) semantics1.getValue();
		double[] s2 = (double[]) semantics2.getValue();

		DesiredSemanticsBase<Double> ds = new DesiredSemanticsBase<Double>(s1.length);
		for (int i = 0; i < s1.length; ++i) {
			if (Double.isNaN(s1[i]) || Double.isNaN(s2[i]) || Double.isInfinite(s1[i]) || Double.isInfinite(s2[i])) {
				// don't care
				assert ds.getValuesFor(i).size() == 0;
			} else {
				ds.addValues(i, 0.5 * (s1[i] + s2[i]));
			}
		}

		return ds;
	}

}
