Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Aug 7, 2024
1 parent 6dc9747 commit 8a64086
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public void handleShapeSelection(int shapeIndex) {
final ShapeWrapper selectedWrapperCopy = canvasModel.getShapeManager().getShapeByIndex(shapeIndex);

// Request user for line of reflection (gradient and y-intercept)
final double[] reflectionLine = requestReflectionLine();
final double[] data = requestReflectionLine();

if (reflectionLine == null) {
if (data.length != 2) {
return; // Cancel operation if user input is invalid
}

double gradient = reflectionLine[0];
double yIntercept = reflectionLine[1];
double gradient = data[0];
double yIntercept = data[1];

// Reflect the shape using the gradient and y-intercept
selectedWrapperCopy.reflect(gradient, yIntercept);
Expand All @@ -51,7 +51,8 @@ public boolean shouldDraw() {

/**
* Asks user to enter the gradient and y-intercept of the line of reflection.
* If input values are invalid or if the operation is canceled, null is returned.
* If input values are invalid or if the operation is canceled, null is
* returned.
*
* @return array with gradient and y-intercept [m, b]
*/
Expand All @@ -64,7 +65,7 @@ private double[] requestReflectionLine() {
panel.add(new JLabel("Y-Intercept (b):"));
panel.add(yInterceptField);

int result = JOptionPane.showConfirmDialog(null, panel, "Enter Line of Reflection",
int result = JOptionPane.showConfirmDialog(canvas, panel, "Enter Line of Reflection",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);

Expand All @@ -80,6 +81,6 @@ private double[] requestReflectionLine() {
JOptionPane.showMessageDialog(null, "Invalid input. Please enter numeric values.");
}
}
return null;
return new double[] {};
}
}

0 comments on commit 8a64086

Please sign in to comment.