src/Operation/Interval/Intersection.php
public function compute(Interval $first, Interval $second): ?Interval
    {
        if ($first->isNeighborBefore($second)) {
            return new Interval(
                $first->getEnd()->changeSide(),
                $second->getStart()->changeSide()
            );
        }

        if ($first->isNeighborAfter($second)) {
            return new Interval(
                $second->getEnd()->changeSide(),
                $first->getStart()->changeSide()
            );
        }

        if (!$first->overlaps($second)) {
            return null;
        }

        return new Interval(
            $first->getStart()->greaterThan($second->getStart()) ? $first->getStart() : $second->getStart(),
            $first->getEnd()->lessThan($second->getEnd()) ? $first->getEnd() : $second->getEnd()
        );
    }
public function compute(Interval $first, Interval $second): ?Interval
    {
        if ($first->isNeighborBefore($second)) {
            return new Interval(
                $first->getEnd()->changeSide(),
                $second->getStart()->changeSide()
            );
        }

        if ($first->isNeighborAfter($second)) {
            return new Interval(
                $second->getEnd()->changeSide(),
                $first->getStart()->changeSide()
            );
        }

        if (!$first->overlaps($second)) {
            return null;
        }

        return new Interval(
            $first->getStart()->greaterThan($second->getStart()) ? $first->getStart() : $second->getStart(),
            $first->getEnd()->lessThan($second->getEnd()) ? $first->getEnd() : $second->getEnd()
        );
    }
public function compute ( Interval $ first , Interval $ second ) : ? Interval { if ( $ first -> isNeighborBefore ( $ second ) ) { return new Interval ( $ first -> getEnd ( ) -> changeSide ( ) , $ second -> getStart ( ) -> changeSide ( ) ) ; } if ( $ first -> isNeighborAfter ( $ second ) ) { return new Interval ( $ second -> getEnd ( ) -> changeSide ( ) , $ first -> getStart ( ) -> changeSide ( ) ) ; } if ( ! $ first -> overlaps ( $ second ) ) { return null ; } return new Interval ( $ first -> getStart ( ) -> greaterThan ( $ second -> getStart ( ) ) ? $ first -> getStart ( ) : $ second -> getStart ( ) , $ first -> getEnd ( ) -> lessThan ( $ second -> getEnd ( ) ) ? $ first -> getEnd ( ) : $ second -> getEnd ( ) ) ; }
Compute the intersection of two intervals. Exp

|_________________|

∩
|_________________|

=
|_____|

@param Interval $first
@param Interval $second
@return Interval
@throws \InvalidArgumentException
@throws \UnexpectedValueException
@throws \RangeException
Compute the intersection of two intervals . Exp