-
Notifications
You must be signed in to change notification settings - Fork 1k
Support cube non rectangle #216
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -124,6 +124,8 @@ function CubeTile(face, x, y, z, geometry) { | |
| this.z = z; | ||
| this._geometry = geometry; | ||
| this._level = geometry.levelList[z]; | ||
| // Pre compute last tile size, when all is square, it's 0 | ||
| this._tileResidue = this._level.width() % this._level.tileWidth(); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -138,32 +140,44 @@ CubeTile.prototype.rotY = function() { | |
|
|
||
|
|
||
| CubeTile.prototype.centerX = function() { | ||
|
Collaborator
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 think this can be expressed more succinctly as which is the same logic as in |
||
| return (this.x + 0.5) / this._level.numHorizontalTiles() - 0.5; | ||
| var levelWidth = this._level.width(); | ||
| var tileWidth = this._level.tileWidth(); | ||
| return (this.x * tileWidth + 0.5 * this.width()) / levelWidth - 0.5; | ||
| }; | ||
|
|
||
|
|
||
| CubeTile.prototype.centerY = function() { | ||
|
Collaborator
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. Likewise as above. |
||
| return 0.5 - (this.y + 0.5) / this._level.numVerticalTiles(); | ||
| var levelHeight = this._level.height(); | ||
| var tileHeight = this._level.tileHeight(); | ||
| return 0.5 - (this.y * tileHeight + 0.5 * this.height()) / levelHeight; | ||
| }; | ||
|
|
||
|
|
||
| CubeTile.prototype.scaleX = function() { | ||
| return 1 / this._level.numHorizontalTiles(); | ||
| return this.width() / this._level.width(); | ||
| }; | ||
|
|
||
|
|
||
| CubeTile.prototype.scaleY = function() { | ||
| return 1 / this._level.numVerticalTiles(); | ||
| return this.height() / this._level.width(); | ||
| }; | ||
|
|
||
|
|
||
| CubeTile.prototype.width = function() { | ||
| // Return remainder when it's edge and the tile has residue | ||
| if (this.atRightEdge() && this._tileResidue !== 0) { | ||
| return this._tileResidue; | ||
| } | ||
| return this._level.tileWidth(); | ||
| }; | ||
|
|
||
|
|
||
| CubeTile.prototype.height = function() { | ||
| return this._level.tileHeight(); | ||
| // Return remainder when it's edge and the tile has residue | ||
| if (this.atBottomEdge() && this._tileResidue !== 0) { | ||
| return this._tileResidue; | ||
| } | ||
| return this._level.tileWidth(); | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -458,11 +472,6 @@ function CubeLevel(levelProperties) { | |
|
|
||
| this._size = levelProperties.size; | ||
| this._tileSize = levelProperties.tileSize; | ||
|
|
||
| if (this._size % this._tileSize !== 0) { | ||
| throw new Error('Level size is not multiple of tile size: ' + | ||
| this._size + ' ' + this._tileSize); | ||
| } | ||
| } | ||
|
|
||
| inherits(CubeLevel, Level); | ||
|
|
@@ -538,11 +547,11 @@ CubeLevel.prototype._validateWithParentLevel = function(parentLevel) { | |
| * multiple resolution levels. | ||
| * | ||
| * The following restrictions apply: | ||
| * - All tiles in a level must be square and form a rectangular grid; | ||
| * - The size of a level must be a multiple of the tile size; | ||
| * - All tiles must be square, except when in the last row or column position, | ||
| * and must form a rectangular grid; | ||
|
Collaborator
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. Add per the discussion above. |
||
| * - The size of a level must be a multiple of the parent level size; | ||
| * - The number of tiles in a level must be a multiple of the number of tiles | ||
| * in the parent level. | ||
| * - The tile width (respectively, height) for a level must be a submultiple | ||
| * of the tile width (respectively, height) for the parent level. | ||
| * | ||
| * @param {Object[]} levelPropertiesList Level description | ||
| * @param {number} levelPropertiesList[].size Cube face size in pixels | ||
|
|
||
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.
You also need to change the
CubeTile#neighborsmethod. Currently, the logic assumes that an edge tile never meets more than one tile in the other face; this is no longer true with residual tiles.Consider, for example, the non-residual tile at the top left of the down face. This tile meets two different tiles in the left face: the residual tile at the bottom right of the left face, and the non-residual tile immediately to the left.
A similar situation happens with some of the other corners of the cube. A strategy that might work is to have a lookup table indicating whether a particular corner is "special" or not ("special" meaning that a residual tile meets a non-residual one at that corner). Then add the additional tile to the neighbor set in the cases where the corner is "special".