Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

105 divergent overlaps implementations #108

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"cSpell.words": [
"Anusha",
"atomnode",
"hasmousedown",
"Huda",
"jamesoswald",
"mosueout",
Expand Down
45 changes: 23 additions & 22 deletions src/AEG/AEGTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export class AEGTree {
sheet: CutNode;

public constructor(sheet?: CutNode) {
this.sheet = sheet ?? new CutNode();
this.sheet.ellipse = null;
this.sheet = sheet ?? new CutNode(null);
}

/**
Expand All @@ -29,24 +28,24 @@ export class AEGTree {
* @returns True, if the structure is structurally consistent. Else, false.
*/
private verifyAEG(currentCut: CutNode): boolean {
for (let i = 0; i < currentCut.children.length; i++) {
for (let i = 0; i < currentCut.Children.length; i++) {
AnushaTiwari5 marked this conversation as resolved.
Show resolved Hide resolved
//Check that all children, in this level, are in currentCut
if (!currentCut.containsNode(currentCut.children[i])) {
if (!currentCut.containsNode(currentCut.Children[i])) {
return false;
}

//Check for overlaps on the same level
for (let j = i + 1; j < currentCut.children.length; j++) {
if (this.overlaps(currentCut.children[i], currentCut.children[j])) {
for (let j = i + 1; j < currentCut.Children.length; j++) {
if (this.overlaps(currentCut.Children[i], currentCut.Children[j])) {
return false;
}
}
}
for (let i = 0; i < currentCut.children.length; i++) {
for (let i = 0; i < currentCut.Children.length; i++) {
//Check one level deeper if the child is a CutNode. Recursive case
if (
currentCut.children[i] instanceof CutNode &&
!this.verifyAEG(currentCut.children[i] as CutNode)
currentCut.Children[i] instanceof CutNode &&
!this.verifyAEG(currentCut.Children[i] as CutNode)
) {
return false;
}
Expand All @@ -62,8 +61,8 @@ export class AEGTree {
*/
public canInsert(incomingNode: AtomNode | CutNode): boolean {
const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode);
for (let i = 0; i < currentCut.children.length; i++) {
if (this.overlaps(incomingNode, currentCut.children[i])) {
for (let i = 0; i < currentCut.Children.length; i++) {
if (this.overlaps(incomingNode, currentCut.Children[i])) {
return false;
}
}
Expand All @@ -81,14 +80,14 @@ export class AEGTree {
}

const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode);
const originalChildren: (AtomNode | CutNode)[] = [...currentCut.children];
currentCut.children.push(incomingNode);
const originalChildren: (AtomNode | CutNode)[] = [...currentCut.Children];
currentCut.Child = incomingNode;

if (incomingNode instanceof CutNode) {
for (let i = 0; i < originalChildren.length; i++) {
if (incomingNode.containsNode(originalChildren[i])) {
incomingNode.children.push(originalChildren[i]);
currentCut.children = currentCut.children.splice(i, 1);
incomingNode.Child = originalChildren[i];
currentCut.Children.splice(i, 1);
}
}
}
Expand All @@ -115,21 +114,23 @@ export class AEGTree {

if (incomingNode instanceof AtomNode) {
if (otherNode instanceof AtomNode) {
return (incomingNode as AtomNode).rect.overlaps((otherNode as AtomNode).rect);
return (incomingNode as AtomNode).Rectangle.overlaps(
(otherNode as AtomNode).Rectangle
);
} else {
//the case where otherNode is the sheet is handled in canInsert()
//and all child.ellipse[i] will never be null. this is the reason for ! below

ellipse1 = (otherNode as CutNode).ellipse!;
return (incomingNode as AtomNode).rect.overlaps(ellipse1);
ellipse1 = (otherNode as CutNode).Ellipse!;
return (incomingNode as AtomNode).Rectangle.overlaps(ellipse1);
}
} else {
if (otherNode instanceof AtomNode) {
ellipse1 = (incomingNode as CutNode).ellipse!;
return ellipse1.overlaps((otherNode as AtomNode).rect);
ellipse1 = (incomingNode as CutNode).Ellipse!;
return ellipse1.overlaps((otherNode as AtomNode).Rectangle);
} else {
ellipse1 = (incomingNode as CutNode).ellipse!;
ellipse2 = (otherNode as CutNode).ellipse!;
ellipse1 = (incomingNode as CutNode).Ellipse!;
ellipse2 = (otherNode as CutNode).Ellipse!;
return ellipse1.overlaps(ellipse2);
}
AnushaTiwari5 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading