Skip to content

Commit

Permalink
Change Matrix4f.set3x3(Matrix4f) to Matrix4f.set3x3(Matrix4fc) (#344
Browse files Browse the repository at this point in the history
)

All of the underlying `MemUtil` functions for copying rely on
the read-only interface methods. These now specify the read-only class
in their parameters. This should allow for greater flexibility in using
these memory helpers.
  • Loading branch information
NicBOMB committed Jun 22, 2024
1 parent 933eb41 commit 0f66b42
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 248 deletions.
51 changes: 8 additions & 43 deletions src/main/java/org/joml/Matrix2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ public Matrix2d() {
* the {@link Matrix2dc} to copy the values from
*/
public Matrix2d(Matrix2dc mat) {
if (mat instanceof Matrix2d) {
MemUtil.INSTANCE.copy((Matrix2d) mat, this);
} else {
setMatrix2dc(mat);
if (mat != this) {
MemUtil.INSTANCE.copy(mat, this);
}
}

Expand All @@ -93,11 +91,7 @@ public Matrix2d(Matrix2fc mat) {
* the {@link Matrix3dc} to copy the values from
*/
public Matrix2d(Matrix3dc mat) {
if (mat instanceof Matrix3d) {
MemUtil.INSTANCE.copy((Matrix3d) mat, this);
} else {
setMatrix3dc(mat);
}
MemUtil.INSTANCE.copy(mat, this);
}

/**
Expand Down Expand Up @@ -277,21 +271,12 @@ Matrix2d _m11(double m11) {
* @return this
*/
public Matrix2d set(Matrix2dc m) {
if (m == this)
return this;
else if (m instanceof Matrix2d) {
MemUtil.INSTANCE.copy((Matrix2d) m, this);
} else {
setMatrix2dc(m);
if (m != this)
{
MemUtil.INSTANCE.copy(m, this);
}
return this;
}
private void setMatrix2dc(Matrix2dc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Set the elements of this matrix to the ones in <code>m</code>.
Expand All @@ -316,19 +301,9 @@ public Matrix2d set(Matrix2fc m) {
* @return this
*/
public Matrix2d set(Matrix3x2dc m) {
if (m instanceof Matrix3x2d) {
MemUtil.INSTANCE.copy((Matrix3x2d) m, this);
} else {
setMatrix3x2dc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix3x2dc(Matrix3x2dc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Set the elements of this matrix to the left 2x2 submatrix of <code>m</code>.
Expand All @@ -353,19 +328,9 @@ public Matrix2d set(Matrix3x2fc m) {
* @return this
*/
public Matrix2d set(Matrix3dc m) {
if (m instanceof Matrix3d) {
MemUtil.INSTANCE.copy((Matrix3d) m, this);
} else {
setMatrix3dc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix3dc(Matrix3dc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Set the elements of this matrix to the upper left 2x2 of the given {@link Matrix3dc}.
Expand Down
44 changes: 7 additions & 37 deletions src/main/java/org/joml/Matrix2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ public Matrix2f() {
* the {@link Matrix2fc} to copy the values from
*/
public Matrix2f(Matrix2fc mat) {
if (mat instanceof Matrix2f) {
MemUtil.INSTANCE.copy((Matrix2f) mat, this);
} else {
setMatrix2fc(mat);
if (mat != this) {
MemUtil.INSTANCE.copy(mat, this);
}
}

Expand All @@ -79,11 +77,7 @@ public Matrix2f(Matrix2fc mat) {
* the {@link Matrix3fc} to copy the values from
*/
public Matrix2f(Matrix3fc mat) {
if (mat instanceof Matrix3f) {
MemUtil.INSTANCE.copy((Matrix3f) mat, this);
} else {
setMatrix3fc(mat);
}
MemUtil.INSTANCE.copy(mat, this);
}

/**
Expand Down Expand Up @@ -250,12 +244,8 @@ Matrix2f _m11(float m11) {
* @return this
*/
public Matrix2f set(Matrix2fc m) {
if (m == this)
return this;
else if (m instanceof Matrix2f) {
MemUtil.INSTANCE.copy((Matrix2f) m, this);
} else {
setMatrix2fc(m);
if (m != this) {
MemUtil.INSTANCE.copy(m, this);
}
return this;
}
Expand All @@ -274,19 +264,9 @@ private void setMatrix2fc(Matrix2fc mat) {
* @return this
*/
public Matrix2f set(Matrix3x2fc m) {
if (m instanceof Matrix3x2f) {
MemUtil.INSTANCE.copy((Matrix3x2f) m, this);
} else {
setMatrix3x2fc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix3x2fc(Matrix3x2fc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Set the elements of this matrix to the upper left 2x2 of the given {@link Matrix3fc}.
Expand All @@ -296,19 +276,9 @@ private void setMatrix3x2fc(Matrix3x2fc mat) {
* @return this
*/
public Matrix2f set(Matrix3fc m) {
if (m instanceof Matrix3f) {
MemUtil.INSTANCE.copy((Matrix3f) m, this);
} else {
setMatrix3fc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix3fc(Matrix3fc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Multiply this matrix by the supplied <code>right</code> matrix.
Expand Down
40 changes: 6 additions & 34 deletions src/main/java/org/joml/Matrix3x2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public Matrix3x2d() {
* the {@link Matrix2dc}
*/
public Matrix3x2d(Matrix2dc mat) {
if (mat instanceof Matrix2d) {
MemUtil.INSTANCE.copy((Matrix2d) mat, this);
} else {
setMatrix2dc(mat);
}
MemUtil.INSTANCE.copy(mat, this);
}

/**
Expand All @@ -96,10 +92,8 @@ public Matrix3x2d(Matrix2fc mat) {
* the {@link Matrix3x2dc} to copy the values from
*/
public Matrix3x2d(Matrix3x2dc mat) {
if (mat instanceof Matrix3x2d) {
MemUtil.INSTANCE.copy((Matrix3x2d) mat, this);
} else {
setMatrix3x2dc(mat);
if (mat != this) {
MemUtil.INSTANCE.copy(mat, this);
}
}

Expand Down Expand Up @@ -242,23 +236,11 @@ Matrix3x2d _m21(double m21) {
* @return this
*/
public Matrix3x2d set(Matrix3x2dc m) {
if (m == this)
return this;
else if (m instanceof Matrix3x2d) {
MemUtil.INSTANCE.copy((Matrix3x2d) m, this);
} else {
setMatrix3x2dc(m);
if (m != this) {
MemUtil.INSTANCE.copy(m, this);
}
return this;
}
private void setMatrix3x2dc(Matrix3x2dc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
m20 = mat.m20();
m21 = mat.m21();
}

/**
* Set the left 2x2 submatrix of this {@link Matrix3x2d} to the given {@link Matrix2dc} and don't change the other elements.
Expand All @@ -268,19 +250,9 @@ private void setMatrix3x2dc(Matrix3x2dc mat) {
* @return this
*/
public Matrix3x2d set(Matrix2dc m) {
if (m instanceof Matrix2d) {
MemUtil.INSTANCE.copy((Matrix2d) m, this);
} else {
setMatrix2dc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix2dc(Matrix2dc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Set the left 2x2 submatrix of this {@link Matrix3x2d} to the given {@link Matrix2fc} and don't change the other elements.
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/org/joml/Matrix3x2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ public Matrix3x2f() {
* the {@link Matrix3x2fc} to copy the values from
*/
public Matrix3x2f(Matrix3x2fc mat) {
if (mat instanceof Matrix3x2f) {
MemUtil.INSTANCE.copy((Matrix3x2f) mat, this);
} else {
setMatrix3x2fc(mat);
if (mat != this) {
MemUtil.INSTANCE.copy(mat, this);
}
}

Expand All @@ -81,11 +79,7 @@ public Matrix3x2f(Matrix3x2fc mat) {
* the {@link Matrix2fc}
*/
public Matrix3x2f(Matrix2fc mat) {
if (mat instanceof Matrix2f) {
MemUtil.INSTANCE.copy((Matrix2f) mat, this);
} else {
setMatrix2fc(mat);
}
MemUtil.INSTANCE.copy(mat, this);
}

/**
Expand Down Expand Up @@ -227,12 +221,8 @@ Matrix3x2f _m21(float m21) {
* @return this
*/
public Matrix3x2f set(Matrix3x2fc m) {
if (m == this)
return this;
else if (m instanceof Matrix3x2f) {
MemUtil.INSTANCE.copy((Matrix3x2f) m, this);
} else {
setMatrix3x2fc(m);
if (m != this) {
MemUtil.INSTANCE.copy(m, this);
}
return this;
}
Expand All @@ -253,19 +243,9 @@ private void setMatrix3x2fc(Matrix3x2fc mat) {
* @return this
*/
public Matrix3x2f set(Matrix2fc m) {
if (m instanceof Matrix2f) {
MemUtil.INSTANCE.copy((Matrix2f) m, this);
} else {
setMatrix2fc(m);
}
MemUtil.INSTANCE.copy(m, this);
return this;
}
private void setMatrix2fc(Matrix2fc mat) {
m00 = mat.m00();
m01 = mat.m01();
m10 = mat.m10();
m11 = mat.m11();
}

/**
* Multiply this matrix by the supplied <code>right</code> matrix by assuming a third row in
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/joml/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -1075,16 +1075,16 @@ public Matrix4f set(Quaterniondc q) {
}

/**
* Set the upper left 3x3 submatrix of this {@link Matrix4f} to that of the given {@link Matrix4f}
* Set the upper left 3x3 submatrix of this {@link Matrix4f} to that of the given {@link Matrix4fc}
* and don't change the other elements.
*
* @param mat
* the {@link Matrix4f}
* the {@link Matrix4fc}
* @return this
*/
public Matrix4f set3x3(Matrix4f mat) {
public Matrix4f set3x3(Matrix4fc mat) {
MemUtil.INSTANCE.copy3x3(mat, this);
return _properties(properties & mat.properties & ~(PROPERTY_PERSPECTIVE));
return _properties(properties & mat.properties() & ~(PROPERTY_PERSPECTIVE));
}


Expand Down Expand Up @@ -1116,16 +1116,16 @@ public Matrix4f set4x3(Matrix4x3fc mat) {
}

/**
* Set the upper 4x3 submatrix of this {@link Matrix4f} to the upper 4x3 submatrix of the given {@link Matrix4f}
* Set the upper 4x3 submatrix of this {@link Matrix4f} to the upper 4x3 submatrix of the given {@link Matrix4fc}
* and don't change the other elements.
*
* @param mat
* the {@link Matrix4f}
* the {@link Matrix4fc}
* @return this
*/
public Matrix4f set4x3(Matrix4f mat) {
public Matrix4f set4x3(Matrix4fc mat) {
MemUtil.INSTANCE.copy4x3(mat, this);
return _properties(properties & mat.properties & ~(PROPERTY_PERSPECTIVE));
return _properties(properties & mat.properties() & ~(PROPERTY_PERSPECTIVE));
}

/**
Expand Down Expand Up @@ -12731,10 +12731,10 @@ public Matrix4f setRowColumn(int row, int column, float value) {
* <p>
* Please note that, if <code>this</code> is an orthogonal matrix or a matrix whose columns are orthogonal vectors,
* then this method <i>need not</i> be invoked, since in that case <code>this</code> itself is its normal matrix.
* In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix
* In that case, use {@link #set3x3(Matrix4fc)} to set a given Matrix4f to only the upper left 3x3 submatrix
* of this matrix.
*
* @see #set3x3(Matrix4f)
* @see #set3x3(Matrix4fc)
*
* @return this
*/
Expand All @@ -12751,10 +12751,10 @@ public Matrix4f normal() {
* <p>
* Please note that, if <code>this</code> is an orthogonal matrix or a matrix whose columns are orthogonal vectors,
* then this method <i>need not</i> be invoked, since in that case <code>this</code> itself is its normal matrix.
* In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix
* In that case, use {@link #set3x3(Matrix4fc)} to set a given Matrix4f to only the upper left 3x3 submatrix
* of this matrix.
*
* @see #set3x3(Matrix4f)
* @see #set3x3(Matrix4fc)
*
* @param dest
* will hold the result
Expand Down
Loading

0 comments on commit 0f66b42

Please sign in to comment.