-
Notifications
You must be signed in to change notification settings - Fork 995
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
Support cube non rectangle #216
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,46 @@ CubeTile.prototype.rotY = function() { | |
|
||
|
||
CubeTile.prototype.centerX = function() { | ||
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 foreWidth = this._level.tileWidth() * this.x; | ||
var partOfWidth = this.width() / 2; | ||
// Compute tile centerX of face | ||
return (foreWidth + partOfWidth + 0.5) / this._level.width() - 0.5; | ||
}; | ||
|
||
|
||
CubeTile.prototype.centerY = function() { | ||
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 foreWidth = this._level.tileWidth() * this.y; | ||
var partOfWidth = this.height() / 2; | ||
// Compute tile centerY of face | ||
return 0.5 - (foreWidth + partOfWidth + 0.5) / this._level.width(); | ||
}; | ||
|
||
|
||
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 +474,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); | ||
|
@@ -488,47 +499,6 @@ CubeLevel.prototype.tileHeight = function() { | |
}; | ||
|
||
|
||
CubeLevel.prototype._validateWithParentLevel = function(parentLevel) { | ||
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. We still want to validate that each tile has at most one parent tile in the previous level (i.e., the tile width must be a submultiple of the parent width, and the same for height). Otherwise, If you're up for it, you can lift this restriction afterwards (but please make it a separate PR, to keep each change small). |
||
|
||
var width = this.width(); | ||
var height = this.height(); | ||
var tileWidth = this.tileWidth(); | ||
var tileHeight = this.tileHeight(); | ||
var numHorizontal = this.numHorizontalTiles(); | ||
var numVertical = this.numVerticalTiles(); | ||
|
||
var parentWidth = parentLevel.width(); | ||
var parentHeight = parentLevel.height(); | ||
var parentTileWidth = parentLevel.tileWidth(); | ||
var parentTileHeight = parentLevel.tileHeight(); | ||
var parentNumHorizontal = parentLevel.numHorizontalTiles(); | ||
var parentNumVertical = parentLevel.numVerticalTiles(); | ||
|
||
if (width % parentWidth !== 0) { | ||
throw new Error('Level width must be multiple of parent level: ' + | ||
width + ' vs. ' + parentWidth); | ||
} | ||
|
||
if (height % parentHeight !== 0) { | ||
throw new Error('Level height must be multiple of parent level: ' + | ||
height + ' vs. ' + parentHeight); | ||
} | ||
|
||
if (numHorizontal % parentNumHorizontal !== 0) { | ||
throw new Error('Number of horizontal tiles must be multiple of parent level: ' + | ||
numHorizontal + " (" + width + '/' + tileWidth + ')' + " vs. " + | ||
parentNumHorizontal + " (" + parentWidth + '/' + parentTileWidth + ')'); | ||
} | ||
|
||
if (numVertical % parentNumVertical !== 0) { | ||
throw new Error('Number of vertical tiles must be multiple of parent level: ' + | ||
numVertical + " (" + height + '/' + tileHeight + ')' + " vs. " + | ||
parentNumVertical + " (" + parentHeight + '/' + parentTileHeight + ')'); | ||
} | ||
|
||
}; | ||
|
||
|
||
/** | ||
* @class CubeGeometry | ||
* @implements Geometry | ||
|
@@ -538,11 +508,8 @@ 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; | ||
* - 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. | ||
* - All tiles must be square, except when in the last row or column position, | ||
* and must form a rectangular grid; | ||
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. |
||
* | ||
* @param {Object[]} levelPropertiesList Level description | ||
* @param {number} levelPropertiesList[].size Cube face size in pixels | ||
|
@@ -556,10 +523,6 @@ function CubeGeometry(levelPropertiesList) { | |
this.levelList = makeLevelList(levelPropertiesList, CubeLevel); | ||
this.selectableLevelList = makeSelectableLevelList(this.levelList); | ||
|
||
for (var i = 1; i < this.levelList.length; i++) { | ||
this.levelList[i]._validateWithParentLevel(this.levelList[i-1]); | ||
} | ||
|
||
this._tileSearcher = new TileSearcher(this); | ||
|
||
this._neighborsCache = new LruMap(CubeTile.equals, CubeTile.hash, 64); | ||
|
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#neighbors
method. 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".