-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into shadowmap_fade_opt
- Loading branch information
Showing
40 changed files
with
3,941 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import Check from "./Check.js"; | ||
import DeveloperError from "./DeveloperError.js"; | ||
|
||
/** | ||
* Hilbert Order helper functions. | ||
* | ||
* @namespace HilbertOrder | ||
*/ | ||
var HilbertOrder = {}; | ||
|
||
/** | ||
* Computes the Hilbert index at the given level from 2D coordinates. | ||
* | ||
* @param {Number} level The level of the curve | ||
* @param {Number} x The X coordinate | ||
* @param {Number} y The Y coordinate | ||
* @returns {Number} The Hilbert index. | ||
* @private | ||
*/ | ||
HilbertOrder.encode2D = function (level, x, y) { | ||
var n = Math.pow(2, level); | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number("level", level); | ||
Check.typeOf.number("x", x); | ||
Check.typeOf.number("y", y); | ||
if (level < 1) { | ||
throw new DeveloperError("Hilbert level cannot be less than 1."); | ||
} | ||
if (x < 0 || x >= n || y < 0 || y >= n) { | ||
throw new DeveloperError("Invalid coordinates for given level."); | ||
} | ||
//>>includeEnd('debug'); | ||
|
||
var p = { | ||
x: x, | ||
y: y, | ||
}; | ||
var rx, | ||
ry, | ||
s, | ||
index = 0; | ||
|
||
for (s = n / 2; s > 0; s /= 2) { | ||
rx = (p.x & s) > 0 ? 1 : 0; | ||
ry = (p.y & s) > 0 ? 1 : 0; | ||
index += ((3 * rx) ^ ry) * s * s; | ||
rotate(n, p, rx, ry); | ||
} | ||
|
||
return index; | ||
}; | ||
|
||
/** | ||
* Computes the 2D coordinates from the Hilbert index at the given level. | ||
* | ||
* @param {Number} level The level of the curve | ||
* @param {Number} index The Hilbert index | ||
* @returns {Number[]} An array containing the 2D coordinates ([x, y]) corresponding to the Morton index. | ||
* @private | ||
*/ | ||
HilbertOrder.decode2D = function (level, index) { | ||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number("level", level); | ||
Check.typeOf.number("index", index); | ||
if (level < 1) { | ||
throw new DeveloperError("Hilbert level cannot be less than 1."); | ||
} | ||
if (index < 0 || index >= Math.pow(4, level)) { | ||
throw new DeveloperError( | ||
"Hilbert index exceeds valid maximum for given level." | ||
); | ||
} | ||
//>>includeEnd('debug'); | ||
|
||
var n = Math.pow(2, level); | ||
var p = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
var rx, ry, s, t; | ||
|
||
for (s = 1, t = index; s < n; s *= 2) { | ||
rx = 1 & (t / 2); | ||
ry = 1 & (t ^ rx); | ||
rotate(s, p, rx, ry); | ||
p.x += s * rx; | ||
p.y += s * ry; | ||
t /= 4; | ||
} | ||
|
||
return [p.x, p.y]; | ||
}; | ||
|
||
/** | ||
* @private | ||
*/ | ||
function rotate(n, p, rx, ry) { | ||
if (ry !== 0) { | ||
return; | ||
} | ||
|
||
if (rx === 1) { | ||
p.x = n - 1 - p.x; | ||
p.y = n - 1 - p.y; | ||
} | ||
|
||
var t = p.x; | ||
p.x = p.y; | ||
p.y = t; | ||
} | ||
|
||
export default HilbertOrder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.