Skip to content

Commit

Permalink
Make TreeUtils.getMinTimepoint() return 0 in case of an empty model.
Browse files Browse the repository at this point in the history
* It was before Integer.MAX_VALUE, which was confusing to be a min time point
* Update javadocs and unit test accordingly
  • Loading branch information
stefanhahmann committed Jun 7, 2024
1 parent ef02997 commit b93f8b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/mastodon/util/TreeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,16 @@ private static < V extends Vertex<E>, 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.
* <br>
* 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() );
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/mastodon/util/TreeUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b93f8b2

Please sign in to comment.