function intersectsSegment(segment, horizontal) {
            // ('x', 'y', 'height', 'width') or ('y', 'x', 'width', 'height')
            var par1, par2, length1, length2;
            // Parameters of projections of both segment and rectangle to the more
            // important axis.
            var segmentStart, segmentEnd, rectangleStart, rectangleEnd;

            if (!(segment instanceof Malakh.Segment)) {
                console.error('Function intersetsSegment expects a Malakh.Segment instance as a parameter');
                return false;
            }

            if (horizontal) {
                par1 = 'x';
                par2 = 'y';
                length1 = 'width';
                length2 = 'height';
            } else { // We convert everything to the horizontal case (further comments assume horizontal case).
                par1 = 'y';
                par2 = 'x';
                length1 = 'height';
                length2 = 'width';
            }
            if (segment[par2 + '1'] < this[par2] || segment[par2 + '1'] > this[par2] + this[length2]) {
                // The segment is above or below the rectangle.
                return false;
            }

            // We check the other dimension.
            segmentStart = segment[par1 + '1'];
            segmentEnd = segment[par1 + '2'];
            rectangleStart = this[par1];
            rectangleEnd = this[par1] + this[length1];

            return ((segmentStart > rectangleStart || segmentEnd > rectangleStart) &&
                (segmentStart < rectangleEnd || segmentEnd < rectangleEnd));
        }
/**
         * Checks if the rectangle intersects a horizontal/vertical segment.
         * WARNING: it gives incorrect results for other kinds of segments!
         *
         * @param {Malakh.Segment} segment
         * @param {boolean} horizontal Do we check for a horizontal intersection?
         * @return {boolean}
         */
Checks if the rectangle intersects a horizontal/vertical segment.
WARNING: it gives incorrect results for other kinds of segments!

@param {Malakh.Segment} segment
@param {boolean} horizontal Do we check for a horizontal intersection.
@return {boolean}
Checks if the rectangle intersects a horizontal / vertical segment . WARNING : it gives incorrect results for other kinds of segments! @param { Malakh . Segment } segment @param { boolean } horizontal Do we check for a horizontal intersection . @return { boolean }
function intersectsSegment(segment, horizontal) {
            var par1, par2, length1, length2;
            var segmentStart, segmentEnd, rectangleStart, rectangleEnd;
            if (!(segment instanceof Malakh.Segment)) {
                console.error('Function intersetsSegment expects a Malakh.Segment instance as a parameter');
                return false;
            }
            if (horizontal) {
                par1 = 'x';
                par2 = 'y';
                length1 = 'width';
                length2 = 'height';
            } else { 
                par1 = 'y';
                par2 = 'x';
                length1 = 'height';
                length2 = 'width';
            }
            if (segment[par2 + '1'] < this[par2] || segment[par2 + '1'] > this[par2] + this[length2]) {
                return false;
            }
            segmentStart = segment[par1 + '1'];
            segmentEnd = segment[par1 + '2'];
            rectangleStart = this[par1];
            rectangleEnd = this[par1] + this[length1];
            return ((segmentStart > rectangleStart || segmentEnd > rectangleStart) &&
                (segmentStart < rectangleEnd || segmentEnd < rectangleEnd));
        }
function intersectsSegment ( segment , horizontal ) { var par1 , par2 , length1 , length2 ; var segmentStart , segmentEnd , rectangleStart , rectangleEnd ; if ( ! ( segment instanceof Malakh . Segment ) ) { console . error ( 'Function intersetsSegment expects a Malakh.Segment instance as a parameter' ) ; return false ; } if ( horizontal ) { par1 = 'x' ; par2 = 'y' ; length1 = 'width' ; length2 = 'height' ; } else { par1 = 'y' ; par2 = 'x' ; length1 = 'height' ; length2 = 'width' ; } if ( segment [ par2 + '1' ] < this [ par2 ] || segment [ par2 + '1' ] > this [ par2 ] + this [ length2 ] ) { return false ; } segmentStart = segment [ par1 + '1' ] ; segmentEnd = segment [ par1 + '2' ] ; rectangleStart = this [ par1 ] ; rectangleEnd = this [ par1 ] + this [ length1 ] ; return ( ( segmentStart > rectangleStart || segmentEnd > rectangleStart ) && ( segmentStart < rectangleEnd || segmentEnd < rectangleEnd ) ) ; }
Checks if the rectangle intersects a horizontal/vertical segment.
Checks if the rectangle intersects a horizontal / vertical segment .
// ('x', 'y', 'height', 'width') or ('y', 'x', 'width', 'height') // Parameters of projections of both segment and rectangle to the more // important axis. // We convert everything to the horizontal case (further comments assume horizontal case). // The segment is above or below the rectangle. // We check the other dimension.