Skip to content

Commit f0a58cf

Browse files
NicoKiaruclaude
authored andcommitted
test: add failing tests for axis-permutation misclassification
isExlusiveTranslation currently accepts matrices whose off-diagonal entries equal 1.0 (e.g. axis permutations), so simplifyAffineGet collapses them to a pure Translation and silently drops the permutation. Add tests pinning the expected behaviour: - isExlusiveTranslation must reject PERMUTATION2D/3D - simplifying a permutation must not yield a Translation* - simplifying a permutation must preserve the full matrix These fail against the current code and document the bug. Also ignore the IntelliJ /.idea/ directory. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e07e6d3 commit f0a58cf

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55

66
# Maven #
77
/target/
8+
9+
# IntelliJ IDEA #
10+
/.idea/

src/test/java/net/imglib2/realtransform/RealViewsSimplificationsTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ public class RealViewsSimplificationsTest
8585
0.0, 0.0, 0.0, 1.0, 10.5,
8686
}, 4 );
8787

88+
// Pure axis permutation (X <-> Y swap) plus translation. NOT a translation.
89+
private static final AffineGet PERMUTATION2D = create( new double[] {
90+
0.0, 1.0, 2.0,
91+
1.0, 0.0, 5.5
92+
}, 2 );
93+
94+
// Pure axis permutation (Y <-> Z swap) plus translation. NOT a translation.
95+
private static final AffineGet PERMUTATION3D = create( new double[] {
96+
1.0, 0.0, 0.0, 2.0,
97+
0.0, 0.0, 1.0, 5.5,
98+
0.0, 1.0, 0.0, 7.5
99+
}, 3 );
100+
88101
private static final AffineGet SCALE2D = create( new double[] {
89102
2.0, 0.0, 0.0,
90103
0.0, 1.0, 0.0
@@ -208,6 +221,35 @@ public void testExlusiveTranslation()
208221
Assert.assertFalse( RealViewsSimplifyUtils.isExlusiveTranslation( SCALE2D ) );
209222
Assert.assertFalse( RealViewsSimplifyUtils.isExlusiveTranslation( SCALE3D ) );
210223
Assert.assertFalse( RealViewsSimplifyUtils.isExlusiveTranslation( SCALE4D ) );
224+
225+
// An axis permutation is not a pure translation.
226+
Assert.assertFalse( RealViewsSimplifyUtils.isExlusiveTranslation( PERMUTATION2D ) );
227+
Assert.assertFalse( RealViewsSimplifyUtils.isExlusiveTranslation( PERMUTATION3D ) );
228+
}
229+
230+
@Test
231+
public void testSimplifyingPermutationIsNotTranslation()
232+
{
233+
// A permutation must not be collapsed to a Translation: that would silently
234+
// drop the axis swap. It should fall through to a generic affine.
235+
Assert.assertFalse( RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION2D ) instanceof Translation );
236+
Assert.assertFalse( RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION2D ) instanceof Translation2D );
237+
Assert.assertFalse( RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION3D ) instanceof Translation );
238+
Assert.assertFalse( RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION3D ) instanceof Translation3D );
239+
}
240+
241+
@Test
242+
public void testSimplifyingPermutationPreservesMatrix()
243+
{
244+
// Simplifying a permutation must preserve the full matrix, not just the
245+
// last (translation) column.
246+
final RealTransform simplified2D = RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION2D );
247+
Assert.assertArrayEquals( PERMUTATION2D.getRowPackedCopy(),
248+
( ( AffineGet ) simplified2D ).getRowPackedCopy(), 0.0 );
249+
250+
final RealTransform simplified3D = RealViewsSimplifyUtils.simplifyRealTransform( PERMUTATION3D );
251+
Assert.assertArrayEquals( PERMUTATION3D.getRowPackedCopy(),
252+
( ( AffineGet ) simplified3D ).getRowPackedCopy(), 0.0 );
211253
}
212254

213255
@Test

0 commit comments

Comments
 (0)