package engine.CollisionEngine;

import engine.objects.Building;

import java.awt.geom.Line2D;

import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

public class Mesh {
    public ArrayList<Triangle> triangles;
    public ArrayList<Line2D> BoundingLines;
    public Rectangle2D boundsRect;
    public float maxY;
    public float minY;
    public Building parentBuilding;

    public boolean BoundsCollides(Line2D line){
        for(Line2D side : BoundingLines)
            if(side.intersectsLine(line))
                return true;

        return false;
    }

    public boolean MeshCollides(Line2D line, float charHeight, float charY){

        //check if movement path intersects this mesh
        if(boundsRect == null){
            return false;
        }

        if(!line.intersects(boundsRect) && !boundsRect.contains(line.getP1()) && !boundsRect.contains(line.getP2()))
            return false;


        //check to see if character is under or over the mesh
        float head = charY + charHeight;
        if(head < this.minY || charY > this.maxY)
            return false;

        //check if any triangles intersect the movement path
        for(Triangle tri : triangles)
            if(tri.collides(line))
                return true;

        //characters movement path did not intersect this mesh
        return false;
    }
}