/**
 * @file 求boundingbox和线段的关系
 * @author mengke01(kekee000@gmail.com)
 */

define(
    function (require) {
        var isPointInBound = require('./util').isPointInBound;
        var isSegmentCross = require('./isSegmentCross');

        /**
         * 求boundingbox和线段的关系
         *
         * @param {Object} bound bounding box
         * @param {Object} s0 线段点1
         * @param {Object} s1 线段点2
         * @return {boolean} 是否相交
         */
        function isBoundingBoxSegmentCross(bound, s0, s1) {
            if (isPointInBound(bound, s0) || isPointInBound(bound, s1)) {
                return true;
            }

            if (
                isSegmentCross(bound, {x: bound.x, y: bound.y + bound.height}, s0, s1)
                || isSegmentCross(bound, {x: bound.x + bound.width, y: bound.y}, s0, s1)
                || isSegmentCross(
                    {x: bound.x + bound.width, y: bound.y},
                    {x: bound.x + bound.width, y: bound.y + bound.height},
                    s0, s1)
                || isSegmentCross(
                    {x: bound.x, y: bound.y + bound.height},
                    {x: bound.x + bound.width, y: bound.y + bound.height},
                    s0, s1)
            ) {
                return true;
            }

            return false;
        }

        return isBoundingBoxSegmentCross;
    }
);
