[glass] Fix Drive widget handling of negative rotation (#3739)

This would crash in debug mode due to an imgui assertion in PathArcTo.
This commit is contained in:
Peter Johnson
2021-11-27 10:58:45 -08:00
committed by GitHub
parent 7f401ae895
commit f6159ee1a2

View File

@@ -90,11 +90,20 @@ void glass::DisplayDrive(DriveModel* m) {
double a1 = 0.0;
double a2 = wpi::numbers::pi / 2 * rotation;
draw->PathArcTo(center, radius, a1, a2, 20);
draw->PathStroke(color, false);
draw->PathArcTo(center, radius, a1 + wpi::numbers::pi,
a2 + wpi::numbers::pi, 20);
draw->PathStroke(color, false);
// PathArcTo requires a_min <= a_max, and rotation can be negative
if (a1 > a2) {
draw->PathArcTo(center, radius, a2, a1, 20);
draw->PathStroke(color, false);
draw->PathArcTo(center, radius, a2 + wpi::numbers::pi,
a1 + wpi::numbers::pi, 20);
draw->PathStroke(color, false);
} else {
draw->PathArcTo(center, radius, a1, a2, 20);
draw->PathStroke(color, false);
draw->PathArcTo(center, radius, a1 + wpi::numbers::pi,
a2 + wpi::numbers::pi, 20);
draw->PathStroke(color, false);
}
double adder = rotation < 0 ? wpi::numbers::pi : 0;