Class MyBuffer

java.lang.Object
jme3utilities.math.MyBuffer

public final class MyBuffer extends Object
Utility methods that operate on buffers, especially float buffers containing 3-D vectors. Unlike the com.jme3.util.BufferUtils methods, these methods ignore buffer limits.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Logger
    message logger for this class
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.jme3.math.Matrix3f
    covariance(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Matrix3f storeResult)
    Return the sample covariance of the 3-D vectors in the specified FloatBuffer range.
    static float
    cylinderRadius(FloatBuffer buffer, int startPosition, int endPosition, int axisIndex)
    Return the radius of a bounding cylinder for the specified FloatBuffer range.
    static VectorSet
    distinct(FloatBuffer buffer, int startPosition, int endPosition)
    Enumerate all distinct 3-D vectors in the specified FloatBuffer range, distinguishing 0 from -0.
    ensureCapacity(int minFloats, FloatBuffer bufferToReuse)
    Reuse the specified FloatBuffer, if it has the required capacity.
    static void
    fill(FloatBuffer buffer, float... floatValues)
    Fill the specified FloatBuffer with a cyclic sequence of values.
    static int
    frequency(IntBuffer buffer, int startPosition, int endPosition, int intValue)
    Count the number of times the specified value occurs in the specified IntBuffer range.
    static void
    get(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f storeVector)
    Read a Vector3f starting from the specified position.
    static boolean
    isAllFinite(FloatBuffer buffer, int startPosition, int endPosition)
    Test whether all values in the specified FloatBuffer range are finite.
    static Set<IntPair>
    listNeighbors(FloatBuffer buffer, int startPosition, int endPosition, float maxDistance)
    Enumerate all pairs of 3-D vectors in the specified FloatBuffer range whose Euclidean distance is less that the specified limit.
    static com.jme3.math.Vector3f
    maxAbs(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult)
    Find the maximum absolute coordinate for each axis in the specified FloatBuffer range.
    static float
    maxLength(FloatBuffer buffer, int startPosition, int endPosition)
    Find the magnitude of the longest 3-D vector in the specified FloatBuffer range.
    static void
    maxMin(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeMaxima, com.jme3.math.Vector3f storeMinima)
    Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range.
    static com.jme3.math.Vector3f
    mean(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult)
    Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.
    static void
    normalize(FloatBuffer buffer, int startPosition, int endPosition)
    Normalize 3-D vectors in the specified FloatBuffer range.
    static void
    put(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f vector)
    Write a Vector3f starting at the specified position.
    static void
    put(FloatBuffer buffer, int startPosition, com.jme3.math.Vector4f vector)
    Write a Vector4f starting at the specified position.
    static int
    readIndex(Buffer buffer)
    Read an index from a Buffer and advance the buffer's position.
    static void
    rotate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation)
    Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.
    static void
    rotateBinormals(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation)
    Apply the specified rotation to the binormals in the specified FloatBuffer range.
    static void
    scale(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f scale)
    Apply the specified scale factors to 3-D vectors in the specified FloatBuffer range.
    static float[]
    toFloatArray(FloatBuffer buffer, int startPosition, int endPosition)
    Copy data in the specified FloatBuffer range to a new array.
    static int[]
    toIntArray(IntBuffer buffer, int startPosition, int endPosition)
    Copy data in the specified IntBuffer range to a new array.
    static void
    transform(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Transform transform)
    Apply the specified coordinate transform to 3-D vectors in the specified FloatBuffer range.
    static void
    translate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f offsetVector)
    Add the specified offset to 3-D vectors in the specified FloatBuffer range.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      public static final Logger logger
      message logger for this class
  • Method Details

    • covariance

      public static com.jme3.math.Matrix3f covariance(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Matrix3f storeResult)
      Return the sample covariance of the 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition-6)
      endPosition - the position at which the vectors end (≥startPosition+6, ≤capacity)
      storeResult - storage for the result (modified if not null)
      Returns:
      the unbiased sample covariance (either storeResult or a new matrix, not null)
    • cylinderRadius

      public static float cylinderRadius(FloatBuffer buffer, int startPosition, int endPosition, int axisIndex)
      Return the radius of a bounding cylinder for the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      axisIndex - the cylinder's height axis: 0→X, 1→Y, 2→Z
      Returns:
      the radius of the minimum bounding cylinder centered at the origin (≥0)
    • distinct

      public static VectorSet distinct(FloatBuffer buffer, int startPosition, int endPosition)
      Enumerate all distinct 3-D vectors in the specified FloatBuffer range, distinguishing 0 from -0.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      Returns:
      a new VectorSet (not null)
    • ensureCapacity

      public static FloatBuffer ensureCapacity(int minFloats, FloatBuffer bufferToReuse)
      Reuse the specified FloatBuffer, if it has the required capacity. If no buffer is specified, allocate a new one.
      Parameters:
      minFloats - the required capacity (in floats, ≥0)
      bufferToReuse - the buffer to reuse, or null for none
      Returns:
      a buffer with at least the required capacity (either storeResult or a new direct buffer)
    • fill

      public static void fill(FloatBuffer buffer, float... floatValues)
      Fill the specified FloatBuffer with a cyclic sequence of values.
      Parameters:
      buffer - the buffer to modify (not null)
      floatValues - the sequence of values (not null, unaffected)
    • frequency

      public static int frequency(IntBuffer buffer, int startPosition, int endPosition, int intValue)
      Count the number of times the specified value occurs in the specified IntBuffer range.
      Parameters:
      buffer - the buffer that contains the data (not null, unaffected)
      startPosition - the position at which the data start (≥0, ≤endPosition)
      endPosition - the position at which the data end (≥startPosition, ≤capacity)
      intValue - the value to search for
      Returns:
      the number of occurrences found (≥0)
    • get

      public static void get(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f storeVector)
      Read a Vector3f starting from the specified position. Does not alter the buffer's position.
      Parameters:
      buffer - the buffer to read from (not null, unaffected)
      startPosition - the position at which to start reading (≥0)
      storeVector - storage for the vector (not null, modified)
      See Also:
      • BufferUtils.populateFromBuffer(com.jme3.math.Vector3f, java.nio.FloatBuffer, int)
    • isAllFinite

      public static boolean isAllFinite(FloatBuffer buffer, int startPosition, int endPosition)
      Test whether all values in the specified FloatBuffer range are finite.
      Parameters:
      buffer - the buffer that contains the data (not null, unaffected)
      startPosition - the position at which the data start (≥0, ≤endPosition)
      endPosition - the position at which the data end (≥startPosition, ≤capacity)
      Returns:
      false if any value is NaN or infinite, otherwise true
    • listNeighbors

      public static Set<IntPair> listNeighbors(FloatBuffer buffer, int startPosition, int endPosition, float maxDistance)
      Enumerate all pairs of 3-D vectors in the specified FloatBuffer range whose Euclidean distance is less that the specified limit.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      maxDistance - the desired limit (≥0)
      Returns:
      a new list of zero-origin index pairs
    • maxAbs

      public static com.jme3.math.Vector3f maxAbs(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult)
      Find the maximum absolute coordinate for each axis in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      storeResult - storage for the result (modified if not null)
      Returns:
      the half extent for each axis (either storeResult or a new instance)
    • maxLength

      public static float maxLength(FloatBuffer buffer, int startPosition, int endPosition)
      Find the magnitude of the longest 3-D vector in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      Returns:
      the radius of the minimum bounding sphere centered at the origin (≥0)
    • maxMin

      public static void maxMin(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeMaxima, com.jme3.math.Vector3f storeMinima)
      Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range. An empty range stores infinities.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      storeMaxima - storage for maxima (not null, modified)
      storeMinima - storage for minima (not null, modified)
      See Also:
      • BoundingBox.containAABB(java.nio.FloatBuffer)
    • mean

      public static com.jme3.math.Vector3f mean(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult)
      Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, unaffected)
      startPosition - the position at which the vectors start (≥0, ≤endPosition-3)
      endPosition - the position at which the vectors end (≥startPosition+3, ≤capacity)
      storeResult - storage for the result (modified if not null)
      Returns:
      the mean (either storeResult or a new vector, not null)
    • normalize

      public static void normalize(FloatBuffer buffer, int startPosition, int endPosition)
      Normalize 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, modified)
      startPosition - the position at which the vectors start (≥0, ≤endPosition-3)
      endPosition - the position at which the vectors end (≥startPosition+3, ≤capacity)
    • put

      public static void put(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f vector)
      Write a Vector3f starting at the specified position. Does not alter the buffer's position.
      Parameters:
      buffer - the buffer to write to (not null, modified)
      startPosition - the position at which to start writing (≥0)
      vector - the input vector (not null, unaffected)
      See Also:
      • BufferUtils.setInBuffer(com.jme3.math.Vector3f, java.nio.FloatBuffer, int)
    • put

      public static void put(FloatBuffer buffer, int startPosition, com.jme3.math.Vector4f vector)
      Write a Vector4f starting at the specified position. Does not alter the buffer's position.
      Parameters:
      buffer - the buffer to write to (not null, modified)
      startPosition - the position at which to start writing (≥0)
      vector - the input vector (not null, unaffected)
      See Also:
      • BufferUtils.setInBuffer(com.jme3.math.Vector4f, java.nio.FloatBuffer, int)
    • readIndex

      public static int readIndex(Buffer buffer)
      Read an index from a Buffer and advance the buffer's position.
      Parameters:
      buffer - a Buffer of bytes or ints or shorts (not null)
      Returns:
      index (≥0)
    • rotate

      public static void rotate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation)
      Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, MODIFIED)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      rotation - the rotation to apply (not null, unaffected)
    • rotateBinormals

      public static void rotateBinormals(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation)
      Apply the specified rotation to the binormals in the specified FloatBuffer range. The W components are left untouched.
      Parameters:
      buffer - the buffer that contains the binormals (not null, MODIFIED)
      startPosition - the position at which the binormals start (≥0, ≤endPosition)
      endPosition - the position at which the binormals end (≥startPosition, ≤capacity)
      rotation - the rotation to apply (not null, unaffected)
    • scale

      public static void scale(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f scale)
      Apply the specified scale factors to 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, MODIFIED)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      scale - the scale factor to apply to each axis (not null, unaffected)
    • toFloatArray

      public static float[] toFloatArray(FloatBuffer buffer, int startPosition, int endPosition)
      Copy data in the specified FloatBuffer range to a new array.
      Parameters:
      buffer - the buffer that contains the data (not null, unaffected)
      startPosition - the position at which the data start (≥0, ≤endPosition)
      endPosition - the position at which the data end (≥startPosition, ≤capacity)
      Returns:
      a new array (not null)
    • toIntArray

      public static int[] toIntArray(IntBuffer buffer, int startPosition, int endPosition)
      Copy data in the specified IntBuffer range to a new array.
      Parameters:
      buffer - the buffer that contains the data (not null, unaffected)
      startPosition - the position at which the data start (≥0, ≤endPosition)
      endPosition - the position at which the data end (≥startPosition, ≤capacity)
      Returns:
      a new array (not null)
    • transform

      public static void transform(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Transform transform)
      Apply the specified coordinate transform to 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, MODIFIED)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      transform - the transform to apply (not null, unaffected)
    • translate

      public static void translate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f offsetVector)
      Add the specified offset to 3-D vectors in the specified FloatBuffer range.
      Parameters:
      buffer - the buffer that contains the vectors (not null, MODIFIED)
      startPosition - the position at which the vectors start (≥0, ≤endPosition)
      endPosition - the position at which the vectors end (≥startPosition, ≤capacity)
      offsetVector - the vector to add (not null, unaffected)