This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support cube non rectangle #216
Open
Justinidlerz
wants to merge
2
commits into
google:master
Choose a base branch
from
Justinidlerz:feature/support-cube-non-rectangle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -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() { | ||
|
Contributor
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() { | ||
|
Contributor
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; | ||
|
Contributor
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 | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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".