Commit b46e23d6 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[constraints][eval] provide labels for violations

parent 05f5d845
......@@ -72,11 +72,33 @@ struct ConstraintsEvaluation
Violation violation() const
{ return violation_; }
//! return the violation label
std::string violationLabel() const
{ return violationLabel(violation_); }
//! returns true if evaluation was
//! positive, i.e. no violation was detected
explicit operator bool() const
{ return violation_ == Violation::none; }
//! return a label for the given violation
static std::string violationLabel(Violation v)
if (v == Violation::none) return "no violation";
else if (v == Violation::distance)
return "minimum distance violation";
else if (v == Violation::intersectionAngle)
return "minimum intersection angle violation";
else if (v == Violation::intersectionMagnitude)
return "minimum intersection magnitude violation";
else if (v == Violation::intersectionDimension)
return "maximum intersection dimensionality violation";
else if (v == Violation::intersectionDistance)
return "minimum intersection distance violation";
throw std::runtime_error("Unsupported violation flag");
Violation violation_;
......@@ -148,8 +148,12 @@ void registerConstraints(py::module& module)
// define members of ConstraintsEvaluation
evalResult.def("violation", &Result::violation, "return the type of detected violation");
evalResult.def("__bool__", &Result::operator bool, "returns true if no violation was detected");
evalResult.def("violation", &Result::violation, "return the type of detected violation");
evalResult.def("violationLabel", py::overload_cast<>(&Result::violationLabel, py::const_),
"return a label for the type of detected violation");
evalResult.def("violationLabel", py::overload_cast<Result::Violation>(&Result::violationLabel),
"return a label for the given violation");
using Constraints = Detail::EntityNetworkConstraintsWrapper<ctype>;
py::class_<Constraints> cls(module, "_EntityNetworkConstraints");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment