src/lib/QrScannerWorker.js
function reorderFinderPatterns(pattern1, pattern2, pattern3) {
        // Find distances between pattern centers
        const oneTwoDistance = distance(pattern1, pattern2);
        const twoThreeDistance = distance(pattern2, pattern3);
        const oneThreeDistance = distance(pattern1, pattern3);
        let bottomLeft;
        let topLeft;
        let topRight;
        // Assume one closest to other two is B; A and C will just be guesses at first
        if (twoThreeDistance >= oneTwoDistance && twoThreeDistance >= oneThreeDistance) {
            [bottomLeft, topLeft, topRight] = [pattern2, pattern1, pattern3];
        }
        else if (oneThreeDistance >= twoThreeDistance && oneThreeDistance >= oneTwoDistance) {
            [bottomLeft, topLeft, topRight] = [pattern1, pattern2, pattern3];
        }
        else {
            [bottomLeft, topLeft, topRight] = [pattern1, pattern3, pattern2];
        }
        // Use cross product to figure out whether bottomLeft (A) and topRight (C) are correct or flipped in relation to topLeft (B)
        // This asks whether BC x BA has a positive z component, which is the arrangement we want. If it's negative, then
        // we've got it flipped around and should swap topRight and bottomLeft.
        if (((topRight.x - topLeft.x) * (bottomLeft.y - topLeft.y)) - ((topRight.y - topLeft.y) * (bottomLeft.x - topLeft.x)) < 0) {
            [bottomLeft, topRight] = [topRight, bottomLeft];
        }
        return { bottomLeft, topLeft, topRight };
    }
function reorderFinderPatterns(pattern1, pattern2, pattern3) {
        // Find distances between pattern centers
        const oneTwoDistance = distance(pattern1, pattern2);
        const twoThreeDistance = distance(pattern2, pattern3);
        const oneThreeDistance = distance(pattern1, pattern3);
        let bottomLeft;
        let topLeft;
        let topRight;
        // Assume one closest to other two is B; A and C will just be guesses at first
        if (twoThreeDistance >= oneTwoDistance && twoThreeDistance >= oneThreeDistance) {
            [bottomLeft, topLeft, topRight] = [pattern2, pattern1, pattern3];
        }
        else if (oneThreeDistance >= twoThreeDistance && oneThreeDistance >= oneTwoDistance) {
            [bottomLeft, topLeft, topRight] = [pattern1, pattern2, pattern3];
        }
        else {
            [bottomLeft, topLeft, topRight] = [pattern1, pattern3, pattern2];
        }
        // Use cross product to figure out whether bottomLeft (A) and topRight (C) are correct or flipped in relation to topLeft (B)
        // This asks whether BC x BA has a positive z component, which is the arrangement we want. If it's negative, then
        // we've got it flipped around and should swap topRight and bottomLeft.
        if (((topRight.x - topLeft.x) * (bottomLeft.y - topLeft.y)) - ((topRight.y - topLeft.y) * (bottomLeft.x - topLeft.x)) < 0) {
            [bottomLeft, topRight] = [topRight, bottomLeft];
        }
        return { bottomLeft, topLeft, topRight };
    }
function reorderFinderPatterns ( pattern1 , pattern2 , pattern3 ) { // Find distances between pattern centers const oneTwoDistance = distance ( pattern1 , pattern2 ) ; const twoThreeDistance = distance ( pattern2 , pattern3 ) ; const oneThreeDistance = distance ( pattern1 , pattern3 ) ; let bottomLeft ; let topLeft ; let topRight ; // Assume one closest to other two is B; A and C will just be guesses at first if ( twoThreeDistance >= oneTwoDistance && twoThreeDistance >= oneThreeDistance ) { [ bottomLeft , topLeft , topRight ] = [ pattern2 , pattern1 , pattern3 ] ; } else if ( oneThreeDistance >= twoThreeDistance && oneThreeDistance >= oneTwoDistance ) { [ bottomLeft , topLeft , topRight ] = [ pattern1 , pattern2 , pattern3 ] ; } else { [ bottomLeft , topLeft , topRight ] = [ pattern1 , pattern3 , pattern2 ] ; } // Use cross product to figure out whether bottomLeft (A) and topRight (C) are correct or flipped in relation to topLeft (B) // This asks whether BC x BA has a positive z component, which is the arrangement we want. If it's negative, then // we've got it flipped around and should swap topRight and bottomLeft. if ( ( ( topRight . x - topLeft . x ) * ( bottomLeft . y - topLeft . y ) ) - ( ( topRight . y - topLeft . y ) * ( bottomLeft . x - topLeft . x ) ) < 0 ) { [ bottomLeft , topRight ] = [ topRight , bottomLeft ] ; } return { bottomLeft , topLeft , topRight } ; }
Takes three finder patterns and organizes them into topLeft, topRight, etc
Takes three finder patterns and organizes them into topLeft topRight etc