001package jmri.jmrix.rps;
002
003import javax.swing.JComboBox;
004import javax.vecmath.Point3d;
005
006/**
007 *
008 * Provide central access to the RPS algorithms.
009 *
010 * @author Bob Jacobsen Copyright (C) 2007
011 */
012public class Algorithms implements Constants {
013
014    static final int DEFAULTALGORITHMINDEX = 3;
015    static final String[] names = new String[]{
016        "Ash 2.0",
017        "Ash 2.1",
018        "Ash 2.2",
019        "Analytic A"
020    };
021
022    public static JComboBox<String> algorithmBox() {
023        JComboBox<String> j = new JComboBox<String>(names);
024        j.setSelectedItem(Engine.instance().getAlgorithm());
025        return j;
026    }
027
028    /**
029     * Create proper Calculator instance.
030     * @param points the points array.
031     * @param vs algorithm getVSound.
032     * @param offset algorithm offset.
033     * @param name algorithm name.
034     * @return the calculator.
035     */
036    public static Calculator newCalculator(Point3d[] points, double vs, int offset, String name) {
037        if (name.equals(names[0])) {
038            return new Ash2_0Algorithm(points, vs, offset);
039        } else if (name.equals(names[1])) {
040            return new Ash2_1Algorithm(points, vs, offset);
041        } else if (name.equals(names[2])) {
042            return new Ash2_2Algorithm(points, vs, offset);
043        } else if (name.equals(names[3])) {
044            return new Analytic_AAlgorithm(points, vs, offset);
045        } else // default is most recent
046        {
047            return new Ash2_1Algorithm(points, vs);
048        }
049    }
050
051}