mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
fixed sort with overflow -- did not acount for min/max gap with overflow...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
47a56706bc
commit
170cfc7242
@ -276,9 +276,7 @@ module.SortActions = actions.Actions({
|
|||||||
b = this.images.getImageNameLeadingSeq(b)
|
b = this.images.getImageNameLeadingSeq(b)
|
||||||
b = typeof(b) == typeof('str') ? 0 : b
|
b = typeof(b) == typeof('str') ? 0 : b
|
||||||
|
|
||||||
return a - b
|
return a - b } },
|
||||||
}
|
|
||||||
},
|
|
||||||
'name-sequence': function(){
|
'name-sequence': function(){
|
||||||
return function(a, b){
|
return function(a, b){
|
||||||
a = this.images.getImageNameSeq(a)
|
a = this.images.getImageNameSeq(a)
|
||||||
@ -286,12 +284,11 @@ module.SortActions = actions.Actions({
|
|||||||
b = this.images.getImageNameSeq(b)
|
b = this.images.getImageNameSeq(b)
|
||||||
b = typeof(b) == typeof('str') ? 0 : b
|
b = typeof(b) == typeof('str') ? 0 : b
|
||||||
|
|
||||||
return a - b
|
return a - b } },
|
||||||
}
|
|
||||||
},
|
|
||||||
// NOTE: this will actually sort twice, stage one build sort index and
|
// NOTE: this will actually sort twice, stage one build sort index and
|
||||||
// second stage is a O(n) lookup cmp...
|
// second stage is a O(n) lookup cmp...
|
||||||
// XXX not sure if this is the best way to go...
|
// XXX not sure if this is the best way to go...
|
||||||
|
// XXX add ability to rotate sections...
|
||||||
'name-sequence-overflow': function(){
|
'name-sequence-overflow': function(){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
@ -304,44 +301,42 @@ module.SortActions = actions.Actions({
|
|||||||
.map(function(gid){
|
.map(function(gid){
|
||||||
return [gid, that.images.getImageNameSeq(gid)] })
|
return [gid, that.images.getImageNameSeq(gid)] })
|
||||||
// keep only items with actual sequence numbers...
|
// keep only items with actual sequence numbers...
|
||||||
.filter(function(e){
|
.filter(function([_, s]){
|
||||||
return typeof(e[1]) == typeof(123) })
|
return typeof(s) == typeof(123) })
|
||||||
// sort by sequence...
|
// sort by sequence...
|
||||||
.sort(function(a, b){
|
.sort(function([x, a], [y, b]){
|
||||||
a = a[1]
|
return a - b })
|
||||||
a = typeof(a) == typeof('str') ? 0 : a
|
|
||||||
b = b[1]
|
|
||||||
b = typeof(b) == typeof('str') ? 0 : b
|
|
||||||
|
|
||||||
return a - b
|
|
||||||
})
|
|
||||||
// find largest gaps...
|
// find largest gaps...
|
||||||
.map(function(e, i, lst){
|
.map(function(e, i, lst){
|
||||||
var c = (lst[i+1] || e)[1] - e[1]
|
var c = (lst[i+1] || e)[1] - e[1]
|
||||||
|
//var c = (lst[i+1] || lst[0])[1] - e[1]
|
||||||
if(c > l){
|
if(c > l){
|
||||||
l = c
|
l = c
|
||||||
gap = i
|
gap = i }
|
||||||
}
|
return e })
|
||||||
return e
|
|
||||||
})
|
// calc gap between min/max accounting for overflow...
|
||||||
|
var a = lst[0][1]
|
||||||
|
var b = lst.slice(-1)[0][1]
|
||||||
|
var c = a + ( 10 ** (''+b).length ) - b - 2
|
||||||
|
if(c > l){
|
||||||
|
l = c
|
||||||
|
gap = -1 }
|
||||||
|
|
||||||
// rotate index blocks...
|
// rotate index blocks...
|
||||||
if(l > 1){
|
if(l > 1 && gap >= 0){
|
||||||
var tail = lst.splice(gap+1, lst.length)
|
var tail = lst.splice(gap+1, lst.length)
|
||||||
lst = tail.concat(lst)
|
lst = tail.concat(lst) }
|
||||||
}
|
|
||||||
|
|
||||||
// build the actual lookup table...
|
// build the actual lookup table...
|
||||||
var index = {}
|
var index = {}
|
||||||
lst.forEach(function(e, i){
|
lst.forEach(function(e, i){
|
||||||
index[e[0]] = i
|
index[e[0]] = i })
|
||||||
})
|
|
||||||
|
|
||||||
// return the lookup cmp...
|
// return the lookup cmp...
|
||||||
return function(a, b){
|
return function(a, b){
|
||||||
// XXX is 0 as alternative here the correct way to go???
|
// XXX is 0 as alternative here the correct way to go???
|
||||||
return (index[a] || 0) - (index[b] || 0) }
|
return (index[a] || 0) - (index[b] || 0) } },
|
||||||
},
|
|
||||||
|
|
||||||
// Keep image order in each ribbon the same but sort ribbons (i.e.
|
// Keep image order in each ribbon the same but sort ribbons (i.e.
|
||||||
// images within ribbons) in ribbon order...
|
// images within ribbons) in ribbon order...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user