Skip to content

Commit

Permalink
Fix and add various Matrix.getTransposed/getTransposedFloats() (#317)
Browse files Browse the repository at this point in the history
- fix Matrix2d.getTransposed(Buffer buffer)
- fix Matrix4x3d.getTransposedFloats(ByteBuffer)
- add Matrix2d.getTransposed([int, ]FloatBuffer)/getTransposedFloats()
- add Matrix3d.getTransposed()/getTransposedFloats()
- add Matrix3x2d.getTransposed()/getTransposedFloats()
- add Matrix4d.getTransposed([int, ]FloatBuffer)/getTransposedFloats()
  • Loading branch information
httpdigest committed Aug 30, 2022
1 parent dd65345 commit d99f4f0
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 28 deletions.
32 changes: 30 additions & 2 deletions src/org/joml/Matrix2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//#ifdef __HAS_NIO__
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
//#endif
import java.io.Externalizable;
import java.io.IOException;
Expand Down Expand Up @@ -670,23 +671,50 @@ public ByteBuffer get(int index, ByteBuffer buffer) {
return buffer;
}

public ByteBuffer getFloats(ByteBuffer buffer) {
return getFloats(buffer.position(), buffer);
}

public ByteBuffer getFloats(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putf(this, index, buffer);
return buffer;
}

public DoubleBuffer getTransposed(DoubleBuffer buffer) {
return get(buffer.position(), buffer);
return getTransposed(buffer.position(), buffer);
}

public DoubleBuffer getTransposed(int index, DoubleBuffer buffer) {
MemUtil.INSTANCE.putTransposed(this, index, buffer);
return buffer;
}

public FloatBuffer getTransposed(FloatBuffer buffer) {
return getTransposed(buffer.position(), buffer);
}

public FloatBuffer getTransposed(int index, FloatBuffer buffer) {
MemUtil.INSTANCE.putfTransposed(this, index, buffer);
return buffer;
}

public ByteBuffer getTransposed(ByteBuffer buffer) {
return get(buffer.position(), buffer);
return getTransposed(buffer.position(), buffer);
}

public ByteBuffer getTransposed(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putTransposed(this, index, buffer);
return buffer;
}

public ByteBuffer getTransposedFloats(ByteBuffer buffer) {
return getTransposedFloats(buffer.position(), buffer);
}

public ByteBuffer getTransposedFloats(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putfTransposed(this, index, buffer);
return buffer;
}
//#endif

//#ifdef __HAS_UNSAFE__
Expand Down
143 changes: 129 additions & 14 deletions src/org/joml/Matrix2dc.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//#ifdef __HAS_NIO__
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
//#endif
import java.util.*;

Expand Down Expand Up @@ -275,68 +276,182 @@ public interface Matrix2dc {
ByteBuffer get(int index, ByteBuffer buffer);

/**
* Store the transpose of this matrix in column-major order into the supplied {@link DoubleBuffer} at the current
* Store the elements of this matrix as float values in column-major order into the supplied {@link ByteBuffer} at the current
* buffer {@link ByteBuffer#position() position}.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given ByteBuffer.
* <p>
* In order to specify the offset into the ByteBuffer at which
* the matrix is stored, use {@link #getFloats(int, ByteBuffer)}, taking
* the absolute position as parameter.
*
* @see #getFloats(int, ByteBuffer)
*
* @param buffer
* will receive the elements of this matrix as float values in column-major order at its current position
* @return the passed in buffer
*/
ByteBuffer getFloats(ByteBuffer buffer);

/**
* Store the elements of this matrix as float values in column-major order into the supplied {@link ByteBuffer}
* starting at the specified absolute buffer position/index.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given ByteBuffer.
*
* @param index
* the absolute position into the ByteBuffer
* @param buffer
* will receive the elements of this matrix as float values in column-major order
* @return the passed in buffer
*/
ByteBuffer getFloats(int index, ByteBuffer buffer);

/**
* Store this matrix in row-major order into the supplied {@link DoubleBuffer} at the current
* buffer {@link DoubleBuffer#position() position}.
* <p>
* This method will not increment the position of the given DoubleBuffer.
* <p>
* In order to specify the offset into the DoubleBuffer at which
* the matrix is stored, use {@link #getTransposed(int, DoubleBuffer)}, taking
* the absolute position as parameter.
*
*
* @see #getTransposed(int, DoubleBuffer)
*
*
* @param buffer
* will receive the values of this matrix in column-major order at its current position
* will receive the values of this matrix in row-major order at its current position
* @return the passed in buffer
*/
DoubleBuffer getTransposed(DoubleBuffer buffer);

/**
* Store the transpose of this matrix in column-major order into the supplied {@link DoubleBuffer} starting at the specified
* Store this matrix in row-major order into the supplied {@link DoubleBuffer} starting at the specified
* absolute buffer position/index.
* <p>
* This method will not increment the position of the given DoubleBuffer.
*
*
* @param index
* the absolute position into the DoubleBuffer
* @param buffer
* will receive the values of this matrix in column-major order
* will receive the values of this matrix in row-major order
* @return the passed in buffer
*/
DoubleBuffer getTransposed(int index, DoubleBuffer buffer);

/**
* Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} at the current
* Store this matrix in row-major order into the supplied {@link ByteBuffer} at the current
* buffer {@link ByteBuffer#position() position}.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* In order to specify the offset into the ByteBuffer at which
* the matrix is stored, use {@link #getTransposed(int, ByteBuffer)}, taking
* the absolute position as parameter.
*
*
* @see #getTransposed(int, ByteBuffer)
*
*
* @param buffer
* will receive the values of this matrix in column-major order at its current position
* will receive the values of this matrix in row-major order at its current position
* @return the passed in buffer
*/
ByteBuffer getTransposed(ByteBuffer buffer);

/**
* Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified
* Store this matrix in row-major order into the supplied {@link ByteBuffer} starting at the specified
* absolute buffer position/index.
* <p>
* This method will not increment the position of the given ByteBuffer.
*
*
* @param index
* the absolute position into the ByteBuffer
* @param buffer
* will receive the values of this matrix in column-major order
* will receive the values of this matrix in row-major order
* @return the passed in buffer
*/
ByteBuffer getTransposed(int index, ByteBuffer buffer);

/**
* Store this matrix in row-major order into the supplied {@link FloatBuffer} at the current
* buffer {@link FloatBuffer#position() position}.
* <p>
* This method will not increment the position of the given FloatBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given FloatBuffer.
* <p>
* In order to specify the offset into the FloatBuffer at which
* the matrix is stored, use {@link #getTransposed(int, FloatBuffer)}, taking
* the absolute position as parameter.
*
* @see #getTransposed(int, FloatBuffer)
*
* @param buffer
* will receive the values of this matrix in row-major order at its current position
* @return the passed in buffer
*/
FloatBuffer getTransposed(FloatBuffer buffer);

/**
* Store this matrix in row-major order into the supplied {@link FloatBuffer} starting at the specified
* absolute buffer position/index.
* <p>
* This method will not increment the position of the given FloatBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given FloatBuffer.
*
* @param index
* the absolute position into the FloatBuffer
* @param buffer
* will receive the values of this matrix in row-major order
* @return the passed in buffer
*/
FloatBuffer getTransposed(int index, FloatBuffer buffer);

/**
* Store this matrix as float values in row-major order into the supplied {@link ByteBuffer} at the current
* buffer {@link ByteBuffer#position() position}.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given FloatBuffer.
* <p>
* In order to specify the offset into the ByteBuffer at which
* the matrix is stored, use {@link #getTransposedFloats(int, ByteBuffer)}, taking
* the absolute position as parameter.
*
* @see #getTransposedFloats(int, ByteBuffer)
*
* @param buffer
* will receive the values of this matrix as float values in row-major order at its current position
* @return the passed in buffer
*/
ByteBuffer getTransposedFloats(ByteBuffer buffer);

/**
* Store this matrix in row-major order into the supplied {@link ByteBuffer} starting at the specified
* absolute buffer position/index.
* <p>
* This method will not increment the position of the given ByteBuffer.
* <p>
* Please note that due to this matrix storing double values those values will potentially
* lose precision when they are converted to float values before being put into the given FloatBuffer.
*
* @param index
* the absolute position into the ByteBuffer
* @param buffer
* will receive the values of this matrix as float values in row-major order
* @return the passed in buffer
*/
ByteBuffer getTransposedFloats(int index, ByteBuffer buffer);
//#endif

//#ifdef __HAS_UNSAFE__
Expand Down
36 changes: 36 additions & 0 deletions src/org/joml/Matrix3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,42 @@ public ByteBuffer getFloats(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putf(this, index, buffer);
return buffer;
}

public DoubleBuffer getTransposed(DoubleBuffer buffer) {
return getTransposed(buffer.position(), buffer);
}

public DoubleBuffer getTransposed(int index, DoubleBuffer buffer) {
MemUtil.INSTANCE.putTransposed(this, index, buffer);
return buffer;
}

public FloatBuffer getTransposed(FloatBuffer buffer) {
return getTransposed(buffer.position(), buffer);
}

public FloatBuffer getTransposed(int index, FloatBuffer buffer) {
MemUtil.INSTANCE.putfTransposed(this, index, buffer);
return buffer;
}

public ByteBuffer getTransposed(ByteBuffer buffer) {
return getTransposed(buffer.position(), buffer);
}

public ByteBuffer getTransposed(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putTransposed(this, index, buffer);
return buffer;
}

public ByteBuffer getTransposedFloats(ByteBuffer buffer) {
return getTransposedFloats(buffer.position(), buffer);
}

public ByteBuffer getTransposedFloats(int index, ByteBuffer buffer) {
MemUtil.INSTANCE.putfTransposed(this, index, buffer);
return buffer;
}
//#endif

//#ifdef __HAS_UNSAFE__
Expand Down

0 comments on commit d99f4f0

Please sign in to comment.