-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Skip LODs #5128
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
Skip LODs #5128
Changes from all commits
d999610
45913ac
c2ad8b0
f464eb1
ac03884
aa50e12
0674041
f5c113e
28f41e9
096c573
448803e
cb4fc4a
fba48f0
d1b1ae8
dbb01f9
a676c6d
be544d5
a2c3392
2231dbc
6970362
82106de
85708d2
bc67e97
d0fa347
8e522f3
e8d8d9e
7b1d584
39f51db
6dd4001
13062a5
05b4ac4
e1b614b
6a64a37
7cf0c24
f4c81b5
fcf34b2
d7783ad
a1bd576
5cf1fcf
77482c0
3152070
77ee9ee
a3fb482
f61bbee
4b67949
cfb7bdd
8815a39
7922fb7
0c7e216
67ea821
0e14df7
3da8d0f
30d8b0d
591ee4f
2d1089c
de402ba
0c85ebf
1cf00aa
4e6bcad
5bdfbe1
2dcd2a5
f092cd7
26ae8e8
6978101
849bf46
3285f4a
2923d84
6b04a59
2fa1588
dbe10de
fd6f891
07cd0ea
143188c
6322fc4
8b45f77
a7e34c1
8501979
273fb43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
/*global define*/ | ||
define([ | ||
'./Check', | ||
'./defaultValue', | ||
'./defined', | ||
'./defineProperties' | ||
], function( | ||
Check, | ||
defaultValue, | ||
defined, | ||
defineProperties) { | ||
'use strict'; | ||
|
||
/** | ||
* @alias Heap | ||
* @constructor | ||
* @private | ||
* | ||
* @param {Function} comparator The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index. | ||
*/ | ||
function Heap(comparator) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.defined('comparator', comparator); | ||
//>>includeEnd('debug'); | ||
|
||
this._comparator = comparator; | ||
this._data = []; | ||
this._length = 0; | ||
this._maximumSize = 0; | ||
} | ||
|
||
defineProperties(Heap.prototype, { | ||
/** | ||
* Gets the internal data in the heap. | ||
* | ||
* @memberof Heap.prototype | ||
* | ||
* @type {Array} | ||
* @readonly | ||
*/ | ||
data : { | ||
get : function() { | ||
return this._data; | ||
} | ||
}, | ||
|
||
/** | ||
* Gets the length of the heap. | ||
* | ||
* @memberof Heap.prototype | ||
* | ||
* @type {Number} | ||
* @readonly | ||
*/ | ||
length : { | ||
get : function() { | ||
return this._length; | ||
} | ||
}, | ||
|
||
/** | ||
* Gets and sets the maximum size of the heap. | ||
* | ||
* @memberof Heap.prototype | ||
* | ||
* @type {Number} | ||
*/ | ||
maximumSize : { | ||
get: function() { | ||
return this._maximumSize; | ||
}, | ||
|
||
set: function(value) { | ||
this._maximumSize = value; | ||
if (this._length > this._maximumSize && this._maximumSize > 0) { | ||
this._length = this._maximumSize; | ||
this._data.length = this._maximumSize; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
function swap(data, a, b) { | ||
var temp = data[a]; | ||
data[a] = data[b]; | ||
data[b] = temp; | ||
} | ||
|
||
/** | ||
* Resizes the internal array of the heap. | ||
* | ||
* @param {Number} [length] The length to resize internal array to. Defaults to the current size of the heap. | ||
*/ | ||
Heap.prototype.reserve = function(length) { | ||
length = defaultValue(length, this._length); | ||
this._data.length = length; | ||
}; | ||
|
||
/** | ||
* Heapify. Update the heap so that index and all descendants satisfy the heap property. | ||
* | ||
* @param {Number} index The starting index to heapify from. | ||
*/ | ||
Heap.prototype.heapify = function(index) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number.greaterThanOrEquals('index', index, 0); | ||
//>>includeEnd('debug'); | ||
|
||
var length = this._length; | ||
var comparator = this._comparator; | ||
var data = this._data; | ||
var candidate = -1; | ||
|
||
while (true) { | ||
var right = 2 * (index + 1); | ||
var left = right - 1; | ||
|
||
if (left < length && comparator(data[left], data[index]) < 0) { | ||
candidate = left; | ||
} else { | ||
candidate = index; | ||
} | ||
|
||
if (right < length && comparator(data[right], data[candidate]) < 0) { | ||
candidate = right; | ||
} | ||
if (candidate !== index) { | ||
swap(data, candidate, index); | ||
|
||
index = candidate; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
if (this._length > this._maximumSize && this._maximumSize > 0) { | ||
this._length = this._maximumSize; | ||
this._data.length = this._maximumSize; | ||
} | ||
}; | ||
|
||
/** | ||
* Create a heap from an existing array. This will modify the original array. | ||
* | ||
* @param {Array} data The array to convert to a heap. | ||
*/ | ||
Heap.prototype.buildHeap = function(data) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.defined('data', data); | ||
//>>includeEnd('debug'); | ||
|
||
var length = data.length; | ||
this._data = data; | ||
this._length = length; | ||
|
||
for (var i = Math.ceil(length / 2); i >= 0; --i) { | ||
this.heapify(i); | ||
} | ||
}; | ||
|
||
/** | ||
* Insert an element into the heap. If the length would grow greater than maximumSize | ||
* of the heap, extra elements are removed. | ||
* | ||
* @param {*} value The element to insert | ||
*/ | ||
Heap.prototype.insert = function(value) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.defined('value', value); | ||
//>>includeEnd('debug'); | ||
|
||
var data = this._data; | ||
var comparator = this._comparator; | ||
|
||
var index = this._length++; | ||
if (index < data.length) { | ||
data[index] = value; | ||
} else { | ||
data.push(value); | ||
} | ||
|
||
while (index !== 0) { | ||
var parent = Math.floor((index - 1) / 2); | ||
if (comparator(data[index], data[parent]) < 0) { | ||
swap(data, index, parent); | ||
index = parent; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
if (this._length > this._maximumSize && this._maximumSize > 0) { | ||
this._length = this._maximumSize; | ||
} | ||
}; | ||
|
||
/** | ||
* Remove the top element from the heap and return it. | ||
* | ||
* @returns {*} The top element of the heap. | ||
*/ | ||
Heap.prototype.pop = function() { | ||
if (this._length === 0) { | ||
return undefined; | ||
} | ||
var data = this._data; | ||
var root = data[0]; | ||
swap(data, 0, --this._length); | ||
this.heapify(0); | ||
return root; | ||
}; | ||
|
||
return Heap; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/*global define*/ | ||
define([ | ||
'./defaultValue', | ||
'./defined', | ||
'./defineProperties', | ||
'./Check' | ||
], function( | ||
defaultValue, | ||
defined, | ||
defineProperties, | ||
Check) { | ||
'use strict'; | ||
|
||
/** | ||
* A wrapper around arrays so that the internal length of the array can be manually managed. | ||
* | ||
* @alias ManagedArray | ||
* @constructor | ||
* @private | ||
* | ||
* @param {Number} [length=0] The initial length of the array. | ||
*/ | ||
function ManagedArray(length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though this is private, I'm still not sure about this name. I haven't looked at all the uses, but can this be replaced with Queue or named something higher level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't plan on reviewing this PR, but I also don't see the point of this class. How is this any different than a raw array with a tracking index or the Queue that we already have? Not trying to bikeshed, but every new class we add the Cesium needs to be maintained. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not. It's just an array that manually tracks its length internally. I thought this would be cleaner than having a new tracking index every time we want to manually manage the size of a raw array. Do you think this is unnecessary? |
||
length = defaultValue(length, 0); | ||
this._array = new Array(length); | ||
this._length = length; | ||
} | ||
|
||
defineProperties(ManagedArray.prototype, { | ||
|
||
/** | ||
* Gets or sets the length of the array. | ||
* If the set length is greater than the length of the internal array, the internal array is resized. | ||
* | ||
* @type Number | ||
*/ | ||
length : { | ||
get : function() { | ||
return this._length; | ||
}, | ||
|
||
set : function(length) { | ||
this._length = length; | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
}, | ||
|
||
/** | ||
* Gets the internal array. | ||
* | ||
* @type Array | ||
* @readonly | ||
*/ | ||
internalArray : { | ||
get : function() { | ||
return this._array; | ||
} | ||
} | ||
}); | ||
|
||
/** | ||
* Gets the element at an index. | ||
* | ||
* @param {Number} index The index to get. | ||
*/ | ||
ManagedArray.prototype.get = function(index) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number.lessThan('index', index, this._array.length); | ||
//>>includeEnd('debug'); | ||
|
||
return this._array[index]; | ||
}; | ||
|
||
/** | ||
* Sets the element at an index. Resizes the array if index is greater than the length of the array. | ||
* | ||
* @param {Number} index The index to set. | ||
* @param {*} value The value to set at index. | ||
*/ | ||
ManagedArray.prototype.set = function(index, value) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number('index', index); | ||
//>>includeEnd('debug'); | ||
|
||
if (index >= this.length) { | ||
this.length = index + 1; | ||
} | ||
this._array[index] = value; | ||
}; | ||
|
||
/** | ||
* Push an element into the array. | ||
*/ | ||
ManagedArray.prototype.push = function(element) { | ||
var index = this.length++; | ||
this._array[index] = element; | ||
}; | ||
|
||
/** | ||
* Pop an element from the array. | ||
* | ||
* @returns {*} The last element in the array. | ||
*/ | ||
ManagedArray.prototype.pop = function() { | ||
return this._array[--this.length]; | ||
}; | ||
|
||
/** | ||
* Resize the internal array if length > _array.length. | ||
* | ||
* @param {Number} length The length. | ||
*/ | ||
ManagedArray.prototype.reserve = function(length) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number.greaterThanOrEquals('length', length, 0); | ||
//>>includeEnd('debug'); | ||
|
||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
}; | ||
|
||
/** | ||
* Resize the array. | ||
* | ||
* @param {Number} length The length. | ||
*/ | ||
ManagedArray.prototype.resize = function(length) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number.greaterThanOrEquals('length', length, 0); | ||
//>>includeEnd('debug'); | ||
|
||
this.length = length; | ||
}; | ||
|
||
/** | ||
* Trim the internal array to the specified length. Defaults to the current length. | ||
* | ||
* @param {Number} [length] The length. | ||
*/ | ||
ManagedArray.prototype.trim = function(length) { | ||
length = defaultValue(length, this.length); | ||
this._array.length = length; | ||
}; | ||
|
||
return ManagedArray; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and
ManagedArray
should have tests.