Skip to content

Commit 9fa00fd

Browse files
committed
Mat44Arg: add an isIdentity() method
1 parent ddea2a7 commit 9fa00fd

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/main/java/com/github/stephengold/joltjni/Mat44.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,20 @@ public boolean isEqual(Mat44Arg m2) {
453453
return result;
454454
}
455455

456+
/**
457+
* Test whether the current matrix is an identity matrix. The matrix is
458+
* unaffected.
459+
*
460+
* @return {@code true} if exactly equal, otherwise {@code false}
461+
*/
462+
@Override
463+
public boolean isIdentity() {
464+
long matrixVa = va();
465+
boolean result = isIdentity(matrixVa);
466+
467+
return result;
468+
}
469+
456470
/**
457471
* Multiply the current matrix by the argument. The current matrix is
458472
* unaffected.
@@ -635,6 +649,8 @@ native private static void getQuaternion(
635649

636650
native private static long inversedRotationTranslation(long currentVa);
637651

652+
native private static boolean isIdentity(long matrixVa);
653+
638654
native private static long multiply(long m1Va, long m2Va);
639655

640656
native private static long multiply3x3(long currentVa, long argVa);

src/main/java/com/github/stephengold/joltjni/readonly/Mat44Arg.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024 Stephen Gold
2+
Copyright (c) 2024-2025 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -101,6 +101,14 @@ public interface Mat44Arg extends ConstJoltPhysicsObject {
101101
*/
102102
boolean isEqual(Mat44Arg m2);
103103

104+
/**
105+
* Test whether the current matrix is an identity matrix. The matrix is
106+
* unaffected.
107+
*
108+
* @return {@code true} if equal, {@code false} if unequal
109+
*/
110+
boolean isIdentity();
111+
104112
/**
105113
* Multiply the current matrix by the specified matrix. The current matrix
106114
* is unaffected.

src/main/native/glue/m/Mat44.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_Mat44_inversedRotati
293293
return reinterpret_cast<jlong> (pResult);
294294
}
295295

296+
/*
297+
* Class: com_github_stephengold_joltjni_Mat44
298+
* Method: isIdentity
299+
* Signature: (J)Z
300+
*/
301+
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_Mat44_isIdentity
302+
(JNIEnv *, jclass, jlong matrixVa) {
303+
const Mat44 * const pMatrix = reinterpret_cast<Mat44 *> (matrixVa);
304+
const bool result = (*pMatrix == Mat44::sIdentity());
305+
return result;
306+
}
307+
296308
/*
297309
* Class: com_github_stephengold_joltjni_Mat44
298310
* Method: multiply

0 commit comments

Comments
 (0)