Permalink
Browse files

Add tests for Line

  • Loading branch information...
awalter17 committed Jan 30, 2017
1 parent 1d9c705 commit 3e9d5823ac3a277b6a864e01adcf6603d089f5f1
Showing with 63 additions and 0 deletions.
  1. +63 −0 src/test/java/net/imglib2/roi/geometric/GeometricShapeTest.java
@@ -935,6 +935,69 @@ public void testConsistencyPolygon2DHyperRectangle()
assertEquals( count, 24 );
}
@Test
public void testLine()
{
final Line l = GeomRegions.line( new double[] { 1, 3 }, new double[] { 6, 0 } );
final RealRandomAccess< BoolType > ra = l.realRandomAccess();
assertEquals( l.numDimensions(), 2 );
// Check interval boundaries
assertEquals( l.realMin( 0 ), 1, 0 );
assertEquals( l.realMin( 1 ), 0, 0 );
assertEquals( l.realMax( 0 ), 6, 0 );
assertEquals( l.realMax( 1 ), 3, 0 );
// On line segment
ra.setPosition( new double[] { 4.5, 0.9 } );
assertTrue( ra.get().get() );
ra.setPosition( new double[] { 2, 2.4 } );
assertTrue( ra.get().get() );
// On line, but not within interval
ra.setPosition( new double[] { 0, 3.6 } );
assertFalse( ra.get().get() );
ra.setPosition( new double[] { 9, -1.8 } );
assertFalse( ra.get().get() );
// Off line
ra.setPosition( new double[] { 1, 1 } );
assertFalse( ra.get().get() );
ra.setPosition( new double[] { 4.5, 1 } );
assertFalse( ra.get().get() );
// Check if endpoints on line
ra.setPosition( new double[] { 1, 3 } );
assertTrue( ra.get().get() );
ra.setPosition( new double[] { 6, 0 } );
assertTrue( ra.get().get() );
}
@Test
public void testHigherDimSpaceLine()
{
final Line l = GeomRegions.line( new double[] { 1, 1, 1, 1, 1 }, new double[] { 10, 10, 10, 10, 10 } );
final RealRandomAccess< BoolType > ra = l.realRandomAccess();
assertEquals( l.numDimensions(), 5 );
// On line
ra.setPosition( new double[] { 6, 6, 6, 6, 6 } );
assertTrue( ra.get().get() );
// Off line
ra.setPosition( new double[] { 0, 0, 0, 0, 0 } );
assertFalse( ra.get().get() );
ra.setPosition( new double[] { 2, 2, 2.0001, 2, 2 } );
assertFalse( ra.get().get() );
}
public static void main( final String... args ) throws IOException
{
// new GeometricShapeTest().testHyperEllipsoid();

0 comments on commit 3e9d582

Please sign in to comment.