diff --git a/src/DrawModes/CopyFromDraw.ts b/src/DrawModes/CopyFromDraw.ts index 0847b18c..0fcf2093 100644 --- a/src/DrawModes/CopyFromDraw.ts +++ b/src/DrawModes/CopyFromDraw.ts @@ -8,7 +8,7 @@ import {AtomNode} from "../AEG/AtomNode"; import {CutNode} from "../AEG/CutNode"; import {treeContext} from "../treeContext"; import {offset} from "../SharedToolUtils/DragTool"; -import {drawAtom, cleanCanvas, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils"; +import {cleanCanvas, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils"; import {legalColor} from "../Themes"; import {AEGTree} from "../AEG/AEGTree"; @@ -118,11 +118,7 @@ function isLegal() { } //Highlight the selected part by redrawing in legalColor - if (selectedNode instanceof AtomNode) { - drawAtom(selectedNode, legalColor(), true); - } else { - highlightNode(selectedNode, legalColor()); - } + highlightNode(selectedNode, legalColor()); //If something was removed, add it back kin if (removed) { diff --git a/src/DrawModes/DeleteMultiTool.ts b/src/DrawModes/DeleteMultiTool.ts index a214f6c9..e5ea0696 100644 --- a/src/DrawModes/DeleteMultiTool.ts +++ b/src/DrawModes/DeleteMultiTool.ts @@ -6,11 +6,11 @@ import {Point} from "../AEG/Point"; import {AtomNode} from "../AEG/AtomNode"; import {CutNode} from "../AEG/CutNode"; -import {redrawTree} from "../SharedToolUtils/DrawUtils"; import {treeContext} from "../treeContext"; import {illegalColor} from "../Themes"; +import {highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils"; import {offset} from "../SharedToolUtils/DragTool"; -import {highlightChildren} from "../SharedToolUtils/EditModeUtils"; +import {reInsertNode} from "../SharedToolUtils/EditModeUtils"; //The initial point the user pressed down. let startingPoint: Point; @@ -33,8 +33,16 @@ export function deleteMultiMouseDown(event: MouseEvent) { currentNode = treeContext.tree.getLowestNode(startingPoint); if (currentNode !== null) { + const currentParent = treeContext.tree.getLowestParent(startingPoint); + if (currentParent !== null) { + currentParent.remove(startingPoint); + } else { + currentNode = treeContext.tree.sheet.copy(); + treeContext.tree.clear(); + } legalNode = true; - highlightChildren(currentNode, illegalColor()); + redrawTree(treeContext.tree); + highlightNode(currentNode, illegalColor()); } } @@ -44,18 +52,29 @@ export function deleteMultiMouseDown(event: MouseEvent) { * The removal will update accordingly. */ export function deleteMultiMouseMove(event: MouseEvent) { + if (legalNode && currentNode !== null) { + reInsertNode(treeContext.tree, currentNode); + } const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y); const newNode: CutNode | AtomNode | null = treeContext.tree.getLowestNode(newPoint); - if (currentNode !== null && currentNode !== treeContext.tree.getLowestNode(newPoint)) { + const currentParent = treeContext.tree.getLowestParent(newPoint); + if (legalNode && currentNode !== null && currentParent !== null) { legalNode = true; - redrawTree(treeContext.tree); if (newNode === null) { currentNode = null; legalNode = false; } else { + currentParent.remove(newPoint); currentNode = newNode; - highlightChildren(currentNode, illegalColor()); + legalNode = true; + redrawTree(treeContext.tree); + highlightNode(currentNode, illegalColor()); } + } else if (legalNode && currentParent === null) { + currentNode = treeContext.tree.sheet.copy(); + treeContext.tree.clear(); + redrawTree(treeContext.tree); + highlightNode(currentNode, illegalColor()); } } @@ -66,9 +85,9 @@ export function deleteMultiMouseMove(event: MouseEvent) { export function deleteMultiMouseUp(event: MouseEvent) { const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y); if (legalNode) { - const currentParent = treeContext.tree.getLowestParent(newPoint); - if (currentParent !== null) { - currentParent.remove(newPoint); + const currentNode = treeContext.tree.getLowestNode(newPoint); + if (currentNode !== null && currentNode instanceof CutNode) { + currentNode.remove(newPoint); } else { treeContext.tree.clear(); } @@ -82,6 +101,9 @@ export function deleteMultiMouseUp(event: MouseEvent) { * If the mouse is held down and the user leaves canvas, we reset fields back to default. */ export function deleteMultiMouseOut() { + if (legalNode && currentNode !== null) { + reInsertNode(treeContext.tree, currentNode); + } currentNode = null; legalNode = false; redrawTree(treeContext.tree); diff --git a/src/DrawModes/DeleteSingleTool.ts b/src/DrawModes/DeleteSingleTool.ts index e355dc49..4b421da4 100644 --- a/src/DrawModes/DeleteSingleTool.ts +++ b/src/DrawModes/DeleteSingleTool.ts @@ -11,6 +11,7 @@ import {offset} from "../SharedToolUtils/DragTool"; import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils"; import {treeContext} from "../treeContext"; import {illegalColor} from "../Themes"; +import {readdChildren, reInsertNode} from "../SharedToolUtils/EditModeUtils"; //The initial point the user pressed down. let startingPoint: Point; @@ -31,14 +32,28 @@ let legalNode: boolean; export function deleteSingleMouseDown(event: MouseEvent) { startingPoint = new Point(event.x - offset.x, event.y - offset.y); currentNode = treeContext.tree.getLowestNode(startingPoint); - if (currentNode !== null) { - legalNode = true; + const currentParent = treeContext.tree.getLowestParent(startingPoint); + if (currentParent !== null) { + currentParent.remove(startingPoint); + } + + if ( + currentNode instanceof CutNode && + currentNode.children.length !== 0 && + currentNode !== treeContext.tree.sheet + ) { + readdChildren(treeContext.tree, currentNode); + } + redrawTree(treeContext.tree); if (currentNode instanceof AtomNode) { drawAtom(currentNode, illegalColor(), true); } else { drawCut(currentNode, illegalColor()); } + legalNode = true; + } else { + legalNode = false; } } @@ -49,16 +64,26 @@ export function deleteSingleMouseDown(event: MouseEvent) { * @param event The mouse move event */ export function deleteSingleMouseMove(event: MouseEvent) { + if (legalNode && currentNode !== null && (currentNode as CutNode).ellipse !== null) { + reInsertNode(treeContext.tree, currentNode); + } const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y); const newNode: CutNode | AtomNode | null = treeContext.tree.getLowestNode(newPoint); - if (currentNode !== null && currentNode !== newNode) { + const currentParent = treeContext.tree.getLowestParent(newPoint); + if (legalNode && currentNode !== null && currentParent !== null) { legalNode = true; redrawTree(treeContext.tree); if (newNode === null) { currentNode = null; legalNode = false; } else { + currentParent.remove(newPoint); currentNode = newNode; + if (currentNode instanceof CutNode && currentNode.children.length !== 0) { + readdChildren(treeContext.tree, currentNode); + currentNode.children = []; + } + redrawTree(treeContext.tree); if (currentNode instanceof AtomNode) { drawAtom(currentNode, illegalColor(), true); } else { @@ -75,22 +100,20 @@ export function deleteSingleMouseMove(event: MouseEvent) { export function deleteSingleMouseUp(event: MouseEvent) { const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y); if (legalNode) { - const currentParent = treeContext.tree.getLowestParent(newPoint); - if (currentParent !== null) { - currentParent.remove(newPoint); + const currentNode = treeContext.tree.getLowestNode(newPoint); + if (currentNode !== null && currentNode instanceof CutNode) { + currentNode.remove(newPoint); } if ( currentNode !== treeContext.tree.sheet && currentNode instanceof CutNode && currentNode.children.length !== 0 ) { - //The cut node loses custody of its children so that those can still be redrawn. - for (let i = 0; i < currentNode.children.length; i++) { - treeContext.tree.insert(currentNode.children[i]); - } + readdChildren(treeContext.tree, currentNode); } + redrawTree(treeContext.tree); } - redrawTree(treeContext.tree); + currentNode = null; legalNode = false; } @@ -99,6 +122,10 @@ export function deleteSingleMouseUp(event: MouseEvent) { * If the mouse leaves the canvas, reset data back to defaults. */ export function deleteSingleMouseOut() { + if (legalNode && currentNode !== null) { + reInsertNode(treeContext.tree, currentNode); + } currentNode = null; legalNode = false; + redrawTree(treeContext.tree); } diff --git a/src/ProofTools/DeiterationTool.ts b/src/ProofTools/DeiterationTool.ts index a8fb795c..ff8cbb03 100644 --- a/src/ProofTools/DeiterationTool.ts +++ b/src/ProofTools/DeiterationTool.ts @@ -6,14 +6,13 @@ import {Point} from "../AEG/Point"; import {AtomNode} from "../AEG/AtomNode"; import {CutNode} from "../AEG/CutNode"; -import {redrawProof} from "../SharedToolUtils/DrawUtils"; +import {redrawProof, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils"; import {treeContext} from "../treeContext"; import {illegalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {ProofNode} from "../AEG/ProofNode"; import {AEGTree} from "../AEG/AEGTree"; -import {highlightChildren} from "../SharedToolUtils/EditModeUtils"; -import {getCurrentProofTree} from "./ProofToolsUtils"; +import {reInsertNode} from "../SharedToolUtils/EditModeUtils"; //The node selected with the user mouse down. let currentNode: CutNode | AtomNode | null = null; @@ -21,6 +20,12 @@ let currentNode: CutNode | AtomNode | null = null; //Whether or not the node is allowed to be moved (not the sheet). let legalNode: boolean; +//A copy of the tree we are dealing with in this step +let tempTree: AEGTree; + +//The point that the current mouse event is targeting +let currentPoint: Point; + //The current tree in the proof chain let currentProofTree: AEGTree; @@ -30,8 +35,12 @@ let currentProofTree: AEGTree; * @param event A Mouse up event while using the deiteration tool */ export function deiterationMouseDown(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentProofTree = getCurrentProofTree(); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); + currentProofTree = new AEGTree(); + if (treeContext.currentProofStep) { + currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy(); + } + tempTree = new AEGTree(currentProofTree.sheet); currentNode = currentProofTree.getLowestNode(currentPoint); setLegal(); @@ -43,11 +52,12 @@ export function deiterationMouseDown(event: MouseEvent) { * @param event A mouse move event while using deiteration tool */ export function deiterationMouseMove(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentNode = currentProofTree.getLowestNode(currentPoint); - redrawProof(); - - setLegal(); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); + if (currentNode !== null) { + currentNode = currentProofTree.getLowestNode(currentPoint); + redrawProof(); + setLegal(); + } } /** @@ -57,7 +67,7 @@ export function deiterationMouseMove(event: MouseEvent) { */ export function deiterationMouseUp(event: MouseEvent) { if (legalNode) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); if ( currentNode !== null && canDeiterate(currentProofTree.sheet, currentProofTree.getLevel(currentNode)) @@ -83,8 +93,21 @@ function setLegal() { !(currentNode instanceof CutNode && currentNode.ellipse === null) && canDeiterate(currentProofTree.sheet, currentProofTree.getLevel(currentNode)) ) { - highlightChildren(currentNode, illegalColor()); legalNode = true; + + //Find the parent at the point we are on + const tempParent = tempTree.getLowestParent(currentPoint); + if (tempParent !== null) { + //remove the node from the parent + tempParent.remove(currentPoint); + } + + //Draw the temp tree, from which the node we want to erase has been removed + redrawTree(tempTree); + //Highlight the node selected for deiteration in illegal color + highlightNode(currentNode, illegalColor()); + //Insert it back into the temporary tree + tempTree.insert(currentNode); } else { legalNode = false; } @@ -94,6 +117,9 @@ function setLegal() { * Reset the current null and make this node illegal until it's selected again, redraws the screen. */ export function deiterationMouseOut() { + if (legalNode && currentNode !== null) { + reInsertNode(tempTree, currentNode); + } legalNode = false; currentNode = null; redrawProof(); diff --git a/src/ProofTools/DoubleCutDeletionTool.ts b/src/ProofTools/DoubleCutDeletionTool.ts index be25fc57..86516014 100644 --- a/src/ProofTools/DoubleCutDeletionTool.ts +++ b/src/ProofTools/DoubleCutDeletionTool.ts @@ -6,13 +6,13 @@ import {Point} from "../AEG/Point"; import {AtomNode} from "../AEG/AtomNode"; import {CutNode} from "../AEG/CutNode"; -import {drawCut, redrawProof} from "../SharedToolUtils/DrawUtils"; +import {drawCut, redrawProof, redrawTree} from "../SharedToolUtils/DrawUtils"; import {treeContext} from "../treeContext"; import {illegalColor} from "../Themes"; import {offset} from "../SharedToolUtils/DragTool"; import {ProofNode} from "../AEG/ProofNode"; import {AEGTree} from "../AEG/AEGTree"; -import {getCurrentProofTree} from "./ProofToolsUtils"; +import {reInsertNode, readdChildren} from "../SharedToolUtils/EditModeUtils"; //The node selected with the user mouse down. let currentNode: CutNode | AtomNode | null = null; @@ -20,16 +20,27 @@ let currentNode: CutNode | AtomNode | null = null; //Whether or not the node is allowed to be moved (not the sheet). let legalNode: boolean; +//The current tree in the proof chain let currentProofTree: AEGTree; +//A copy of the tree we are dealing with in this step +let tempTree: AEGTree; + +//The point that the current mouse event is targeting +let currentPoint: Point; + /** * Takes the current point and finds the lowest node containing that point. * If that node is a double cut then it is a legal node and highlights it with the illegal color. * @param event The event of a mouse down while the user is using double cut deletion */ export function doubleCutDeletionMouseDown(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentProofTree = getCurrentProofTree(); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); + currentProofTree = new AEGTree(); + if (treeContext.currentProofStep) { + currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy(); + } + tempTree = new AEGTree(currentProofTree.sheet); currentNode = currentProofTree.getLowestNode(currentPoint); isLegal(); @@ -41,11 +52,13 @@ export function doubleCutDeletionMouseDown(event: MouseEvent) { * @param event The event of a mouse move while the user is using double cut deletion */ export function doubleCutDeletionMouseMove(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentNode = currentProofTree.getLowestNode(currentPoint); - redrawProof(); - - isLegal(); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); + tempTree = new AEGTree(currentProofTree.sheet); + if (currentNode !== null) { + currentNode = currentProofTree.getLowestNode(currentPoint); + redrawProof(); + isLegal(); + } } /** @@ -57,7 +70,7 @@ export function doubleCutDeletionMouseUp(event: MouseEvent) { //Stores the tree of the previous proof so that we can perform double cut actions without //altering that tree const nextProof = new ProofNode(currentProofTree, "DC Delete"); - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); if (legalNode && currentNode instanceof CutNode) { const currentParent: CutNode | null = nextProof.tree.getLowestParent(currentPoint); @@ -79,6 +92,10 @@ export function doubleCutDeletionMouseUp(event: MouseEvent) { * Resets the canvas if the mouse ends up out of the canvas. */ export function doubleCutDeletionMouseOut() { + if (legalNode && currentNode !== null) { + reInsertNode(tempTree, currentNode); + } + currentNode = null; legalNode = false; redrawProof(); } @@ -111,6 +128,22 @@ function highlightDoubleCut(parentCut: CutNode) { function isLegal() { if (currentNode instanceof CutNode && isDoubleCut(currentNode)) { legalNode = true; + + //Find the parent at the point we are on + const tempParent = tempTree.getLowestParent(currentPoint); + if (tempParent !== null) { + //remove the node from the parent + tempParent.remove(currentPoint); + //The parent should adopt the children from the lower cut + const tempLower = currentNode.children[0].copy() as CutNode; + readdChildren(tempTree, tempLower); + tempLower.children = []; + } + + //Draw the temp tree, from which the node we want to erase has been removed + redrawTree(tempTree); + + //Highlight the double cut selected for deletion in illegal color highlightDoubleCut(currentNode); } else { legalNode = false; diff --git a/src/ProofTools/ErasureTool.ts b/src/ProofTools/ErasureTool.ts index d1e078d9..6159f8aa 100644 --- a/src/ProofTools/ErasureTool.ts +++ b/src/ProofTools/ErasureTool.ts @@ -6,14 +6,13 @@ import {Point} from "../AEG/Point"; import {AtomNode} from "../AEG/AtomNode"; import {CutNode} from "../AEG/CutNode"; -import {redrawProof} from "../SharedToolUtils/DrawUtils"; import {treeContext} from "../treeContext"; import {illegalColor} from "../Themes"; -import {offset} from "../SharedToolUtils/DragTool"; -import {highlightChildren} from "../SharedToolUtils/EditModeUtils"; import {ProofNode} from "../AEG/ProofNode"; import {AEGTree} from "../AEG/AEGTree"; -import {getCurrentProofTree} from "./ProofToolsUtils"; +import {reInsertNode} from "../SharedToolUtils/EditModeUtils"; +import {redrawProof, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils"; +import {offset} from "../SharedToolUtils/DragTool"; //The node selected with the user mouse down. let currentNode: CutNode | AtomNode | null = null; @@ -21,16 +20,27 @@ let currentNode: CutNode | AtomNode | null = null; //Whether or not the node is allowed to be moved (not the sheet). let legalNode: boolean; +//The current tree in the proof chain let currentProofTree: AEGTree; +//A copy of the tree we are dealing with in this step +let tempTree: AEGTree; + +//The point that the current mouse event is targeting +let currentPoint: Point; + /** * Captures the current location, and the node linked with that location. * Determines if it is a legal node. * @param event The mouse down event while using the erasure tool */ export function erasureMouseDown(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentProofTree = getCurrentProofTree(); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); + currentProofTree = new AEGTree(); + if (treeContext.currentProofStep) { + currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy(); + } + tempTree = new AEGTree(currentProofTree.sheet); currentNode = currentProofTree.getLowestNode(currentPoint); isLegal(); @@ -42,11 +52,13 @@ export function erasureMouseDown(event: MouseEvent) { * @param event The mouse move event while using the erasure tool */ export function erasureMouseMove(event: MouseEvent) { - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); - currentNode = currentProofTree.getLowestNode(currentPoint); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); - redrawProof(); - isLegal(); + if (currentNode !== null) { + currentNode = currentProofTree.getLowestNode(currentPoint); + redrawProof(); + isLegal(); + } } /** @@ -60,7 +72,7 @@ export function erasureMouseUp(event: MouseEvent) { //altering that tree const nextProof = new ProofNode(currentProofTree, "Erasure"); - const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y); + currentPoint = new Point(event.x - offset.x, event.y - offset.y); const currentParent = nextProof.tree.getLowestParent(currentPoint); if (currentParent !== null) { currentParent.remove(currentPoint); @@ -78,6 +90,9 @@ export function erasureMouseUp(event: MouseEvent) { * If the mouse is exited the canvas resets the current node and makes it illegal. */ export function erasureMouseOut() { + if (legalNode && currentNode !== null) { + reInsertNode(tempTree, currentNode); + } currentNode = null; legalNode = false; redrawProof(); @@ -94,7 +109,20 @@ function isLegal() { currentProofTree.getLevel(currentNode) % 2 === 0 ) { legalNode = true; - highlightChildren(currentNode, illegalColor()); + + //Find the parent at the point we are on + const tempParent = tempTree.getLowestParent(currentPoint); + if (tempParent !== null) { + //remove the node from the parent + tempParent.remove(currentPoint); + } + + //Draw the temp tree, from which the node we want to erase has been removed + redrawTree(tempTree); + //Highlight the node selected for erasure in illegal color + highlightNode(currentNode, illegalColor()); + //Insert it back into the temporary tree + tempTree.insert(currentNode); } else { legalNode = false; } diff --git a/src/SharedToolUtils/DrawUtils.ts b/src/SharedToolUtils/DrawUtils.ts index a3098857..2aa979ac 100644 --- a/src/SharedToolUtils/DrawUtils.ts +++ b/src/SharedToolUtils/DrawUtils.ts @@ -1,6 +1,6 @@ /** * File containing all drawing function for the canvas - * @author Dawn MOore + * @author Dawn Moore */ import {Point} from "../AEG/Point"; @@ -163,7 +163,9 @@ export function redrawProof() { } /** - * Helper function to highlight the specific selected node + * Highlights all the children of the incoming node as the incoming color. + * @param child The incoming node + * @param color The incoming color */ export function highlightNode(child: AtomNode | CutNode, color: string) { if (child instanceof AtomNode) { diff --git a/src/SharedToolUtils/EditModeUtils.ts b/src/SharedToolUtils/EditModeUtils.ts index cc4967d3..43f16347 100644 --- a/src/SharedToolUtils/EditModeUtils.ts +++ b/src/SharedToolUtils/EditModeUtils.ts @@ -9,7 +9,7 @@ import {CutNode} from "../AEG/CutNode"; import {treeContext} from "../treeContext"; import {offset} from "./DragTool"; import {Ellipse} from "../AEG/Ellipse"; -import {drawCut, drawAtom} from "./DrawUtils"; +import {drawCut, drawAtom, redrawTree} from "./DrawUtils"; import {AEGTree} from "../AEG/AEGTree"; const modeElm: HTMLSelectElement = document.getElementById("mode"); @@ -193,22 +193,6 @@ export function alterAtom(originalAtom: AtomNode, difference: Point) { ); } -/** - * Highlights all the children of the incoming node as the incoming color. - * @param child The incoming node - * @param color The incoming color - */ -export function highlightChildren(child: AtomNode | CutNode, color: string) { - if (child instanceof AtomNode) { - drawAtom(child, color, true); - } else if (child instanceof CutNode) { - drawCut(child, color); - for (let i = 0; i < child.children.length; i++) { - highlightChildren(child.children[i], color); - } - } -} - /** * Makes a copy of original cut and changes the center and radii by the difference given. * Alters the change to the center based on the direction that is being moved to. @@ -233,6 +217,38 @@ export function resizeCut(originalCut: CutNode, difference: Point, direction: Po throw new Error("Cannot alter the position of a cut without an ellipse."); } } + +/** + * Readds children of a parent CutNode. + * In the wise words of Dawn Moore, + * "The cut node loses custody of its children so that those can still be redrawn." + * @param tree The AEG tree we want to readd the children into + * @param parentCut Parent CutNode + */ +export function readdChildren(tree: AEGTree, parentCut: CutNode) { + for (let i = 0; i < parentCut.children.length; i++) { + if (tree.canInsert(parentCut.children[i])) { + tree.insert(parentCut.children[i]); + } + } +} + +/** + * Adds the incoming node to the tree, and, if necessary, its children + * @param tree The AEG Tree we want to inset the node into + * @param currentNode The incoming node + */ +export function reInsertNode(tree: AEGTree, currentNode: AtomNode | CutNode) { + if (currentNode instanceof CutNode && currentNode.ellipse === null) { + tree.sheet = currentNode; + } else if (tree.canInsert(currentNode)) { + tree.insert(currentNode); + if (currentNode instanceof CutNode && (currentNode as CutNode).children.length !== 0) { + readdChildren(tree, currentNode); + } + redrawTree(tree); + } +} /** * A function to calculate an ellipse between two points designated by the user. * @param original the point where the user originally clicked