Skip to content

Commit

Permalink
Rename percentage to tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Apr 17, 2024
1 parent 062aad1 commit ea2a181
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace behaviour_tree::node::custom::condition
class SucceedOnAverageColour final : public CustomNode
{
public:
SucceedOnAverageColour(const std::string &name, const std::string hex_colour, const double percentage) : CustomNode(name),
SucceedOnAverageColour(const std::string &name, const std::string hex_colour, const double tolerance) : CustomNode(name),
hex_colour(hex_colour),
percentage(percentage)
tolerance(tolerance)
{
}

Expand All @@ -42,16 +42,16 @@ namespace behaviour_tree::node::custom::condition
return tl::unexpected(fmt::format(R"(Invalid hex_colour: '{}' | Condition:SucceedOnAverageColour:['{}',{}])", hex_colour, name_attribute, index));
}
}
const double percentage = node.attribute("percentage").as_double();
if (percentage < 0 || percentage > 100)
const double tolerance = node.attribute("tolerance").as_double();
if (tolerance < 0 || tolerance > 100)
{
return tl::unexpected(fmt::format(R"(Invalid percentage: '{}' | Condition:SucceedOnAverageColour:['{}',{}])", percentage, name_attribute, index));
return tl::unexpected(fmt::format(R"(Invalid tolerance: '{}' | Condition:SucceedOnAverageColour:['{}',{}])", tolerance, name_attribute, index));
}
return std::make_shared<SucceedOnAverageColour>(
SucceedOnAverageColour(
name_attribute,
hex_colour,
percentage));
tolerance));
}

const Status run(const int tick_count, std::shared_ptr<Context> context) final override
Expand All @@ -74,7 +74,7 @@ namespace behaviour_tree::node::custom::condition
std::string avg_color_hex = fmt::format("#{:02x}{:02x}{:02x}", static_cast<int>(avg_color[2]), static_cast<int>(avg_color[1]), static_cast<int>(avg_color[0]));

int color_diff = calculateColorDifference(avg_color_hex, this->hex_colour);
int max_color_diff = calculateMaxColorDifference(this->percentage);
int max_color_diff = calculateMaxColorDifference(this->tolerance);

if (color_diff <= max_color_diff)
{
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace behaviour_tree::node::custom::condition
int max_color_diff = static_cast<int>(cv::norm(black, white));

// Now, we scale the maximum color difference based on the percentage
return static_cast<int>(max_color_diff * (this->percentage / 100.0));
return static_cast<int>(max_color_diff * (percentage / 100.0));
}
#endif // !BEHAVIOUR_TREE_DISABLE_RUNss

Expand All @@ -135,23 +135,23 @@ namespace behaviour_tree::node::custom::condition
return this->hex_colour;
}

const double getPercentage() const
const double getTolerance() const
{
return this->percentage;
return this->tolerance;
}

const std::string toString() const final override
{
const std::string &name = this->getName();
if (name != "")
return fmt::format(R"(<Condition:SucceedOnAverageColour name='{}' hex_colour='{}' percentage='{}'/>)", name, this->getHexColour(), this->getPercentage());
return fmt::format(R"(<Condition:SucceedOnAverageColour name='{}' hex_colour='{}' tolerance='{}'/>)", name, this->getHexColour(), this->getTolerance());
else
return fmt::format(R"(<Condition:SucceedOnAverageColour hex_colour='{}' percentage='{}'/>)", this->getHexColour(), this->getPercentage());
return fmt::format(R"(<Condition:SucceedOnAverageColour hex_colour='{}' tolerance='{}'/>)", this->getHexColour(), this->getTolerance());
}

private:
const std::string hex_colour;
const double percentage;
const double tolerance;
};
}

Expand Down

0 comments on commit ea2a181

Please sign in to comment.