Skip to content

Commit

Permalink
Add AprilTagFieldLayout.loadStandardField()
Browse files Browse the repository at this point in the history
Also change AprilTagFields.loadFromResource() to use the new method
  • Loading branch information
KangarooKoala committed Jan 31, 2024
1 parent 90bb6cf commit a686fa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -221,6 +222,22 @@ public void serialize(Path path) throws IOException {
new ObjectMapper().writeValue(path.toFile(), this);
}

/**
* Get a standard {@link AprilTagFieldLayout}.
*
* @param field The loadable AprilTag field layout.
* @return AprilTagFieldLayout of the field.
* @throws UncheckedIOException If the layout does not exist.
*/
public static AprilTagFieldLayout loadStandardField(AprilTagFields field) {
try {
return loadFromResource(field.m_resourceFile);
} catch (IOException e) {
throw new UncheckedIOException(
"Could not load AprilTagFieldLayout from " + field.m_resourceFile, e);
}
}

/**
* Deserializes a field layout from a resource within a internal jar file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package edu.wpi.first.apriltag;

import java.io.IOException;
import java.io.UncheckedIOException;

/** Loadable AprilTag field layouts. */
Expand Down Expand Up @@ -36,11 +35,6 @@ public enum AprilTagFields {
* @throws UncheckedIOException If the layout does not exist
*/
public AprilTagFieldLayout loadAprilTagLayoutField() {
try {
return AprilTagFieldLayout.loadFromResource(m_resourceFile);
} catch (IOException e) {
throw new UncheckedIOException(
"Could not load AprilTagFieldLayout from " + m_resourceFile, e);
}
return AprilTagFieldLayout.loadStandardField(this);
}
}

0 comments on commit a686fa0

Please sign in to comment.