Skip to content

Commit

Permalink
Resize Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnTheWitch committed Nov 25, 2023
1 parent 6939691 commit b8c9392
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 42 deletions.
27 changes: 16 additions & 11 deletions src/DrawModes/ResizeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let legalNode: boolean;

//The direction the cut will move in. For x 1 means going to the right and -1 means left.
//For y 1 means going down and -1 means going up.
const direction: Point = new Point(1, 1);
let direction: Point = new Point(1, 1);

/**
* Takes the point the user clicked and stores that for later use. If the lowest node containing
Expand All @@ -34,7 +34,7 @@ const direction: Point = new Point(1, 1);
export function resizeMouseDown(event: MouseEvent) {
startingPoint = new Point(event.x - offset.x, event.y - offset.y);
currentNode = treeContext.tree.getLowestNode(startingPoint);
if (currentNode !== treeContext.tree.sheet && currentNode instanceof CutNode) {
if (currentNode instanceof CutNode && currentNode.ellipse !== null) {
legalNode = true;
const currentParent = treeContext.tree.getLowestParent(startingPoint);
if (currentParent !== null) {
Expand All @@ -44,7 +44,7 @@ export function resizeMouseDown(event: MouseEvent) {
for (let i = 0; i < currentNode.children.length; i++) {
treeContext.tree.insert(currentNode.children[i]);
}
determineDirection();
direction = determineDirection(currentNode, startingPoint);
currentNode.children = [];
}
}
Expand All @@ -62,7 +62,7 @@ export function resizeMouseMove(event: MouseEvent) {
);

if (currentNode instanceof CutNode) {
const tempCut: CutNode = resizeCut(currentNode, moveDifference);
const tempCut: CutNode = resizeCut(currentNode, moveDifference, direction);
//This is just to make the lint stop yelling
if (tempCut.ellipse !== null) {
redrawTree(treeContext.tree);
Expand All @@ -88,7 +88,7 @@ export function resizeMouseUp(event: MouseEvent) {
);

if (currentNode instanceof CutNode) {
const tempCut: CutNode = resizeCut(currentNode, moveDifference);
const tempCut: CutNode = resizeCut(currentNode, moveDifference, direction);
//This is just to make the lint stop yelling
if (tempCut.ellipse !== null) {
if (treeContext.tree.canInsert(tempCut) && ellipseLargeEnough(tempCut.ellipse)) {
Expand Down Expand Up @@ -119,9 +119,10 @@ export function resizeMouseOut() {
* Alters the change to the center based on the direction that is being moved to.
* @param originalCut The original cut that will be copied and altered
* @param difference The change for the new cut
* @param direction the direction the radius will be expanding towards
* @returns The new altered cut
*/
function resizeCut(originalCut: CutNode, difference: Point) {
export function resizeCut(originalCut: CutNode, difference: Point, direction: Point) {
if (originalCut.ellipse !== null) {
return new CutNode(
new Ellipse(
Expand All @@ -145,8 +146,10 @@ function resizeCut(originalCut: CutNode, difference: Point) {
* widestPoints[1] = topmost widest point of the ellipse
* widestPoints[2] = rightmost widest point of the ellipse
* widestPoints[3] = bottommost widest point of the ellipse
* @returns The new direction for x and y
*/
function determineDirection() {
export function determineDirection(currentNode: CutNode, startingPoint: Point): Point {
const newDirection = new Point(1, 1);
if (currentNode instanceof CutNode && (currentNode as CutNode).ellipse !== null) {
const currentEllipse: Ellipse = currentNode.ellipse as Ellipse;
const widestPoints: Point[] = [
Expand All @@ -158,16 +161,18 @@ function determineDirection() {

//If the current point is closer to the top or equal the direction is positive and going down
if (widestPoints[0].distance(startingPoint) >= widestPoints[2].distance(startingPoint)) {
direction.x = 1;
newDirection.x = 1;
} else {
direction.x = -1;
newDirection.x = -1;
}

//If the current point is closer to the left or equal the direction is positive and going right
if (widestPoints[1].distance(startingPoint) >= widestPoints[3].distance(startingPoint)) {
direction.y = 1;
newDirection.y = 1;
} else {
direction.y = -1;
newDirection.y = -1;
}
}

return newDirection;
}
14 changes: 7 additions & 7 deletions src/ProofTools/ProofMoveMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function proofMoveMultiMouseMove(event: MouseEvent) {
*/
export function proofMoveMultiMouseUp(event: MouseEvent) {
if (legalNode) {
const nextProof = new ProofNode(currentProofTree, "Multi Movement");
const nextStep = new ProofNode(currentProofTree, "Multi Movement");
const moveDifference: Point = new Point(
event.x - startingPoint.x,
event.y - startingPoint.y
Expand All @@ -97,22 +97,22 @@ export function proofMoveMultiMouseUp(event: MouseEvent) {
const tempCut: CutNode = alterCutChildren(currentNode, moveDifference);

if (isLegal(tempCut)) {
nextProof.tree.insert(tempCut);
nextStep.tree.insert(tempCut);
} else {
nextProof.tree.insert(currentNode);
nextStep.tree.insert(currentNode);
}
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);

if (isLegal(tempAtom)) {
nextProof.tree.insert(tempAtom);
nextStep.tree.insert(tempAtom);
} else {
nextProof.tree.insert(currentNode);
nextStep.tree.insert(currentNode);
}
}

treeContext.proofHistory.push(nextProof);
redrawTree(nextProof.tree);
treeContext.proofHistory.push(nextStep);
redrawTree(nextStep.tree);
}
legalNode = false;
}
Expand Down
14 changes: 7 additions & 7 deletions src/ProofTools/ProofMoveSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function proofMoveSingleMouseMove(event: MouseEvent) {
*/
export function proofMoveSingleMouseUp(event: MouseEvent) {
if (legalNode) {
const nextProof = new ProofNode(currentProofTree, "Single Movement");
const nextStep = new ProofNode(currentProofTree, "Single Movement");
const moveDifference: Point = new Point(
event.x - startingPoint.x,
event.y - startingPoint.y
Expand All @@ -105,23 +105,23 @@ export function proofMoveSingleMouseUp(event: MouseEvent) {

//If the new location is legal, insert the cut otherwise reinsert the cut we removed.
if (isLegal(tempCut)) {
nextProof.tree.insert(tempCut);
nextStep.tree.insert(tempCut);
} else {
nextProof.tree.insert(currentNode);
nextStep.tree.insert(currentNode);
}
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);

//If the new location is legal, insert the atom, if not reinsert the atom we removed.
if (isLegal(tempAtom)) {
nextProof.tree.insert(tempAtom);
nextStep.tree.insert(tempAtom);
} else {
nextProof.tree.insert(currentNode);
nextStep.tree.insert(currentNode);
}
}

treeContext.proofHistory.push(nextProof);
redrawTree(nextProof.tree);
treeContext.proofHistory.push(nextStep);
redrawTree(nextStep.tree);
}
legalNode = false;
}
Expand Down
113 changes: 113 additions & 0 deletions src/ProofTools/ProofResizeTool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Resize tool to be used during Proof Mode
* @author Dawn Moore
*/

import {AEGTree} from "../AEG/AEGTree";
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "../DrawModes/DragTool";
import {drawCut, redrawTree} from "../DrawModes/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {ProofNode} from "../AEG/ProofNode";
import {resizeCut, determineDirection} from "../DrawModes/ResizeTool";
import {ellipseLargeEnough} from "../DrawModes/CutTool";
import {proofCanInsert} from "./ProofMoveSingleTool";

//The initial point the user pressed down.
let startingPoint: Point;

//The node selected with the user mouse down.
let currentNode: CutNode | AtomNode | null = null;

//Whether or not the node is allowed to be moved (not the sheet).
let legalNode: boolean;

//The direction the cut will move in. For x 1 means going to the right and -1 means left.
//For y 1 means going down and -1 means going up.
let direction: Point = new Point(1, 1);

//The tree of the current proof step
let currentProofTree: AEGTree;

export function proofResizeMouseDown(event: MouseEvent) {
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
startingPoint = new Point(event.x - offset.x, event.y - offset.y);
currentNode = currentProofTree.getLowestNode(startingPoint);

if (currentNode instanceof CutNode && currentNode.ellipse !== null) {
legalNode = true;
const currentParent = currentProofTree.getLowestParent(startingPoint);
if (currentParent !== null) {
currentParent.remove(startingPoint);
}

for (let i = 0; i < currentNode.children.length; i++) {
currentProofTree.insert(currentNode.children[i]);
}
direction = determineDirection(currentNode, startingPoint);
currentNode.children = [];
}
}

export function proofResizeMouseMove(event: MouseEvent) {
if (legalNode) {
const moveDifference: Point = new Point(
(event.x - offset.x - startingPoint.x) / 2,
(event.y - offset.y - startingPoint.y) / 2
);

if (currentNode instanceof CutNode) {
const tempCut: CutNode = resizeCut(currentNode, moveDifference, direction);
//This is just to make the lint stop yelling
if (tempCut.ellipse !== null) {
redrawTree(currentProofTree);
const color = isLegal(tempCut) ? legalColor() : illegalColor();
drawCut(tempCut, color);
}
}
}
}

export function proofResizeMouseUp(event: MouseEvent) {
if (legalNode) {
const moveDifference: Point = new Point(
(event.x - offset.x - startingPoint.x) / 2,
(event.y - offset.y - startingPoint.y) / 2
);

if (currentNode instanceof CutNode) {
const tempCut: CutNode = resizeCut(currentNode, moveDifference, direction);
//This is just to make the lint stop yelling
if (tempCut.ellipse !== null) {
if (isLegal(tempCut)) {
currentProofTree.insert(tempCut);
} else {
currentProofTree.insert(currentNode);
}
}
}

treeContext.proofHistory.push(new ProofNode(currentProofTree, "Resize Cut"));
redrawTree(treeContext.getLastProofStep().tree);
legalNode = false;
}
}

export function proofResizeMouseOut() {
if (legalNode && currentNode !== null) {
currentProofTree.insert(currentNode);
}
legalNode = false;
redrawTree(treeContext.getLastProofStep().tree);
}

function isLegal(currentCut: CutNode): boolean {
return (
currentProofTree.canInsert(currentCut) &&
ellipseLargeEnough(currentCut.ellipse!) &&
proofCanInsert(new AEGTree(currentProofTree.sheet), currentCut)
);
}
6 changes: 3 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@
</div>
<div id="ProofButtons">
<div class="row">
<button type="button" onclick="setTool(proofMoveSingle)" title="Move Single" class="toolButton">
<button type="button" onclick="setTool(proofMoveSingleTool)" title="Move Single" class="toolButton">
<i class="fa fa-mouse-pointer" aria-hidden="true"></i>
</button>
<button type="button" onclick="setTool(proofMoveMulti)" title="Move Multiple" class="toolButton">
<button type="button" onclick="setTool(proofMoveMultiTool)" title="Move Multiple" class="toolButton">
<i class="fa fa-arrows" aria-hidden="true"></i>
</button>
</div>
<div class="row">
<button type="button" onclick="" title="Resize Single" class="toolButton">
<button type="button" onclick="setTool(proofResizeTool)" title="Resize Single" class="toolButton">
<i class="fa fa-arrows-alt" aria-hidden="true"></i>
</button>
<button type="button" onclick="setTool(pasteInProofTool)" title="Paste graph from Draw Mode" class="toolButton">
Expand Down
Loading

0 comments on commit b8c9392

Please sign in to comment.