use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.
the class DragHandler method handlePathMoveDrag.
private void handlePathMoveDrag(DragEvent event, Path path, Waypoint point) {
double offsetX = event.getX() - point.getX();
double offsetY = event.getY() + point.getY();
// Make sure all waypoints will be within the bounds
for (Waypoint checkPoint : path.getWaypoints()) {
double wpNewX = checkPoint.getX() + offsetX;
double wpNewY = -checkPoint.getY() + offsetY;
if (!controller.checkBounds(wpNewX, -wpNewY)) {
return;
}
}
// Apply new positions
for (Waypoint changedPoint : path.getWaypoints()) {
double wpNewX = changedPoint.getX() + offsetX;
double wpNewY = changedPoint.getY() - offsetY;
changedPoint.setX(wpNewX);
changedPoint.setY(wpNewY);
}
path.update();
}
use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.
the class Path method recalculateTangents.
/**
* Recalculate the tangents for the waypoint provided, as well as those before and after it.
* This implementation skips over non-existent waypoints, calling the {@link #updateTangent(Waypoint)} on the others.
* @param wp the waypoint to recalculate tangents for
*/
public void recalculateTangents(Waypoint wp) {
int curWpIndex = getWaypoints().indexOf(wp);
if (curWpIndex - 1 > 0) {
Waypoint previous = getWaypoints().get(curWpIndex - 1);
updateTangent(previous);
}
updateTangent(wp);
if (curWpIndex + 1 < waypoints.size()) {
Waypoint next = getWaypoints().get(curWpIndex + 1);
updateTangent(next);
}
}
use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.
the class Path method flip.
/**
* Reflects the Path across an axis.
* The coordinate system's origin is the starting point of the Path.
*
* @param horizontal Flip over horizontal axis?
* @param drawPane Pane to check validity of new points.
*/
public void flip(boolean horizontal, Pane drawPane) {
// Check if any new points are outside drawPane
for (Waypoint wp : waypoints) {
if (!drawPane.contains(reflectPoint(getStart(), wp, horizontal, false))) {
Alert a = new Alert(Alert.AlertType.INFORMATION);
FxUtils.applyDarkMode(a);
a.setTitle("");
a.setHeaderText("The path could not be flipped.");
a.setContentText("Flipping this path would cause it to go out of bounds");
a.showAndWait();
// The new path is invalid
return;
}
}
// New waypoints are valid, update all Waypoints
for (Waypoint wp : waypoints) {
Point2D reflectedPos = reflectPoint(getStart(), wp, horizontal, false);
Point2D reflectedTangent = reflectPoint(getStart(), wp, horizontal, true);
wp.setX(reflectedPos.getX());
wp.setY(reflectedPos.getY());
wp.setTangent(reflectedTangent);
}
}
use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.
the class Path method enableSubchildSelector.
public void enableSubchildSelector(int i) {
this.subchildIdx = i;
for (Waypoint wp : waypoints) {
wp.enableSubchildSelector(subchildIdx);
}
spline.enableSubchildSelector(subchildIdx);
}
use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.
the class Path method deselectWaypoint.
/**
* Selects the given waypoint by calling the appropriate methods in {@link CurrentSelections}, making care to update the waypoint.
* This implementation does not currently null out {@link CurrentSelections#curPathProperty()} due to a NPE.
* @param waypoint the waypoint to deselect
*/
public void deselectWaypoint(Waypoint waypoint) {
Waypoint curWaypoint = CurrentSelections.getCurWaypoint();
if (CurrentSelections.getCurWaypoint() == waypoint) {
curWaypoint.getIcon().pseudoClassStateChanged(SELECTED_CLASS, false);
mainGroup.requestFocus();
CurrentSelections.setCurWaypoint(null);
}
}
Aggregations