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

public class AngleFilter {

    protected double lowerAngle;
    protected double upperAngle;


    public AngleFilter(double lowerAngle, double upperAngle) {

        this.lowerAngle = lowerAngle < -Math.PI / 2 ? lowerAngle + Math.PI : lowerAngle;
        this.upperAngle = upperAngle >= Math.PI / 2 ? upperAngle - Math.PI : upperAngle;
    }


    public boolean matches(Neighbor neighbor) {

        return matches(neighbor.getAngle());
    }


    public boolean matches(double angle) {

        if (lowerAngle <= upperAngle) {
            return lowerAngle <= angle && angle < upperAngle;
        } else {
            return lowerAngle <= angle || angle < upperAngle;
        }
    }

}