diff --git a/src/AEG/AEGTree.ts b/src/AEG/AEGTree.ts index c078fc7a..ba6a66aa 100644 --- a/src/AEG/AEGTree.ts +++ b/src/AEG/AEGTree.ts @@ -61,6 +61,7 @@ export class AEGTree { * @returns True, if the node can be inserted. Else, false */ public canInsert(incomingNode: AtomNode | CutNode): boolean { + console.log("checking can insert"); const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode); for (let i = 0; i < currentCut.children.length; i++) { if (this.overlaps(incomingNode, currentCut.children[i])) { diff --git a/src/AEG/CutNode.ts b/src/AEG/CutNode.ts index b504b515..25419b24 100644 --- a/src/AEG/CutNode.ts +++ b/src/AEG/CutNode.ts @@ -36,6 +36,7 @@ export class CutNode { public getCurrentCut(newNode: CutNode | AtomNode): CutNode { for (let i = 0; i < this.children.length; i++) { if (this.children[i] instanceof CutNode && this.children[i].containsNode(newNode)) { + console.log("current cut: " + this.children[i]); //newNode can be placed at least one layer deeper return this.getCurrentCut(this.children[i]); } diff --git a/src/AEG/Ellipse.ts b/src/AEG/Ellipse.ts index 615dca8b..41478f96 100644 --- a/src/AEG/Ellipse.ts +++ b/src/AEG/Ellipse.ts @@ -60,7 +60,10 @@ export class Ellipse { this.radiusX + ", \n" + "Vertical Radius of: " + - this.radiusY + this.radiusY + + ", \n" + + "Bounding box: " + + this.boundingBox.toString() ); } @@ -74,9 +77,10 @@ export class Ellipse { //(x, y) = new point //(h, k) = center - const p: number = + const p: number = Math.round( Math.pow(otherPoint.x - this.center.x, 2) / Math.pow(this.radiusX, 2) + - Math.pow(otherPoint.y - this.center.y, 2) / Math.pow(this.radiusY, 2); + Math.pow(otherPoint.y - this.center.y, 2) / Math.pow(this.radiusY, 2) + ); return p <= 1; @@ -106,6 +110,7 @@ export class Ellipse { } else { //check if the rectangular bounding boxes of the ellipse overlap if (this.boundingBox.overlaps((otherShape as Ellipse).boundingBox)) { + console.log("ellipse boxes overlap"); //if there is an overlap, check if points along the ellipse curve overlap //this can be done by checking if points along the curve of the other ellipse //are within this ellipse @@ -142,25 +147,6 @@ export class Ellipse { } } - /** - * An array containing the widest coordinates of the ellipse, i.e. the coordinates along the - * x-axis and y-axis of the ellipse. - * The coordinates are in clockwise order such that: - * 0 - Top most coordinate (Top along y-axis). - * 1 - Right most coordinate (Right along x-axis). - * 2 - Bottom most coordinate (Bottom along y-axis). - * 3 - Left most coordinate (Left along x-axis). - * @returns - */ - public getWidestCoordinates(): Point[] { - return [ - new Point(this.center.x, this.center.y - this.radiusY), - new Point(this.center.x + this.radiusX, this.center.y), - new Point(this.center.x, this.center.y + this.radiusY), - new Point(this.center.x - this.radiusX, this.center.y), - ]; - } - /** * Method that checks if any quadrant of another ellipse overlaps with this ellipse. * This can be done by checking if a point on the curve of the ellipse is within this ellipse. @@ -171,7 +157,6 @@ export class Ellipse { //Get the quadrant which might be overlapping with this ellipse. //To do so, check which corner of the rectangular bounding box of the other ellipse //is within this ellipse. - for (let i = 0; i < 4; i++) { if (this.containsPoint(otherEllipse.boundingBox.getCorners()[i])) { //Get the points on the curve of the ellipse in that quadrant @@ -191,50 +176,73 @@ export class Ellipse { return false; } + /** + * An array containing the widest coordinates of the ellipse, i.e. the coordinates along the + * x-axis and y-axis of the ellipse. + * The coordinates are in clockwise order such that: + * 0 - Top most coordinate (Top along y-axis). + * 1 - Right most coordinate (Right along x-axis). + * 2 - Bottom most coordinate (Bottom along y-axis). + * 3 - Left most coordinate (Left along x-axis). + * @returns + */ + public getWidestCoordinates(): Point[] { + return [ + new Point(this.center.x, this.center.y - this.radiusY), + new Point(this.center.x + this.radiusX, this.center.y), + new Point(this.center.x, this.center.y + this.radiusY), + new Point(this.center.x - this.radiusX, this.center.y), + ]; + } + /** * Method that returns the points on the curve of the ellipse in a specific quadrant * @param quadrant The quadrant which we want the points in * @returns An array of points along the curve of the ellipse */ private getQuadrantPoints(quadrant: number): Point[] { + //==========DEBUGGG========= + console.log("Getting points for: " + this + "\n" + "In quad: " + quadrant); + const points: Point[] = []; - let quadDistance = 0; + const quadDistance = this.radiusX; let curve = 1; if (quadrant === 0) { //top left quadrant points[0] = this.getWidestCoordinates()[3]; points[1] = this.getWidestCoordinates()[0]; - - quadDistance = Math.abs(points[0].x - points[1].x); } else if (quadrant === 1) { //top right quadrant points[0] = this.getWidestCoordinates()[0]; points[1] = this.getWidestCoordinates()[1]; - - quadDistance = Math.abs(points[0].x - points[1].x); } else if (quadrant === 2) { //bottom right quadrant points[0] = this.getWidestCoordinates()[1]; points[1] = this.getWidestCoordinates()[2]; - quadDistance = Math.abs(points[0].x - points[1].x); curve = -1; } else if (quadrant === 3) { //bottom left quadrant points[0] = this.getWidestCoordinates()[2]; points[1] = this.getWidestCoordinates()[3]; - quadDistance = Math.abs(points[0].x - points[1].x); curve = -1; } for (let i = 2; i < 6; i++) { - const x = points[0].x + (i - 1) * (quadDistance / 5); + let x = points[0].x; + if (curve === 1) { + x = x + (i - 1) * (quadDistance / 5); + } else { + x = x - (i - 1) * (quadDistance / 5); + } const y = this.getCurvePoint(x, curve); points[i] = new Point(x, y); } + //========DEBUGGGG======== + console.log(points); return points; }