minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-19 17:43:28 +04:00
parent 444ee5e3d7
commit abb3610758
2 changed files with 46 additions and 12 deletions

View File

@ -42,6 +42,49 @@ var ZOOM_SCALE = 1.2
* Helpers
*/
// Match the results of two functions
//
// If the results are not the same then print a warning.
//
// NOTE: this is here for testing.
// NOTE: this expects that none of the functions will modify the
// arguments...
// NOTE: this will return the result of the first function.
function match2(f0, f1){
return function(){
var a = f0.apply(f0, arguments)
var b = f1.apply(f1, arguments)
if(a != b){
console.warn('Result mismatch: f0:'+a+' f1:'+b)
}
return a
}
}
// Same as match2 but can take an arbitrary number of functions.
// XXX test
function matchN(){
vat funcs = arguments
return function(){
var res = []
var err = false
var r
// call everything...
for(var i=0; i < funcs.lenght; i++){
r = f0.apply(f0, arguments)
// match the results...
if(r != res[res.length-1]){
err = false
}
res.push(r)
}
if(err){
console.warn('Not all results matched:', r)
}
return res[0]
}
}
// XXX might need shift left/right indicators (later)...

View File

@ -136,6 +136,8 @@ function isBetween(a, i, lst){
// Basic liner search...
//
// NOTE: this is here for testing reasons only...
function linSearch(target, lst, check, return_position){
check = check == null ? cmp : check
@ -190,23 +192,12 @@ Array.prototype.binSearch = function(target, cmp){
}
function match(f0, f1){
return function(){
var a = f0.apply(f0, arguments)
var b = f1.apply(f1, arguments)
if(a != b){
console.warn('Result mismatch: f0:'+a+' f1:'+b)
}
return a
}
}
// Same as getImageBefore, but uses gids and searches in DATA...
//
// NOTE: this uses it's own predicate...
function getGIDBefore(gid, ribbon, search){
search = search == null ? binSearch : search
//search = search == null ? match(linSearch, binSearch) : search
//search = search == null ? match2(linSearch, binSearch) : search
ribbon = DATA.ribbons[ribbon]
var order = DATA.order