Line selectedSide = (Line)step.getInputs()[1];
Line newSide = (Line)step.getInputs()[2];
boolean orientation = ((Boolean)step.getInputs()[3]).booleanValue();
if (Math.abs(selectedSide.getLength()-newSide.getLength()) < Point.LEAST_COUNT) {
Point[] vertices = tri.getVertices();
Point ptOppSelSide = new Point();
if (vertices[0].canIntersect(selectedSide))
if (vertices[1].canIntersect(selectedSide))
ptOppSelSide.setCoordinates(vertices[2].getX(), vertices[2].getY());
else
ptOppSelSide.setCoordinates(vertices[1].getX(), vertices[1].getY());
else
ptOppSelSide.setCoordinates(vertices[0].getX(), vertices[0].getY());
Line line1 = (orientation)?
(new Line(selectedSide.getStart(), newSide.getStart())):
(new Line(selectedSide.getStart(), newSide.getEnd()));
Line line2 = (orientation)?
(new Line(selectedSide.getEnd(), newSide.getEnd())):
(new Line(selectedSide.getEnd(), newSide.getStart()));
Point centreOfRotation;
Angle angleOfRotation;
if (line1.getLength() < Point.LEAST_COUNT) {
centreOfRotation = new Point(line1.getStart().getX(),line1.getStart().getY());
angleOfRotation = (new Line(centreOfRotation, line2.getEnd())).getSlope().
sub((new Line(centreOfRotation, line2.getStart())).getSlope());
}
else if (line2.getLength() < Point.LEAST_COUNT) {
centreOfRotation = new Point(line2.getStart().getX(),line2.getStart().getY());
angleOfRotation = (new Line(centreOfRotation, line1.getEnd())).getSlope().
sub((new Line(centreOfRotation, line1.getStart())).getSlope());
}
else {
Line perpLine1 = new Line(line1.midPoint(),line1.getSlope().
add(new Angle(Math.PI/2)),1);
Line perpLine2 = new Line(line2.midPoint(),line2.getSlope().
add(new Angle(Math.PI/2)),1);
if (perpLine1.canIntersect(perpLine2)) {
centreOfRotation = perpLine1.intersect(perpLine2)[0];
angleOfRotation = (new Line(centreOfRotation, line1.getEnd())).getSlope().
sub((new Line(centreOfRotation, line1.getStart())).getSlope());
}
else {
Point translation = new Point(
line1.getEnd().getX() - line1.getStart().getX(),
line1.getEnd().getY() - line1.getStart().getY());
ptOppSelSide.move(translation, new Angle(0), new Point());
Triangle newTriangle = new Triangle(ptOppSelSide, newSide);
newTriangle.addToObjects(objects);
clearAndHide();
step.setOutputs(new Object[]{ptOppSelSide, newTriangle.getSides()[1],
newTriangle.getSides()[2], newTriangle});
fireUndoableEditUpdate(new UndoableEditEvent(this, step));
return;
}
}
ptOppSelSide.move(new Point(), angleOfRotation, centreOfRotation);
Triangle newTriangle = new Triangle(ptOppSelSide, newSide);
newTriangle.addToObjects(objects);
clearAndHide();
step.setOutputs(new Object[]{ptOppSelSide, newTriangle.getSides()[1],
newTriangle.getSides()[2], newTriangle});