From 6298b331e612381bcc8f9e0f5a9fd4042b360a30 Mon Sep 17 00:00:00 2001 From: Nicolas Bornand Date: Sun, 11 May 2014 12:44:34 +0200 Subject: Merge origin/master Conflicts: app/js/services.js --- app/js/services.js | 53 +++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 79d4c40..9913856 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -9,52 +9,25 @@ app.service('pathService', function() { var dy = point1.y - point2.y; return Math.sqrt(dx * dx + dy * dy); }, - computePlaylist: function(songList, constrainList, duration) { + computePlaylist: function(songList, line, duration) { //compute distances from the constrain path + console.log('length',line.length); - var songListCopy = songList.slice(0); - var maxDistOverall = Number.MIN_VALUE; - angular.forEach(songListCopy, function(song){ + var threshold = 60; + angular.forEach(songList, function(song){ song.selected = false; - song.minDist = Number.MAX_VALUE; - for(var i=0; i maxDistOverall){ - maxDistOverall = song.minDist; - } }); - //select the songs - var selection = []; - var tuning = .5; - angular.forEach(songListCopy, function(song){ - song.rand = /*(tuning + tuning*Math.random())*/song.minDist; - }); - songListCopy.sort(function(a,b){return a.rand-b.rand;}); - //take from the sorted list util we reach the desired duration - while(duration > 0 && songListCopy.length > 0){ - var removed = songListCopy.splice(0, 1); - selection.push(removed[0]); - duration -= 10; - removed[0].selected = true; - } - selection.sort(function(a,b){ return a.closestIndex-b.closestIndex;}); - - //clean points - angular.forEach(songList, function(song) { - delete song.minDist; - delete song.closest; - delete song.closestIndex; - delete song.rand; + var selection = []; + angular.forEach(line, function(point){ + angular.forEach(songList, function(song){ + var d = self.dist(song, point); + if(d < threshold && song.selected !== true){ + selection.push(song); + song.selected = true; + } + }); }); - return selection; } }; -- cgit v1.2.3