Skip to content

Commit

Permalink
Merge pull request #296 from RAIRLab/blame-fix-ProofMoveUtils.ts
Browse files Browse the repository at this point in the history
Code Cleanup fix
  • Loading branch information
RyanR712 authored Dec 9, 2023
2 parents 3350920 + d8c2525 commit 6b1a3e2
Show file tree
Hide file tree
Showing 31 changed files with 334 additions and 402 deletions.
20 changes: 7 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"aegtest",
"Anusha",
"atomnode",
"buttonface",
Expand All @@ -10,6 +11,7 @@
"ICSI",
"jamesoswald",
"mosueout",
"msedge",
"npmignore",
"peaceiris",
"Peirced",
Expand All @@ -19,26 +21,18 @@
"rady",
"RAIR",
"Rensselaer",
"singlefile",
"stringification",
"styleguidelines",
"subbar",
"Subrina",
"Tiwari",
"uitest",
"viewports",
"vite",
"vitest",
"vitetest",
"wicg",
"vitest",
"xshift",
"yshift",
"ICSI",
"RAIR",
"npmignore",
"viewports",
"msedge",
"singlefile",
"aegtest",
"uitest"
"subbar",
"buttonface",
"Wireframe",
"xshift",
"yshift"
Expand Down
6 changes: 3 additions & 3 deletions src/DrawModes/AtomTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {treeContext} from "../treeContext";
import {redrawTree} from "./DrawUtils";
import {offset} from "./DragTool";
import {redrawTree} from "../SharedToolUtils/DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {legalColor, illegalColor} from "../Themes";
import {drawAtom} from "./DrawUtils";
import {drawAtom} from "../SharedToolUtils/DrawUtils";

//Setting Up Canvas
const canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById("canvas");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawAtom, cleanCanvas, redrawTree, highlightNode} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, cleanCanvas, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils";
import {legalColor} from "../Themes";
import {AEGTree} from "../AEG/AEGTree";

Expand Down
22 changes: 13 additions & 9 deletions src/DrawModes/CopyMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawAtom, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, redrawTree} from "../SharedToolUtils/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {validateChildren, drawAltered, insertChildren, alterAtom} from "./EditModeUtils";
import * as EditModeUtils from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand Down Expand Up @@ -52,12 +52,16 @@ export function copyMultiMouseMove(event: MouseEvent) {

redrawTree(treeContext.tree);
if (currentNode instanceof CutNode) {
const color = validateChildren(treeContext.tree, currentNode, moveDifference)
const color = EditModeUtils.validateChildren(
treeContext.tree,
currentNode,
moveDifference
)
? legalColor()
: illegalColor();
drawAltered(currentNode, color, moveDifference);
EditModeUtils.drawAltered(currentNode, color, moveDifference);
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);
const tempAtom: AtomNode = EditModeUtils.alterAtom(currentNode, moveDifference);
const color = treeContext.tree.canInsert(tempAtom) ? legalColor() : illegalColor();
drawAtom(tempAtom, color, true);
}
Expand All @@ -79,11 +83,11 @@ export function copyMultiMouseUp(event: MouseEvent) {
);

if (currentNode instanceof CutNode) {
if (validateChildren(treeContext.tree, currentNode, moveDifference)) {
insertChildren(currentNode, moveDifference);
if (EditModeUtils.validateChildren(treeContext.tree, currentNode, moveDifference)) {
EditModeUtils.insertChildren(currentNode, moveDifference);
}
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);
const tempAtom: AtomNode = EditModeUtils.alterAtom(currentNode, moveDifference);

if (treeContext.tree.canInsert(tempAtom)) {
treeContext.tree.insert(tempAtom);
Expand Down
6 changes: 3 additions & 3 deletions src/DrawModes/CopySingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawCut, drawAtom, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawCut, drawAtom, redrawTree} from "../SharedToolUtils/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {alterAtom, alterCut} from "./EditModeUtils";
import {alterAtom, alterCut} from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand Down
49 changes: 3 additions & 46 deletions src/DrawModes/CutTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {Point} from "../AEG/Point";
import {CutNode} from "../AEG/CutNode";
import {Ellipse} from "../AEG/Ellipse";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {offset} from "../SharedToolUtils/DragTool";
import {legalColor, illegalColor} from "../Themes";
import {drawCut, redrawTree, drawGuidelines} from "./DrawUtils";
import {drawCut, redrawTree, drawGuidelines} from "../SharedToolUtils/DrawUtils";
import {createEllipse, ellipseLargeEnough} from "../SharedToolUtils/EditModeUtils";

const showRectElm: HTMLInputElement = <HTMLInputElement>document.getElementById("showRect");
const modeElm: HTMLSelectElement = <HTMLSelectElement>document.getElementById("mode");

//The point the ellipse is initially placed.
let startingPoint: Point;
Expand Down Expand Up @@ -78,46 +78,3 @@ export function cutMouseOut() {
wasOut = true;
redrawTree(treeContext.tree);
}

/**
* A function to calculate an ellipse between two points designated by the user.
* @param original the point where the user originally clicked
* @param current the point where the user's mouse is currently located
*/
export function createEllipse(original: Point, current: Point): Ellipse {
const center: Point = new Point(
(current.x - original.x) / 2 + original.x,
(current.y - original.y) / 2 + original.y
);

const sdx = original.x - current.x;
const sdy = original.y - current.y;
const dx = Math.abs(sdx);
const dy = Math.abs(sdy);
let rx, ry: number;

if (modeElm.value === "circumscribed") {
//This inscribed ellipse solution is inspired by the discussion of radius ratios in
//https://stackoverflow.com/a/433426/6342516
const rv: number = Math.floor(center.distance(current));
ry = Math.floor(rv * (dy / dx));
rx = Math.floor(rv * (dx / dy));
} else {
rx = dx / 2;
ry = dy / 2;
}

return new Ellipse(center, rx, ry);
}

/**
* Checks to see if the given ellipse is large enough to be considered legal.
* @param ellipse The ellipse to be checked
* @returns Whether the given ellipse is large enough to be legal
*/
export function ellipseLargeEnough(ellipse: Ellipse) {
if (ellipse.radiusX > 15 && ellipse.radiusY > 15) {
return true;
}
return false;
}
6 changes: 3 additions & 3 deletions src/DrawModes/DeleteMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {redrawTree} from "./DrawUtils";
import {redrawTree} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";
import {offset} from "./DragTool";
import {highlightChildren} from "./EditModeUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {highlightChildren} from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand Down
4 changes: 2 additions & 2 deletions src/DrawModes/DeleteSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {offset} from "./DragTool";
import {drawAtom, drawCut, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";

Expand Down
26 changes: 17 additions & 9 deletions src/DrawModes/MoveMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawAtom, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {validateChildren, drawAltered, insertChildren, alterAtom} from "./EditModeUtils";
import * as EditModeUtils from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand All @@ -35,6 +35,10 @@ export function moveMultiMouseDown(event: MouseEvent) {
currentParent.remove(startingPoint);
}
legalNode = true;

// highlight the chosen node and its children in legal color to show what will be moved
redrawTree(treeContext.tree);
highlightNode(currentNode, legalColor());
} else {
legalNode = false;
}
Expand All @@ -55,12 +59,16 @@ export function moveMultiMouseMove(event: MouseEvent) {

redrawTree(treeContext.tree);
if (currentNode instanceof CutNode) {
const color = validateChildren(treeContext.tree, currentNode, moveDifference)
const color = EditModeUtils.validateChildren(
treeContext.tree,
currentNode,
moveDifference
)
? legalColor()
: illegalColor();
drawAltered(currentNode, color, moveDifference);
EditModeUtils.drawAltered(currentNode, color, moveDifference);
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);
const tempAtom: AtomNode = EditModeUtils.alterAtom(currentNode, moveDifference);
const color = treeContext.tree.canInsert(tempAtom) ? legalColor() : illegalColor();
drawAtom(tempAtom, color, true);
}
Expand All @@ -82,13 +90,13 @@ export function moveMultiMouseUp(event: MouseEvent) {
);

if (currentNode instanceof CutNode) {
if (validateChildren(treeContext.tree, currentNode, moveDifference)) {
insertChildren(currentNode, moveDifference);
if (EditModeUtils.validateChildren(treeContext.tree, currentNode, moveDifference)) {
EditModeUtils.insertChildren(currentNode, moveDifference);
} else {
treeContext.tree.insert(currentNode);
}
} else if (currentNode instanceof AtomNode) {
const tempAtom: AtomNode = alterAtom(currentNode, moveDifference);
const tempAtom: AtomNode = EditModeUtils.alterAtom(currentNode, moveDifference);

if (treeContext.tree.canInsert(tempAtom)) {
treeContext.tree.insert(tempAtom);
Expand Down
14 changes: 11 additions & 3 deletions src/DrawModes/MoveSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawCut, drawAtom, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawCut, drawAtom, redrawTree} from "../SharedToolUtils/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {alterAtom, alterCut} from "./EditModeUtils";
import {alterAtom, alterCut} from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand Down Expand Up @@ -44,6 +44,14 @@ export function moveSingleMouseDown(event: MouseEvent) {
currentNode.children = [];
}
legalNode = true;

// highlight the chosen node in legal color to show what will be moved
redrawTree(treeContext.tree);
if (currentNode instanceof AtomNode) {
drawAtom(currentNode, legalColor(), true);
} else {
drawCut(currentNode as CutNode, legalColor());
}
} else {
legalNode = false;
}
Expand Down
8 changes: 3 additions & 5 deletions src/DrawModes/ResizeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
*/

import {Point} from "../AEG/Point";
import {determineDirection} from "./DrawUtils";
import {resizeCut} from "./EditModeUtils";
import {ellipseLargeEnough, resizeCut} from "../SharedToolUtils/EditModeUtils";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "./DragTool";
import {drawCut, redrawTree} from "./DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {drawCut, redrawTree, determineDirection} from "../SharedToolUtils/DrawUtils";
import {legalColor, illegalColor} from "../Themes";
import {ellipseLargeEnough} from "./CutTool";

//The initial point the user pressed down.
let startingPoint: Point;
Expand Down
2 changes: 1 addition & 1 deletion src/ProofHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import {treeContext} from "./treeContext";
import {redrawProof} from "./DrawModes/DrawUtils";
import {redrawProof} from "./SharedToolUtils/DrawUtils";
import {ProofNode} from "./AEG/ProofNode";

/**
Expand Down
8 changes: 3 additions & 5 deletions src/ProofTools/ClearProofTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

import {treeContext} from "../treeContext";
import {cleanCanvas, highlightNode, redrawProof} from "../DrawModes/DrawUtils";
import {cleanCanvas, highlightNode, redrawProof} from "../SharedToolUtils/DrawUtils";
import {AEGTree} from "../AEG/AEGTree";
import {illegalColor} from "../Themes";
import {deleteButtons} from "../ProofHistory";
import {getCurrentProofTree} from "./ProofToolsUtils";

//The current tree in the proof chain
let currentProofTree: AEGTree;
Expand All @@ -21,10 +22,7 @@ let legalNode: boolean;
*/
export function clearProofMouseDown() {
//Get the tree of the current step
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
currentProofTree = getCurrentProofTree();

//As long as we are within the canvas, we can legally perform clear
legalNode = true;
Expand Down
12 changes: 5 additions & 7 deletions src/ProofTools/DeiterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {redrawProof} from "../DrawModes/DrawUtils";
import {redrawProof} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";
import {offset} from "../DrawModes/DragTool";
import {offset} from "../SharedToolUtils/DragTool";
import {ProofNode} from "../AEG/ProofNode";
import {AEGTree} from "../AEG/AEGTree";
import {highlightChildren} from "../DrawModes/EditModeUtils";
import {highlightChildren} from "../SharedToolUtils/EditModeUtils";
import {getCurrentProofTree} from "./ProofToolsUtils";

//The node selected with the user mouse down.
let currentNode: CutNode | AtomNode | null = null;
Expand All @@ -30,10 +31,7 @@ let currentProofTree: AEGTree;
*/
export function deiterationMouseDown(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
currentProofTree = getCurrentProofTree();
currentNode = currentProofTree.getLowestNode(currentPoint);

setLegal();
Expand Down
Loading

0 comments on commit 6b1a3e2

Please sign in to comment.