Skip to content

Commit

Permalink
Modify arrays in place
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 15, 2018
1 parent af109b2 commit b7852e9
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -3957,12 +3957,14 @@ define([
return cartographic.height;
}

function sampleHeightMostDetailed(scene, position, objectsToExclude) {
var ray = getRayForSampleHeight(scene, position);
function sampleHeightMostDetailed(scene, cartographic, objectsToExclude) {
var ray = getRayForSampleHeight(scene, cartographic);
return launchAsyncLoader(scene, ray, objectsToExclude, function() {
var pickResult = pickFromRay(scene, ray, objectsToExclude, true, true);
if (defined(pickResult)) {
return getHeightFromCartesian(scene, pickResult.position);
cartographic.height = getHeightFromCartesian(scene, pickResult.position);
} else {
cartographic.height = undefined;
}
});
}
Expand All @@ -3972,7 +3974,7 @@ define([
return launchAsyncLoader(scene, ray, objectsToExclude, function() {
var pickResult = pickFromRay(scene, ray, objectsToExclude, true, true);
if (defined(pickResult)) {
return pickResult.position;
return Cartesian3.clone(pickResult.position, cartesian);
}
});
}
Expand Down Expand Up @@ -4046,12 +4048,14 @@ define([
};

/**
* Initiates an asynchronous {@link Scene#sampleHeight} request using the maximum level of detail for 3D Tilesets
* regardless of visibility.
* Initiates an asynchronous {@link Scene#sampleHeight} query for an array of {@link Cartographic} positions
* using the maximum level of detail for 3D Tilesets in the scene. Returns a promise that is resolved when
* the query completes. Each point height is modified in place. If a height cannot be determined because no
* geometry can be sampled at that location, or another error occurs, the height is set to undefined.
*
* @param {Cartographic[]} positions The cartographic positions to sample height from.
* @param {Cartographic[]} positions The cartographic positions to update with sampled heights.
* @param {Object[]} [objectsToExclude] A list of primitives, entities, or features to not sample height from.
* @returns {Promise.<Number[]>} A promise that resolves to the heights, or <code>undefined</code> if there was no scene geometry to sample height from.
* @returns {Promise.<Number[]>} A promise that resolves to the provided list of positions when the query has completed.
*
* @see Scene#sampleHeight
*
Expand All @@ -4071,16 +4075,21 @@ define([
for (var i = 0; i < length; ++i) {
promises[i] = sampleHeightMostDetailed(this, positions[i], objectsToExclude);
}
return when.all(promises);
return when.all(promises).then(function() {
return positions;
});
};

/**
* Initiates an asynchronous {@link Scene#clampToHeight} request using the maximum level of detail for 3D Tilesets
* Initiates an asynchronous {@link Scene#clampToHeight} query for an array of {@link Cartesian3} positions
* using the maximum level of detail for 3D Tilesets in the scene. Returns a promise that is resolved when
* the query completes. Each position is modified in place. If a position cannot be clamped because no geometry
* can be sampled at that location, or another error occurs, the element in the array is set to undefined.
* regardless of visibility.
*
* @param {Cartesian3[]} cartesians The cartesian positions.
* @param {Cartesian3[]} cartesians The cartesian positions to update with clamped positions.
* @param {Object[]} [objectsToExclude] A list of primitives, entities, or features to not clamp to.
* @returns {Promise.<Cartesian3[]>} A promise that resolves to the clamped cartesian positions, or <code>undefined</code> if there was no scene geometry to clamp to.
* @returns {Promise.<Cartesian3[]>} A promise that resolves to the provided list of positions when the query has completed.
*
* @see Scene#clampToHeight
*
Expand All @@ -4089,7 +4098,7 @@ define([
*/
Scene.prototype.clampToHeightMostDetailed = function(cartesians, objectsToExclude) {
//>>includeStart('debug', pragmas.debug);
Check.defined('cartesian', cartesians);
Check.defined('cartesians', cartesians);
if (!this.clampToHeightSupported) {
throw new DeveloperError('clampToHeightMostDetailed required depth texture support. Check clampToHeightSupported.');
}
Expand All @@ -4100,7 +4109,13 @@ define([
for (var i = 0; i < length; ++i) {
promises[i] = clampToHeightMostDetailed(this, cartesians[i], objectsToExclude);
}
return when.all(promises);
return when.all(promises).then(function(clampedCartesians) {
// Replace the elements of the input array with the elements of the clamped array.
// Positions are modified in place, except when undefined.
cartesians.length = 0;
cartesians.push.apply(cartesians, clampedCartesians);
return cartesians;
});
};

/**
Expand Down

0 comments on commit b7852e9

Please sign in to comment.