palette/median-cut.js
// separate node samples into 2 subblocks
separate node samples into 2 subblocks
separate node samples into 2 subblocks
function divideNode(node) {
    if (node.samples.length === 0)
        return null;
    var median = calcNodeMedian(node);
    var samplesA = [];
    var samplesB = [];
    for (var n = 0; n < node.samples.length; n++) {
        if ( (median.channel === "red")   && (node.samples[n].r >= median.value)
          || (median.channel === "green") && (node.samples[n].g >= median.value)
          || (median.channel === "blue")  && (node.samples[n].b >= median.value) )
             samplesA.push(node.samples[n]);
        else samplesB.push(node.samples[n]);
    }
    return [ Node(samplesA), Node(samplesB) ];
}
function divideNode ( node ) { if ( node . samples . length === 0 ) return null ; var median = calcNodeMedian ( node ) ; var samplesA = [ ] ; var samplesB = [ ] ; for ( var n = 0 ; n < node . samples . length ; n ++ ) { if ( ( median . channel === "red" ) && ( node . samples [ n ] . r >= median . value ) || ( median . channel === "green" ) && ( node . samples [ n ] . g >= median . value ) || ( median . channel === "blue" ) && ( node . samples [ n ] . b >= median . value ) ) samplesA . push ( node . samples [ n ] ) ; else samplesB . push ( node . samples [ n ] ) ; } return [ Node ( samplesA ) , Node ( samplesB ) ] ; }
separate node samples into 2 subblocks
separate node samples into 2 subblocks
// calculate median point and axis