Return split values in a single interleaved Float32Array
This commit is contained in:
+13
-19
@@ -22,12 +22,6 @@ ol.structs.BufferUsage = {
|
|||||||
ol.BUFFER_REPLACE_UNUSED_ENTRIES_WITH_NANS = goog.DEBUG;
|
ol.BUFFER_REPLACE_UNUSED_ENTRIES_WITH_NANS = goog.DEBUG;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {{high: Float32Array, low: Float32Array}}
|
|
||||||
*/
|
|
||||||
ol.structs.BufferSplit32;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -70,7 +64,7 @@ ol.structs.Buffer = function(opt_arr, opt_used, opt_usage) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {?ol.structs.BufferSplit32}
|
* @type {?Float32Array}
|
||||||
*/
|
*/
|
||||||
this.split32_ = null;
|
this.split32_ = null;
|
||||||
|
|
||||||
@@ -165,9 +159,12 @@ ol.structs.Buffer.prototype.getFreeSet = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits this buffer into two Float32Arrays.
|
* Returns a Float32Array twice the length of the buffer containing each value
|
||||||
|
* split into two 32-bit floating point values that, when added together,
|
||||||
|
* approximate the original value. Even indicies contain the high bits, odd
|
||||||
|
* indicies contain the low bits.
|
||||||
* @see http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/
|
* @see http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/
|
||||||
* @return {ol.structs.BufferSplit32} Split.
|
* @return {Float32Array} Split.
|
||||||
*/
|
*/
|
||||||
ol.structs.Buffer.prototype.getSplit32 = function() {
|
ol.structs.Buffer.prototype.getSplit32 = function() {
|
||||||
var arr = this.arr_;
|
var arr = this.arr_;
|
||||||
@@ -177,24 +174,21 @@ ol.structs.Buffer.prototype.getSplit32 = function() {
|
|||||||
this.addDirtySet(this.split32DirtySet_);
|
this.addDirtySet(this.split32DirtySet_);
|
||||||
}
|
}
|
||||||
if (goog.isNull(this.split32_)) {
|
if (goog.isNull(this.split32_)) {
|
||||||
this.split32_ = {
|
this.split32_ = new Float32Array(2 * n);
|
||||||
high: new Float32Array(n),
|
|
||||||
low: new Float32Array(n)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
var split32 = this.split32_;
|
var split32 = this.split32_;
|
||||||
this.split32DirtySet_.forEachRange(function(start, stop) {
|
this.split32DirtySet_.forEachRange(function(start, stop) {
|
||||||
var doubleHigh, i, value;
|
var doubleHigh, i, j, value;
|
||||||
for (i = start; i < stop; ++i) {
|
for (i = start, j = 2 * start; i < stop; ++i, j += 2) {
|
||||||
value = arr[i];
|
value = arr[i];
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
doubleHigh = 65536 * Math.floor(-value / 65536);
|
doubleHigh = 65536 * Math.floor(-value / 65536);
|
||||||
split32.high[i] = -doubleHigh;
|
split32[j] = -doubleHigh;
|
||||||
split32.low[i] = value + doubleHigh;
|
split32[j + 1] = value + doubleHigh;
|
||||||
} else {
|
} else {
|
||||||
doubleHigh = 65536 * Math.floor(value / 65536);
|
doubleHigh = 65536 * Math.floor(value / 65536);
|
||||||
split32.high[i] = doubleHigh;
|
split32[j] = doubleHigh;
|
||||||
split32.low[i] = value - doubleHigh;
|
split32[j + 1] = value - doubleHigh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -231,14 +231,12 @@ describe('ol.structs.Buffer', function() {
|
|||||||
|
|
||||||
it('returns the expected value', function() {
|
it('returns the expected value', function() {
|
||||||
var split32 = b.getSplit32();
|
var split32 = b.getSplit32();
|
||||||
expect(split32.high).to.be.a(Float32Array);
|
expect(split32).to.be.a(Float32Array);
|
||||||
expect(split32.low).to.be.a(Float32Array);
|
expect(split32).to.have.length(4);
|
||||||
expect(split32.high).to.have.length(2);
|
expect(split32[0]).to.roughlyEqual(1179648.0, 1e1);
|
||||||
expect(split32.low).to.have.length(2);
|
expect(split32[1]).to.roughlyEqual(54919.12345670001, 1e-2);
|
||||||
expect(split32.high[0]).to.roughlyEqual(1179648.0, 1e1);
|
expect(split32[2]).to.roughlyEqual(-7602176.0, 1e1);
|
||||||
expect(split32.low[0]).to.roughlyEqual(54919.12345670001, 1e-2);
|
expect(split32[3]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
||||||
expect(split32.high[1]).to.roughlyEqual(-7602176.0, 1e1);
|
|
||||||
expect(split32.low[1]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks updates', function() {
|
it('tracks updates', function() {
|
||||||
@@ -246,14 +244,12 @@ describe('ol.structs.Buffer', function() {
|
|||||||
b.getArray()[0] = 0;
|
b.getArray()[0] = 0;
|
||||||
b.markDirty(1, 0);
|
b.markDirty(1, 0);
|
||||||
var split32 = b.getSplit32();
|
var split32 = b.getSplit32();
|
||||||
expect(split32.high).to.be.a(Float32Array);
|
expect(split32).to.be.a(Float32Array);
|
||||||
expect(split32.low).to.be.a(Float32Array);
|
expect(split32).to.have.length(4);
|
||||||
expect(split32.high).to.have.length(2);
|
expect(split32[0]).to.be(0);
|
||||||
expect(split32.low).to.have.length(2);
|
expect(split32[1]).to.be(0);
|
||||||
expect(split32.high[0]).to.be(0);
|
expect(split32[2]).to.roughlyEqual(-7602176.0, 1e1);
|
||||||
expect(split32.low[0]).to.be(0);
|
expect(split32[3]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
||||||
expect(split32.high[1]).to.roughlyEqual(-7602176.0, 1e1);
|
|
||||||
expect(split32.low[1]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user