Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"I Want Hue" online tool "diff" mode bug #32

Open
EricBerridge opened this issue Feb 5, 2019 · 0 comments
Open

"I Want Hue" online tool "diff" mode bug #32

EricBerridge opened this issue Feb 5, 2019 · 0 comments

Comments

@EricBerridge
Copy link

EricBerridge commented Feb 5, 2019

The ns.diffSort function has a bug. The indicated code should be inside the loop above it. Otherwise, the loop above simply recomputes "d" several times and the only iteration has any subsequent effect.

ns.diffSort = function(colorsToSort, distanceType){
	// Sort
	var diffColors = [colorsToSort.shift()];
	while(colorsToSort.length>0){
		var index = -1;
		var maxDistance = -1;
		for(candidate_index=0; candidate_index<colorsToSort.length; candidate_index++){
			var d = Infinity;
			for(i=0; i<diffColors.length; i++){
				var colorA = colorsToSort[candidate_index].lab();
				var colorB = diffColors[i].lab();
				var d = ns.getColorDistance(colorA, colorB, distanceType);
				/* *** Code below belongs here *** */
			}
                            // **** BEGIN
			if(d > maxDistance){
				maxDistance = d;
				index = candidate_index;
			}
                            //**** END
		}
		var color = colorsToSort[index];
		diffColors.push(color);
		colorsToSort = colorsToSort.filter(function(c,i){return i!=index;});
	}
	return diffColors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant