Skip to content

Commit

Permalink
Merge pull request CesiumGS#5881 from AnalyticalGraphicsInc/more-cove…
Browse files Browse the repository at this point in the history
…rity

Minor logic tweaks
  • Loading branch information
pjcozzi authored Oct 9, 2017
2 parents 40de6d6 + ddab777 commit 42864a5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
28 changes: 17 additions & 11 deletions Source/Core/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define([
* The bounding sphere is computed by running two algorithms, a naive algorithm and
* Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
*
* @param {Cartesian3[]} positions An array of points that the bounding sphere will enclose. Each point must have <code>x</code>, <code>y</code>, and <code>z</code> properties.
* @param {Cartesian3[]} [positions] An array of points that the bounding sphere will enclose. Each point must have <code>x</code>, <code>y</code>, and <code>z</code> properties.
* @param {BoundingSphere} [result] The object onto which to store the result.
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
*
Expand Down Expand Up @@ -223,7 +223,7 @@ define([
/**
* Computes a bounding sphere from a rectangle projected in 2D.
*
* @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
* @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.
* @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
* @param {BoundingSphere} [result] The object onto which to store the result.
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
Expand All @@ -236,7 +236,7 @@ define([
* Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the
* object's minimum and maximum heights over the rectangle.
*
* @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
* @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.
* @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
* @param {Number} [minimumHeight=0.0] The minimum height over the rectangle.
* @param {Number} [maximumHeight=0.0] The maximum height over the rectangle.
Expand Down Expand Up @@ -282,7 +282,7 @@ define([
* Computes a bounding sphere from a rectangle in 3D. The bounding sphere is created using a subsample of points
* on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.
*
* @param {Rectangle} rectangle The valid rectangle used to create a bounding sphere.
* @param {Rectangle} [rectangle] The valid rectangle used to create a bounding sphere.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.
* @param {Number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.
* @param {BoundingSphere} [result] The object onto which to store the result.
Expand All @@ -292,11 +292,17 @@ define([
ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
surfaceHeight = defaultValue(surfaceHeight, 0.0);

var positions;
if (defined(rectangle)) {
positions = Rectangle.subsample(rectangle, ellipsoid, surfaceHeight, fromRectangle3DScratch);
if (!defined(result)) {
result = new BoundingSphere();
}

if (!defined(rectangle)) {
result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
result.radius = 0.0;
return result;
}

var positions = Rectangle.subsample(rectangle, ellipsoid, surfaceHeight, fromRectangle3DScratch);
return BoundingSphere.fromPoints(positions, result);
};

Expand All @@ -306,7 +312,7 @@ define([
* algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
* ensure a tight fit.
*
* @param {Number[]} positions An array of points that the bounding sphere will enclose. Each point
* @param {Number[]} [positions] An array of points that the bounding sphere will enclose. Each point
* is formed from three elements in the array in the order X, Y, Z.
* @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the
* origin of the coordinate system. This is useful when the positions are to be used for
Expand Down Expand Up @@ -489,9 +495,9 @@ define([
* algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
* ensure a tight fit.
*
* @param {Number[]} positionsHigh An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point
* @param {Number[]} [positionsHigh] An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point
* is formed from three elements in the array in the order X, Y, Z.
* @param {Number[]} positionsLow An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point
* @param {Number[]} [positionsLow] An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point
* is formed from three elements in the array in the order X, Y, Z.
* @param {BoundingSphere} [result] The object onto which to store the result.
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
Expand Down Expand Up @@ -700,7 +706,7 @@ define([
/**
* Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.
*
* @param {BoundingSphere[]} boundingSpheres The array of bounding spheres.
* @param {BoundingSphere[]} [boundingSpheres] The array of bounding spheres.
* @param {BoundingSphere} [result] The object onto which to store the result.
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/PointVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ define([
pointPrimitive.pixelSize = Property.getValueOrDefault(pointGraphics._pixelSize, time, defaultPixelSize);
pointPrimitive.distanceDisplayCondition = Property.getValueOrUndefined(pointGraphics._distanceDisplayCondition, time, distanceDisplayCondition);
pointPrimitive.disableDepthTestDistance = Property.getValueOrDefault(pointGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
} else { // billboard
} else if (defined(billboard)) {
billboard.show = true;
billboard.position = position;
billboard.scaleByDistance = Property.getValueOrUndefined(pointGraphics._scaleByDistance, time, scaleByDistance);
Expand Down
7 changes: 7 additions & 0 deletions Source/Scene/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'../Core/Color',
'../Core/defined',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/isArray',
'../Core/Math',
'../Core/RuntimeError',
Expand All @@ -19,6 +20,7 @@ define([
Color,
defined,
defineProperties,
DeveloperError,
isArray,
CesiumMath,
RuntimeError,
Expand Down Expand Up @@ -1716,6 +1718,11 @@ define([
}
break;
case ExpressionNodeType.LITERAL_VECTOR:
//>>includeStart('debug', pragmas.debug);
if (!defined(left)) {
throw new DeveloperError('left should always be defined for type ExpressionNodeType.LITERAL_VECTOR');
}
//>>includeEnd('debug');
var length = left.length;
var vectorExpression = value + '(';
for (var i = 0; i < length; ++i) {
Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/GetFeatureInfoFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ define([
break;
}
}

if (!defined(layer)) {
throw new RuntimeError('Unable to find first child of the feature info xml document');
}
var featureMembers = layer.childNodes;
for (var featureIndex = 0; featureIndex < featureMembers.length; ++featureIndex) {
var featureMember = featureMembers[featureIndex];
Expand Down
12 changes: 11 additions & 1 deletion Source/Scene/createTileMapServiceImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ define([
}
}

var message;
if (!defined(tilesets) || !defined(bbox)) {
message = 'Unable to find expected tilesets or bbox attributes in ' + joinUrls(url, 'tilemapresource.xml') + '.';
metadataError = TileProviderError.handleError(metadataError, imageryProvider, imageryProvider.errorEvent, message, undefined, undefined, undefined, requestMetadata);
if(!metadataError.retry) {
deferred.reject(new RuntimeError(message));
}
return;
}

var fileExtension = defaultValue(options.fileExtension, format.getAttribute('extension'));
var tileWidth = defaultValue(options.tileWidth, parseInt(format.getAttribute('width'), 10));
var tileHeight = defaultValue(options.tileHeight, parseInt(format.getAttribute('height'), 10));
Expand All @@ -143,7 +153,7 @@ define([
} else if (tilingSchemeName === 'mercator' || tilingSchemeName === 'global-mercator') {
tilingScheme = new WebMercatorTilingScheme({ ellipsoid : options.ellipsoid });
} else {
var message = joinUrls(url, 'tilemapresource.xml') + 'specifies an unsupported profile attribute, ' + tilingSchemeName + '.';
message = joinUrls(url, 'tilemapresource.xml') + 'specifies an unsupported profile attribute, ' + tilingSchemeName + '.';
metadataError = TileProviderError.handleError(metadataError, imageryProvider, imageryProvider.errorEvent, message, undefined, undefined, undefined, requestMetadata);
if(!metadataError.retry) {
deferred.reject(new RuntimeError(message));
Expand Down
35 changes: 35 additions & 0 deletions Specs/Scene/createTileMapServiceImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ defineSuite([
});
});

it('rejects readyPromise on invalid xml', function() {
loadWithXhr.load = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, "text/xml");
deferred.resolve(xml);
}, 1);
};

var provider = createTileMapServiceImageryProvider({
url : 'made/up/tms/server'
});

return provider.readyPromise.then(function() {
fail('should not resolve');
}).otherwise(function (e) {
expect(provider.ready).toBe(false);
expect(e.message).toContain('expected tilesets or bbox attributes');
});
});

it('requires the url to be specified', function() {
function createWithoutUrl() {
return createTileMapServiceImageryProvider({});
Expand Down

0 comments on commit 42864a5

Please sign in to comment.