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

Divergent Overlaps Implementations #105

Closed
James-Oswald opened this issue Oct 9, 2023 · 0 comments · Fixed by #108
Closed

Divergent Overlaps Implementations #105

James-Oswald opened this issue Oct 9, 2023 · 0 comments · Fixed by #108
Assignees
Labels
Bug Something isn't working. Rightmost number in semantic versioning required This feature is required to be implemented by the current implementation team
Milestone

Comments

@James-Oswald
Copy link
Member

We have divergent overlaps implementations causing issues.
in elipse.ts

    public overlaps(otherShape: Rectangle | Ellipse): boolean {
        if (otherShape instanceof Rectangle) {
            for (let i = 0; i < 4; i++) {
                if (this.containsPoint(otherShape.getCorners()[i])) {
                    return true;
                }
            }

            return false;
        } else {
            //check if the rectangular bounding boxes of the ellipse overlap
            if (
                this.boundingBox.overlaps((otherShape as Ellipse).boundingBox) ||
                //this.boundingBox.containsShape((otherShape as Ellipse).boundingBox) ||
                (otherShape as Ellipse).boundingBox.containsShape(this.boundingBox)
            ) {
                //return true;
                //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 this ellipse
                //are within the other ellipse
                const points: Point[] = this.getEllipsePoints();
                for (let i = 0; i < points.length; i++) {
                    if (otherShape.containsPoint(points[i])) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

and in rectangle.ts

    public overlaps(otherShape: Rectangle | Ellipse): boolean {
        if (otherShape instanceof Rectangle) {
            return this.edgesOverlap(otherShape);
        } else if (otherShape instanceof Ellipse) {
            for (let i = 0; i < 4; i++) {
                if (otherShape.containsPoint(this.getCorners()[i])) {
                    return true;
                }
            }
            return false;
        } else {
            throw Error("Invalid Shape passed to overlaps, must be a Rectangle | Ellipse");
        }
    }

elipse.overlaps(rectangle) and rectangle.overlaps(ellipse) should ALWAYS return the same thing
but clearly, they don't due to the fact we have completely deferent implementations.
You should move ALL of this logic to a single helper function (probably in a new file, AEGUtils or something) overlaps(s1 : Rectangle | Ellipse, s2 : Rectangle | Ellipse) that both methods call.

@James-Oswald James-Oswald added Bug Something isn't working. Rightmost number in semantic versioning required This feature is required to be implemented by the current implementation team labels Oct 9, 2023
@James-Oswald James-Oswald added this to the Milestone 5: Demo 2 milestone Oct 9, 2023
@AnushaTiwari5 AnushaTiwari5 linked a pull request Oct 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working. Rightmost number in semantic versioning required This feature is required to be implemented by the current implementation team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants