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) {

        if (lowerAngle <= upperAngle) {
            return lowerAngle <= neighbor.getAngle() && neighbor.getAngle() < upperAngle;
        } else {
            return lowerAngle <= neighbor.getAngle() || neighbor.getAngle() < upperAngle;
        }
    }

}