diff --git a/src/main/java/org/mastodon/util/TreeUtils.java b/src/main/java/org/mastodon/util/TreeUtils.java index b1c6ae44b..14149a5ac 100644 --- a/src/main/java/org/mastodon/util/TreeUtils.java +++ b/src/main/java/org/mastodon/util/TreeUtils.java @@ -232,12 +232,16 @@ private static < V extends Vertex, E extends Edge< V > > RefSet< V > filterRo } /** - * Gets the minimum timepoint in the given {@link Model} at which at least one {@link Spot} exists in the Model. + * Gets the minimum time point in the given {@link Model} at which at least one {@link Spot} exists in the Model. + *
+ * If the model is empty, returns 0. * @param model the {@link Model} * @return the timepoint */ public static int getMinTimepoint( final Model model ) { + if ( model.getGraph().vertices().isEmpty() ) + return 0; int minTimepoint = Integer.MAX_VALUE; for ( final Spot spot : model.getGraph().vertices() ) minTimepoint = Math.min( minTimepoint, spot.getTimepoint() ); diff --git a/src/test/java/org/mastodon/util/TreeUtilsTest.java b/src/test/java/org/mastodon/util/TreeUtilsTest.java index fbaf9df3c..aefbdec85 100644 --- a/src/test/java/org/mastodon/util/TreeUtilsTest.java +++ b/src/test/java/org/mastodon/util/TreeUtilsTest.java @@ -41,6 +41,7 @@ import org.mastodon.collection.RefSet; import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph1; import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph2; +import org.mastodon.mamut.model.Model; import org.mastodon.mamut.model.ModelGraph; import org.mastodon.mamut.model.Spot; @@ -182,7 +183,7 @@ public void testGetMinTimepoint() { assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph1().getModel() ) ); assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph2().getModel() ) ); - + assertEquals( 0, TreeUtils.getMinTimepoint( new Model() ) ); } @Test