Exemplo n.º 1
0
  /**
   * Returns the vector element at the specified position, as a {@link Vec4}. This buffer's logical
   * vector size must be either 2, 3 or 4.
   *
   * @param position the logical vector position.
   * @return the vector at the specified vector position.
   * @throws IllegalArgumentException if the position is out of range, or if this buffer cannot
   *     store a Vec4.
   */
  public Vec4 getVector(int position) {
    if (position < 0 || position >= this.getSize()) {
      String message =
          Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (this.coordsPerVec != 2 && this.coordsPerVec != 3 && this.coordsPerVec != 4) {
      String message = Logging.getMessage("generic.BufferIncompatible", this);
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    double[] compArray = new double[this.coordsPerVec];
    this.get(position, compArray);
    return Vec4.fromDoubleArray(compArray, 0, this.coordsPerVec);
  }