INNER CODE UNIT · JavaScript

intersectRect

Brbb/graphql-rover · js/utils.js:103

    function intersectRect(node, point) {
        var x = node.x;
        var y = node.y;
        var dx = point.x - x;
        var dy = point.y - y;
        var w = $("#" + node.customId).attr('width') / 2;
        var h = $("#" + node.customId).attr('height') / 2;
        var sx = 0,
            sy = 0;
        if (Math.abs(dy) * w > Math.abs(dx) * h) {
            // Intersection is top or bottom of rect.
            if (dy < 0) {
                h = -h;
            }
            sx = dy === 0 ? 0 : h * dx / dy;
            sy = h;
        } else {
            // Intersection is left or right of rect.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…