mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-23 01:21:40 +00:00
Remove hasTargets member variable and fix docs warnings (#283)
hasTargets is redundant because the same information can be obtained by checking the size of the targets array.
This commit is contained in:
@@ -21,13 +21,10 @@ namespace photonlib {
|
||||
PhotonPipelineResult::PhotonPipelineResult(
|
||||
units::second_t latency, wpi::ArrayRef<PhotonTrackedTarget> targets)
|
||||
: latency(latency),
|
||||
targets(targets.data(), targets.data() + targets.size()) {
|
||||
hasTargets = targets.size() != 0;
|
||||
}
|
||||
targets(targets.data(), targets.data() + targets.size()) {}
|
||||
|
||||
bool PhotonPipelineResult::operator==(const PhotonPipelineResult& other) const {
|
||||
return latency == other.latency && hasTargets == other.hasTargets &&
|
||||
targets == other.targets;
|
||||
return latency == other.latency && targets == other.targets;
|
||||
}
|
||||
|
||||
bool PhotonPipelineResult::operator!=(const PhotonPipelineResult& other) const {
|
||||
@@ -35,8 +32,8 @@ bool PhotonPipelineResult::operator!=(const PhotonPipelineResult& other) const {
|
||||
}
|
||||
|
||||
Packet& operator<<(Packet& packet, const PhotonPipelineResult& result) {
|
||||
// Encode latency, existence of targets, and number of targets.
|
||||
packet << result.latency.to<double>() * 1000 << result.hasTargets
|
||||
// Encode latency and number of targets.
|
||||
packet << result.latency.to<double>() * 1000
|
||||
<< static_cast<int8_t>(result.targets.size());
|
||||
|
||||
// Encode the information of each target.
|
||||
@@ -50,7 +47,7 @@ Packet& operator>>(Packet& packet, PhotonPipelineResult& result) {
|
||||
// Decode latency, existence of targets, and number of targets.
|
||||
int8_t targetCount = 0;
|
||||
double latencyMillis = 0;
|
||||
packet >> latencyMillis >> result.hasTargets >> targetCount;
|
||||
packet >> latencyMillis >> targetCount;
|
||||
result.latency = units::second_t(latencyMillis / 1000.0);
|
||||
|
||||
result.targets.clear();
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "photonlib/PhotonPipelineResult.h"
|
||||
|
||||
@@ -118,9 +119,11 @@ class PhotonCamera {
|
||||
* This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should
|
||||
* be used instead.
|
||||
* @deprecated This method should be replaced with {@link
|
||||
* PhotonPipelineResult#hasTargets()}
|
||||
* PhotonPipelineResult#HasTargets()}
|
||||
* @return Whether the latest target result has targets.
|
||||
*/
|
||||
WPI_DEPRECATED(
|
||||
"This method should be replaced with PhotonPipelineResult::HasTargets()")
|
||||
bool HasTargets() const { return GetLatestResult().HasTargets(); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -57,12 +57,12 @@ class PhotonPipelineResult {
|
||||
if (!HasTargets() && !HAS_WARNED) {
|
||||
::frc::DriverStation::ReportError(
|
||||
"This PhotonPipelineResult object has no targets associated with it! "
|
||||
"Please check hasTargets() before calling this method. For more "
|
||||
"Please check HasTargets() before calling this method. For more "
|
||||
"information, please review the PhotonLib documentation at "
|
||||
"http://docs.photonvision.org");
|
||||
HAS_WARNED = true;
|
||||
}
|
||||
return hasTargets ? targets[0] : PhotonTrackedTarget();
|
||||
return HasTargets() ? targets[0] : PhotonTrackedTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ class PhotonPipelineResult {
|
||||
* Returns whether the pipeline has targets.
|
||||
* @return Whether the pipeline has targets.
|
||||
*/
|
||||
bool HasTargets() const { return hasTargets; }
|
||||
bool HasTargets() const { return targets.size() > 0; }
|
||||
|
||||
/**
|
||||
* Returns a reference to the vector of targets.
|
||||
@@ -93,7 +93,6 @@ class PhotonPipelineResult {
|
||||
|
||||
private:
|
||||
units::second_t latency = 0_s;
|
||||
bool hasTargets = false;
|
||||
wpi::SmallVector<PhotonTrackedTarget, 10> targets;
|
||||
inline static bool HAS_WARNED = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user