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 Matrix3f
    covariance(FloatBuffer buffer, int startPosition, int endPosition, 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.
    ensureCapacity(int minFloats, FloatBuffer bufferToReuse)
    Reuse the specified FloatBuffer, if it has the required capacity.
    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, Vector3f storeVector)
    Read a Vector3f starting from the specified position.
    static Vector3f
    maxAbs(FloatBuffer buffer, int startPosition, int endPosition, 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, Vector3f storeMaxima, Vector3f storeMinima)
    Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range.
    static Vector3f
    mean(FloatBuffer buffer, int startPosition, int endPosition, Vector3f storeResult)
    Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.
    static void
    put(FloatBuffer buffer, int startPosition, Vector3f vector)
    Write a Vector3f starting at the specified position.
    static void
    rotate(FloatBuffer buffer, int startPosition, int endPosition, Quaternion rotation)
    Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.
    static void
    transform(FloatBuffer buffer, int startPosition, int endPosition, 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, 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 Matrix3f covariance(FloatBuffer buffer, int startPosition, int endPosition, 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)
    • 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)
    • 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, 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)
    • maxAbs

      public static Vector3f maxAbs(FloatBuffer buffer, int startPosition, int endPosition, 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, Vector3f storeMaxima, 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)
    • mean

      public static Vector3f mean(FloatBuffer buffer, int startPosition, int endPosition, 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)
    • put

      public static void put(FloatBuffer buffer, int startPosition, 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)
    • rotate

      public static void rotate(FloatBuffer buffer, int startPosition, int endPosition, 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)
    • transform

      public static void transform(FloatBuffer buffer, int startPosition, int endPosition, 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, 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)