Skip to content

Commit

Permalink
Update default path + use default constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 committed Feb 5, 2024
1 parent 101a934 commit b5c5d6a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 40 deletions.
15 changes: 5 additions & 10 deletions lib/path/pathplanner_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,16 @@ class PathPlannerPath {
rotationTargets = [],
eventMarkers = [],
reversed = false,
previewStartingState = null,
useDefaultConstraints = false {
previewStartingState = PreviewStartingState(),
useDefaultConstraints = true {
waypoints.addAll([
Waypoint(
anchor: const Point(2.0, 7.0),
nextControl: const Point(3.0, 6.5),
nextControl: const Point(3.0, 7.0),
),
Waypoint(
prevControl: const Point(4.0, 6.0),
anchor: const Point(5.0, 5.0),
nextControl: const Point(6.0, 4.0),
),
Waypoint(
prevControl: const Point(6.75, 2.5),
anchor: const Point(7.0, 1.0),
prevControl: const Point(3.0, 6.0),
anchor: const Point(4.0, 6.0),
),
]);

Expand Down
2 changes: 1 addition & 1 deletion test/widgets/editor/split_auto_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void main() {
];
testPath.eventMarkers = [
EventMarker(
waypointRelativePos: 1.5,
waypointRelativePos: 0.5,
command: SequentialCommandGroup(commands: []),
),
];
Expand Down
8 changes: 5 additions & 3 deletions test/widgets/editor/split_path_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() {
];
path.eventMarkers = [
EventMarker(
waypointRelativePos: 1.5,
waypointRelativePos: 0.5,
command: SequentialCommandGroup(commands: []),
name: 'm',
),
Expand Down Expand Up @@ -219,14 +219,14 @@ void main() {
await widgetTester.tapAt(tapLocation);
await widgetTester.pumpAndSettle();

expect(path.waypoints.length, 4);
expect(path.waypoints.length, 3);
expect(path.waypoints.last.anchor.x, closeTo(1.0, 0.05));
expect(path.waypoints.last.anchor.y, closeTo(1.0, 0.05));

undoStack.undo();
await widgetTester.pumpAndSettle();

expect(path.waypoints.length, 3);
expect(path.waypoints.length, 2);
});

testWidgets('drag waypoint', (widgetTester) async {
Expand Down Expand Up @@ -415,6 +415,7 @@ void main() {
await widgetTester.binding.setSurfaceSize(const Size(1280, 720));

path.waypointsExpanded = true;
path.addWaypoint(const Point(7.0, 4.0));

await widgetTester.pumpWidget(MaterialApp(
home: Scaffold(
Expand Down Expand Up @@ -449,6 +450,7 @@ void main() {
await widgetTester.binding.setSurfaceSize(const Size(1280, 720));

path.waypointsExpanded = true;
path.addWaypoint(const Point(7.0, 4.0));

await widgetTester.pumpWidget(MaterialApp(
home: Scaffold(
Expand Down
12 changes: 6 additions & 6 deletions test/widgets/editor/tree_widgets/constraint_zones_tree_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ void main() {
ConstraintsZone(
constraints: PathConstraints(),
minWaypointRelativePos: 0.2,
maxWaypointRelativePos: 1.8,
maxWaypointRelativePos: 0.7,
name: '0',
),
ConstraintsZone(
constraints: PathConstraints(),
minWaypointRelativePos: 1.2,
maxWaypointRelativePos: 1.8,
minWaypointRelativePos: 0.3,
maxWaypointRelativePos: 0.8,
name: '1',
),
];
Expand Down Expand Up @@ -349,7 +349,7 @@ void main() {
await widgetTester.pump();

expect(pathChanged, true);
expect(path.constraintZones[0].minWaypointRelativePos, 1.0);
expect(path.constraintZones[0].minWaypointRelativePos, 0.5);

undoStack.undo();
await widgetTester.pump();
Expand Down Expand Up @@ -380,12 +380,12 @@ void main() {
await widgetTester.pump();

expect(pathChanged, true);
expect(path.constraintZones[0].maxWaypointRelativePos, 1.0);
expect(path.constraintZones[0].maxWaypointRelativePos, 0.5);

undoStack.undo();
await widgetTester.pump();

expect(path.constraintZones[0].maxWaypointRelativePos, 1.8);
expect(path.constraintZones[0].maxWaypointRelativePos, 0.7);
});

testWidgets('Delete zone button', (widgetTester) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void main() {
await widgetTester.pump();

expect(pathChanged, true);
expect(path.eventMarkers[0].waypointRelativePos, 1.0);
expect(path.eventMarkers[0].waypointRelativePos, 0.5);

undoStack.undo();
await widgetTester.pump();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
pathDir: '/paths',
fs: MemoryFileSystem(),
);
path.useDefaultConstraints = false;
path.globalConstraintsExpanded = true;
path.globalConstraints = PathConstraints(
maxVelocity: 1.0,
Expand Down
12 changes: 6 additions & 6 deletions test/widgets/editor/tree_widgets/rotation_targets_tree_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ void main() {
);
path.rotationTargets = [
RotationTarget(
waypointRelativePos: 0.5,
waypointRelativePos: 0.2,
rotationDegrees: 0.0,
rotateFast: false,
),
RotationTarget(
waypointRelativePos: 1.5,
waypointRelativePos: 0.7,
rotationDegrees: 0.0,
rotateFast: false,
),
Expand Down Expand Up @@ -103,8 +103,8 @@ void main() {
),
));

expect(find.text('Rotation Target at 0.50'), findsOneWidget);
expect(find.text('Rotation Target at 1.50'), findsOneWidget);
expect(find.text('Rotation Target at 0.20'), findsOneWidget);
expect(find.text('Rotation Target at 0.70'), findsOneWidget);
});

testWidgets('Target card hover', (widgetTester) async {
Expand Down Expand Up @@ -223,12 +223,12 @@ void main() {
await widgetTester.pump();

expect(pathChanged, true);
expect(path.rotationTargets[0].waypointRelativePos, 1.0);
expect(path.rotationTargets[0].waypointRelativePos, 0.5);

undoStack.undo();
await widgetTester.pump();

expect(path.rotationTargets[0].waypointRelativePos, 0.5);
expect(path.rotationTargets[0].waypointRelativePos, 0.2);
});

testWidgets('Delete target button', (widgetTester) async {
Expand Down
30 changes: 17 additions & 13 deletions test/widgets/editor/tree_widgets/waypoints_tree_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ void main() {
expect(
find.descendant(
of: find.byType(TreeCardNode), matching: find.byType(TreeCardNode)),
findsNWidgets(3));
findsNWidgets(2));
});

testWidgets('waypoint card titles', (widgetTester) async {
path.addWaypoint(const Point(7.0, 4.0));

await widgetTester.pumpWidget(MaterialApp(
home: Scaffold(
body: WaypointsTree(
Expand Down Expand Up @@ -161,14 +163,14 @@ void main() {

expect(find.byType(NumberTextField), findsNothing);

await widgetTester.tap(waypointCards.at(1));
await widgetTester.tap(waypointCards.at(0));
await widgetTester.pumpAndSettle();
expect(selectedWaypoint, 1);
expect(selectedWaypoint, 0);
expect(find.byType(NumberTextField), findsWidgets);

await widgetTester.tap(waypointCards.at(2));
await widgetTester.tap(waypointCards.at(1));
await widgetTester.pumpAndSettle();
expect(selectedWaypoint, 2);
expect(selectedWaypoint, 1);

await widgetTester.tap(find.text('End Point'));
await widgetTester.pumpAndSettle();
Expand Down Expand Up @@ -355,7 +357,7 @@ void main() {
onWaypointDeleted: (value) => deletedWaypoint = value,
onWaypointHovered: (value) => hoveredWaypoint = value,
onWaypointSelected: (value) => selectedWaypoint = value,
initialSelectedWaypoint: 1,
initialSelectedWaypoint: 0,
holonomicMode: true,
),
),
Expand All @@ -366,18 +368,18 @@ void main() {

expect(textField, findsOneWidget);

num oldVal = path.waypoints[1].getNextControlLength();
num oldVal = path.waypoints[0].getNextControlLength();

await widgetTester.enterText(textField, '0.1');
await widgetTester.testTextInput.receiveAction(TextInputAction.done);
await widgetTester.pump();

expect(pathChanged, true);
expect(path.waypoints[1].getNextControlLength(), closeTo(0.1, epsilon));
expect(path.waypoints[0].getNextControlLength(), closeTo(0.1, epsilon));

undoStack.undo();
await widgetTester.pump();
expect(path.waypoints[1].getNextControlLength(), closeTo(oldVal, epsilon));
expect(path.waypoints[0].getNextControlLength(), closeTo(oldVal, epsilon));
});

testWidgets('Insert waypoint button', (widgetTester) async {
Expand All @@ -390,7 +392,7 @@ void main() {
onWaypointDeleted: (value) => deletedWaypoint = value,
onWaypointHovered: (value) => hoveredWaypoint = value,
onWaypointSelected: (value) => selectedWaypoint = value,
initialSelectedWaypoint: 1,
initialSelectedWaypoint: 0,
holonomicMode: true,
),
),
Expand All @@ -404,12 +406,12 @@ void main() {
await widgetTester.pump();

expect(pathChanged, true);
expect(path.waypoints.length, 4);
expect(path.waypoints.length, 3);

undoStack.undo();
await widgetTester.pump();

expect(path.waypoints.length, 3);
expect(path.waypoints.length, 2);
expect(selectedWaypoint, isNull);
});

Expand Down Expand Up @@ -561,7 +563,7 @@ void main() {

var lockButtons = find.byTooltip('Lock');

expect(lockButtons, findsNWidgets(3));
expect(lockButtons, findsNWidgets(2));

await widgetTester.tap(lockButtons.at(1));
await widgetTester.pump();
Expand All @@ -576,6 +578,8 @@ void main() {
});

testWidgets('Delete waypoint button', (widgetTester) async {
path.addWaypoint(const Point(7.0, 4.0));

await widgetTester.pumpWidget(MaterialApp(
home: Scaffold(
body: WaypointsTree(
Expand Down

0 comments on commit b5c5d6a

Please sign in to comment.