001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math;
006
007import edu.wpi.first.math.numbers.N1;
008import edu.wpi.first.math.numbers.N10;
009import edu.wpi.first.math.numbers.N2;
010import edu.wpi.first.math.numbers.N3;
011import edu.wpi.first.math.numbers.N4;
012import edu.wpi.first.math.numbers.N5;
013import edu.wpi.first.math.numbers.N6;
014import edu.wpi.first.math.numbers.N7;
015import edu.wpi.first.math.numbers.N8;
016import edu.wpi.first.math.numbers.N9;
017
018/**
019 * A specialization of {@link MatBuilder} for constructing vectors (Nx1 matrices).
020 *
021 * @param <N> The dimension of the vector to be constructed.
022 */
023public class VecBuilder<N extends Num> extends MatBuilder<N, N1> {
024  public VecBuilder(Nat<N> rows) {
025    super(rows, Nat.N1());
026  }
027
028  private Vector<N> fillVec(double... data) {
029    return new Vector<>(fill(data));
030  }
031
032  /**
033   * Returns a 1x1 vector containing the given elements.
034   *
035   * @param n1 the first element.
036   * @return 1x1 vector
037   */
038  public static Vector<N1> fill(double n1) {
039    return new VecBuilder<>(Nat.N1()).fillVec(n1);
040  }
041
042  /**
043   * Returns a 2x1 vector containing the given elements.
044   *
045   * @param n1 the first element.
046   * @param n2 the second element.
047   * @return 2x1 vector
048   */
049  public static Vector<N2> fill(double n1, double n2) {
050    return new VecBuilder<>(Nat.N2()).fillVec(n1, n2);
051  }
052
053  /**
054   * Returns a 3x1 vector containing the given elements.
055   *
056   * @param n1 the first element.
057   * @param n2 the second element.
058   * @param n3 the third element.
059   * @return 3x1 vector
060   */
061  public static Vector<N3> fill(double n1, double n2, double n3) {
062    return new VecBuilder<>(Nat.N3()).fillVec(n1, n2, n3);
063  }
064
065  /**
066   * Returns a 4x1 vector containing the given elements.
067   *
068   * @param n1 the first element.
069   * @param n2 the second element.
070   * @param n3 the third element.
071   * @param n4 the fourth element.
072   * @return 4x1 vector
073   */
074  public static Vector<N4> fill(double n1, double n2, double n3, double n4) {
075    return new VecBuilder<>(Nat.N4()).fillVec(n1, n2, n3, n4);
076  }
077
078  /**
079   * Returns a 5x1 vector containing the given elements.
080   *
081   * @param n1 the first element.
082   * @param n2 the second element.
083   * @param n3 the third element.
084   * @param n4 the fourth element.
085   * @param n5 the fifth element.
086   * @return 5x1 vector
087   */
088  public static Vector<N5> fill(double n1, double n2, double n3, double n4, double n5) {
089    return new VecBuilder<>(Nat.N5()).fillVec(n1, n2, n3, n4, n5);
090  }
091
092  /**
093   * Returns a 6x1 vector containing the given elements.
094   *
095   * @param n1 the first element.
096   * @param n2 the second element.
097   * @param n3 the third element.
098   * @param n4 the fourth element.
099   * @param n5 the fifth element.
100   * @param n6 the sixth element.
101   * @return 6x1 vector
102   */
103  public static Vector<N6> fill(double n1, double n2, double n3, double n4, double n5, double n6) {
104    return new VecBuilder<>(Nat.N6()).fillVec(n1, n2, n3, n4, n5, n6);
105  }
106
107  /**
108   * Returns a 7x1 vector containing the given elements.
109   *
110   * @param n1 the first element.
111   * @param n2 the second element.
112   * @param n3 the third element.
113   * @param n4 the fourth element.
114   * @param n5 the fifth element.
115   * @param n6 the sixth element.
116   * @param n7 the seventh element.
117   * @return 7x1 vector
118   */
119  public static Vector<N7> fill(
120      double n1, double n2, double n3, double n4, double n5, double n6, double n7) {
121    return new VecBuilder<>(Nat.N7()).fillVec(n1, n2, n3, n4, n5, n6, n7);
122  }
123
124  /**
125   * Returns a 8x1 vector containing the given elements.
126   *
127   * @param n1 the first element.
128   * @param n2 the second element.
129   * @param n3 the third element.
130   * @param n4 the fourth element.
131   * @param n5 the fifth element.
132   * @param n6 the sixth element.
133   * @param n7 the seventh element.
134   * @param n8 the eighth element.
135   * @return 8x1 vector
136   */
137  public static Vector<N8> fill(
138      double n1, double n2, double n3, double n4, double n5, double n6, double n7, double n8) {
139    return new VecBuilder<>(Nat.N8()).fillVec(n1, n2, n3, n4, n5, n6, n7, n8);
140  }
141
142  /**
143   * Returns a 9x1 vector containing the given elements.
144   *
145   * @param n1 the first element.
146   * @param n2 the second element.
147   * @param n3 the third element.
148   * @param n4 the fourth element.
149   * @param n5 the fifth element.
150   * @param n6 the sixth element.
151   * @param n7 the seventh element.
152   * @param n8 the eighth element.
153   * @param n9 the ninth element.
154   * @return 9x1 vector
155   */
156  public static Vector<N9> fill(
157      double n1,
158      double n2,
159      double n3,
160      double n4,
161      double n5,
162      double n6,
163      double n7,
164      double n8,
165      double n9) {
166    return new VecBuilder<>(Nat.N9()).fillVec(n1, n2, n3, n4, n5, n6, n7, n8, n9);
167  }
168
169  /**
170   * Returns a 10x1 vector containing the given elements.
171   *
172   * @param n1 the first element.
173   * @param n2 the second element.
174   * @param n3 the third element.
175   * @param n4 the fourth element.
176   * @param n5 the fifth element.
177   * @param n6 the sixth element.
178   * @param n7 the seventh element.
179   * @param n8 the eighth element.
180   * @param n9 the ninth element.
181   * @param n10 the tenth element.
182   * @return 10x1 vector
183   */
184  public static Vector<N10> fill(
185      double n1,
186      double n2,
187      double n3,
188      double n4,
189      double n5,
190      double n6,
191      double n7,
192      double n8,
193      double n9,
194      double n10) {
195    return new VecBuilder<>(Nat.N10()).fillVec(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10);
196  }
197}