package de.frajul.endlessroll.entities.collision.geometry;

import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.collision.CollisionDetector;
import de.frajul.endlessroll.entities.tools.Ramp;

/**
 * Created by Julian on 01.12.2015.
 */
public class Triangle implements Geometry {

    //bottom right
    private Vector vertex1;
    //top right
    private Vector vertex2;
    //bottom left
    private Vector vertex3;

    public Triangle(Ramp ramp) {
        Vector vertex1 = new Vector(ramp.getRightEdge(), ramp.getBottomEdge());
        Vector vertex2 = new Vector(ramp.getRightEdge(), ramp.getTopEdge());
        Vector vertex3 = new Vector(ramp.getLeftEdge(), ramp.getBottomEdge());
        this.vertex1 = vertex1;
        this.vertex2 = vertex2;
        this.vertex3 = vertex3;
    }

    public Triangle(Vector vertex1, Vector vertex2, Vector vertex3) {
        this.vertex1 = vertex1;
        this.vertex2 = vertex2;
        this.vertex3 = vertex3;
    }

    public Vector getVertex1() {
        return vertex1;
    }

    public Vector getVertex2() {
        return vertex2;
    }

    public Vector getVertex3() {
        return vertex3;
    }

    @Override
    public boolean isCollisionWithCircle(Circle circle, CollisionDetector collisionDetector) {
        return collisionDetector.isCircleTriangleCollision(circle, this);
    }

    @Override
    public boolean isCollisionWithQuad(Quad quad, CollisionDetector collisionDetector) {
        return collisionDetector.isQuadTriangleCollision(quad, this);
    }

    @Override
    public boolean isCollisionWithTriangle(Triangle triangle, CollisionDetector collisionDetector) {
        return collisionDetector.isTriangleTriangleCollision(this, triangle);
    }

}
