package com.knecon.fforesight.service.layoutparser.processor.docstrum.model;

import java.awt.geom.Rectangle2D;

import lombok.Data;

@Data
public abstract class BoundingBox {

    private Rectangle2D bBox;


    public double getX() {

        return bBox.getX();
    }


    public double getY() {

        return bBox.getY();
    }


    public double getWidth() {

        return bBox.getWidth();
    }


    public double getHeight() {

        return bBox.getHeight();
    }


    public double getArea() {

        return (bBox.getHeight() * bBox.getWidth());
    }


    public boolean contains(Rectangle2D contained, double tolerance) {

        return bBox.getX() <= contained.getX() + tolerance && bBox.getY() <= contained.getY() + tolerance && bBox.getX() + bBox.getWidth() >= contained.getX() + contained.getWidth() - tolerance && bBox.getY() + bBox.getHeight() >= contained.getY() + contained.getHeight() - tolerance;
    }


    public boolean intersectsY(BoundingBox other) {

        return this.getBBox().getMinY() <= other.getBBox().getMaxY() && this.getBBox().getMaxY() >= other.getBBox().getMinY();
    }

}
