Make various refactors to clean up codebase#1830
Merged
mcm001 merged 21 commits intoPhotonVision:mainfrom Apr 20, 2025
Merged
Conversation
Contributor
|
Do we wanna hold off until champs on this one? |
Member
Author
|
I’d be fine with that. I think there are other places I could do refactors as well. |
mcm001
reviewed
Mar 21, 2025
photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java
Show resolved
Hide resolved
mcm001
reviewed
Mar 26, 2025
photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java
Show resolved
Hide resolved
mcm001
reviewed
Mar 26, 2025
photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagPoseEstimatorPipe.java
Show resolved
Hide resolved
Matt says this was for mmal, and we use libcamera now, so this is unnecessary now. Also, the filtering logic that used blacklistedResIndices was completely broken.
…efinitely never modified
a5f8e63 to
76f6528
Compare
In places like pipelines or DataSocketHandler, objects were being instantiated and assigned to a variable, but were then passed into a method, never to be used again. For pipelines especially, that style of code wasn't always consistently used, and other pipelines skipped assignment and instantiated objects in the method call. Make everything consistent by always instantiating in the method call. GenericUSBCameraSettables also had an unnecessary assignment, and that was cleaned up too for readability.
6aba6f7 to
7175275
Compare
samfreund
previously approved these changes
Apr 11, 2025
Member
|
Take a peek at these guys, they don't seem to be doing anything |
Contributor
|
Tempted to merge this as a not-squash to preserve history and make bisecting easier |
Member
Sure. Imma put another blocking review so that we remember. |
This allowed us to drop a few Apache Commons dependencies, which is good for reducing JAR size and the number of things we need to pull in.
printTestResults was duplicated a lot, so it has been moved to TestUtils for maintainability.
QuirkyCamera was refactored to use EnumMap, since that seems to be more efficient. This also enables more concise copying of QuirkyCamera in getQuirkyCamera by just passing in the Map of the QuirkyCamera. Also, putAll was used instead of manually copying quirks in updateQuirks for conciseness.
Member
Author
|
Cleaned up history for a rebase merge so some of the commits have nice summaries and descriptions. |
mcm001
approved these changes
Apr 20, 2025
Contributor
|
FUCK IT EINSTEIN IS OVER WE BALL LETS GET THIS BREAD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Code that was unused has been removed to tidy up the codebase.
The creation of arrays was also tidied up, using initializers when possible and just
new Type[0]for zero length arrays.Text blocks were used to increase readability.
VideoSimUtil was refactored to reduce copies when generating 36h11 tag images.
FileSaveFrameConsumer was refactored to let Java handle paths instead of us doing it manually.
I switched to WPILib's Pair class instead of the Apache Commons Pair class. This allowed us to drop a few Apache Commons dependencies, which is good for reducing JAR size and the number of things we need to pull in.
#1556 added a UiVmmState class, but it appears to have been unused, so removing it to reduce confusion.
printTestUtilswas a common function duplicated across several tests, so they were consolidated into TestUtils for maintainability.blacklistedResIndiceswas removed from HardwareConfig because the filtering logic that used it was broken. Matt says it was something from the mmal days, but we use libcamera now, so we just don't need it.collect(Collectors.toList())for Streams was replaced withtoList()when the resulting List wasn't modified. It's more concise and possibly a little bit more performant.Math.hypotwas used in place ofMath.sqrt(a^2 + b^2)for conciseness.Several classes were made into records to reduce boilerplate and increase readability.
In a few places, especially in pipelines, objects were being assigned to a variable, only to be passed to a method and never used again in the same scope. Worse, this wasn't consistent, and assignment was just skipped entirely sometimes. Now, the code more consistently creates the object directly in the method call, skipping the unnecessary assignment.
switch case and instanceof use was refactored to reduce unnecessary operations like casting if statements and casts and improve code clarity.
JUnit assertions were not always statically imported, so I statically imported all of them.
A Timer is now used to calculate FPS instead of handrolling the time tracking for readability and maintainability.
Whatever CameraServer bug caused #123 seems to have been fixed, so CameraServer is now used directly instead of duplicating its code.
QuirkyCamera was refactored to use EnumMap, since that seems to be more efficient. This also enables more concise copying of QuirkyCamera in
getQuirkyCameraby just passing in the Map of the QuirkyCamera. Also,putAllwas used instead of manually copying quirks inupdateQuirksfor conciseness.There's some other miscellanous clean up in
Miscellanous clean up, which is mostly either removing unnecessary code or making operations more efficient.Meta
Merge checklist: