diff --git a/CHANGES.md b/CHANGES.md index 25095b946112..fe2fddeaf28b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,25 @@ _This releases fixes 2D and other issues with Chrome 29.0.1547.57 ([#1002](https * Breaking changes: * The `CameraFlightPath` functions `createAnimation`, `createAnimationCartographic`, and `createAnimationExtent` now take `scene` as their first parameter instead of `frameState`. * `Source/Widgets/Viewer/lighter.css` was deleted, use `Source/Widgets/lighter.css` instead. + * Completely refactored the `DynamicScene` property system to vastly improve the API. See [#1080](https://github.com/AnalyticalGraphicsInc/cesium/pull/1080) for complete details. + * Removed `CzmlBoolean`, `CzmlCartesian2`, `CzmlCartesian3`, `CzmlColor`, `CzmlDefaults`, `CzmlDirection`, `CzmlHorizontalOrigin`, `CzmlImage`, `CzmlLabelStyle`, `CzmlNumber`, `CzmlPosition`, `CzmlString`, `CzmlUnitCartesian3`, `CzmlUnitQuaternion`, `CzmlUnitSpherical`, and `CzmlVerticalOrigin` since they are no longer needed. + * Removed `DynamicProperty`, `DynamicMaterialProperty`, `DynamicDirectionsProperty`, and `DynamicVertexPositionsProperty`; replacing them with an all new system of properties. + * `Property` - base interface for all properties. + * `CompositeProperty` - a property composed of other properties. + * `ConstantProperty` - a property whose value never changes. + * `SampledProperty` - a property whose value is interpolated from a set of samples. + * `TimeIntervalCollectionProperty` - a property whose value changes based on time interval. + * `MaterialProperty` - base interface for all material properties. + * `CompositeMaterialProperty` - a `CompositeProperty` for materials. + * `ColorMaterialProperty` - a property that maps to a color material. (replaces `DynamicColorMaterial`) + * `GridMaterialProperty` - a property that maps to a grid material. (replaces `DynamicGridMaterial`) + * `ImageMaterialProperty` - a property that maps to an image material. (replaces `DynamicImageMaterial`) + * `PositionProperty`- base interface for all position properties. + * `CompositePositionProperty` - a `CompositeProperty` for positions. + * `ConstantPositionProperty` - a `PositionProperty` whose value does not change in respect to the `ReferenceFrame` in which is it defined. + * `SampledPositionProperty` - a `SampledProperty` for positions. + * `TimeIntervalCollectionPositionProperty` - A `TimeIntervalCollectionProperty` for positions. + * Removed `processCzml`, use `CzmlDataSource` instead. * `Source/Widgets/Viewer/lighter.css` was deleted, use `Source/Widgets/lighter.css` instead. * Replaced `ExtentGeometry` parameters for extruded extent to make them consistent with other geometries. * `options.extrudedOptions.height` -> `options.extrudedHeight` * `options.extrudedOptions.closeTop` -> `options.closeBottom` @@ -48,6 +67,9 @@ var geometry = BoxGeometry.createGeometry(box); * Added `Color.fromRandom` to generate random and partially random colors. * Added an `onCancel` callback to `CameraFlightPath` functions that will be executed if the flight is canceled. * Added `Scene.debugShowFrustums` and `Scene.debugFrustumStatistics` for rendering debugging. +* Added an `onCancel` callback to `CameraFlightPath` functions that will be executed if the flight is canceled. +* Added `Packable` and `PackableForInterpolation` interfaces to aid interpolation and in-memory data storage. Also made most core Cesium types implement them. +* Added `InterpolationAlgorithm` interface to codify the base interface already being used by `LagrangePolynomialApproximation`, `LinearApproximation`, and `HermitePolynomialApproximation`. * Improved the performance of polygon triangulation using an O(n log n) algorithm. * Improved geometry batching performance by moving work to a web worker. * Improved `WallGeometry` to follow the curvature of the earth. diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 678c3a1f0c31..94c1ed0e92a9 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -19,6 +19,7 @@ define([ * @param {Number} [x=0.0] The X component. * @param {Number} [y=0.0] The Y component. * + * @see Packable * @see Cartesian3 * @see Cartesian4 */ @@ -148,6 +149,63 @@ define([ */ Cartesian2.fromCartesian4 = Cartesian2.clone; + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + Cartesian2.packedLength = 2; + + /** + * Stores the provided instance into the provided array. + * @memberof Cartesian2 + * + * @param {Cartesian2} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + Cartesian2.pack = function(value, array, startingIndex) { + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.x; + array[startingIndex] = value.y; + }; + + /** + * Retrieves an instance from a packed array. + * @memberof Cartesian2 + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Cartesian2} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + Cartesian2.unpack = function(array, startingIndex, result) { + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Cartesian2(); + } + result.x = array[startingIndex++]; + result.y = array[startingIndex]; + return result; + }; + /** * Computes the value of the maximum component for the supplied Cartesian. * @memberof Cartesian2 diff --git a/Source/Core/Cartesian3.js b/Source/Core/Cartesian3.js index b0cbbb5791f7..275ee5daffe1 100644 --- a/Source/Core/Cartesian3.js +++ b/Source/Core/Cartesian3.js @@ -22,6 +22,7 @@ define([ * * @see Cartesian2 * @see Cartesian4 + * @see Packable */ var Cartesian3 = function(x, y, z) { /** @@ -173,6 +174,65 @@ define([ */ Cartesian3.fromCartesian4 = Cartesian3.clone; + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + Cartesian3.packedLength = 3; + + /** + * Stores the provided instance into the provided array. + * @memberof Cartesian3 + * + * @param {Cartesian3} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + Cartesian3.pack = function(value, array, startingIndex) { + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.x; + array[startingIndex++] = value.y; + array[startingIndex] = value.z; + }; + + /** + * Retrieves an instance from a packed array. + * @memberof Cartesian3 + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Cartesian3} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + Cartesian3.unpack = function(array, startingIndex, result) { + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Cartesian3(); + } + result.x = array[startingIndex++]; + result.y = array[startingIndex++]; + result.z = array[startingIndex]; + return result; + }; + /** * Computes the value of the maximum component for the supplied Cartesian. * @memberof Cartesian3 diff --git a/Source/Core/Cartesian4.js b/Source/Core/Cartesian4.js index 95d3b81fdbbb..8169681d53b5 100644 --- a/Source/Core/Cartesian4.js +++ b/Source/Core/Cartesian4.js @@ -23,6 +23,7 @@ define([ * * @see Cartesian2 * @see Cartesian3 + * @see Packable */ var Cartesian4 = function(x, y, z, w) { /** @@ -145,6 +146,68 @@ define([ return result; }; + + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + Cartesian4.packedLength = 4; + + /** + * Stores the provided instance into the provided array. + * @memberof Cartesian4 + * + * @param {Cartesian4} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + Cartesian4.pack = function(value, array, startingIndex) { + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.x; + array[startingIndex++] = value.y; + array[startingIndex++] = value.z; + array[startingIndex] = value.w; + }; + + /** + * Retrieves an instance from a packed array. + * @memberof Cartesian4 + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Cartesian4} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + Cartesian4.unpack = function(array, startingIndex, result) { + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Cartesian4(); + } + result.x = array[startingIndex++]; + result.y = array[startingIndex++]; + result.z = array[startingIndex++]; + result.w = array[startingIndex]; + return result; + }; + /** * Computes the value of the maximum component for the supplied Cartesian. * @memberof Cartesian4 diff --git a/Source/Core/Color.js b/Source/Core/Color.js index f53ae44c5c5d..865dd1c13480 100644 --- a/Source/Core/Color.js +++ b/Source/Core/Color.js @@ -44,6 +44,8 @@ define([ * * @constructor * @alias Color + * + * @see Packable */ var Color = function(red, green, blue, alpha) { /** @@ -330,6 +332,67 @@ define([ return undefined; }; + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + Color.packedLength = 4; + + /** + * Stores the provided instance into the provided array. + * @memberof Color + * + * @param {Color} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + Color.pack = function(value, array, startingIndex) { + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.red; + array[startingIndex++] = value.green; + array[startingIndex++] = value.blue; + array[startingIndex] = value.alpha; + }; + + /** + * Retrieves an instance from a packed array. + * @memberof Color + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Color} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + Color.unpack = function(array, startingIndex, result) { + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Color(); + } + result.red = array[startingIndex++]; + result.green = array[startingIndex++]; + result.blue = array[startingIndex++]; + result.alpha = array[startingIndex]; + return result; + }; + /** * Converts a 'byte' color component in the range of 0 to 255 into * a 'float' color component in the range of 0 to 1.0. diff --git a/Source/Core/InterpolationAlgorithm.js b/Source/Core/InterpolationAlgorithm.js new file mode 100644 index 000000000000..4de81390f6eb --- /dev/null +++ b/Source/Core/InterpolationAlgorithm.js @@ -0,0 +1,57 @@ +/*global define*/ +define(['./DeveloperError'], function(DeveloperError) { + "use strict"; + + /** + * The interface for interpolation algorithms. + * @exports InterpolationAlgorithm + * + * @see LagrangePolynomialApproximation + * @see LinearApproximation + * @see HermitePolynomialApproximation + */ + var InterpolationAlgorithm = {}; + + /** + * Gets the name of this interpolation algorithm. + * @type {String} + */ + InterpolationAlgorithm.type = undefined; + + /** + * Given the desired degree, returns the number of data points required for interpolation. + * @memberof InterpolationAlgorithm + * + * @param degree The desired degree of interpolation. + * + * @returns The number of required data points needed for the desired degree of interpolation. + */ + InterpolationAlgorithm.getRequiredDataPoints = function(degree) { + throw new DeveloperError('This function defines an interface and should not be called directly.'); + }; + + /** + * Interpolates values. + * @memberof InterpolationAlgorithm + * + * @param {Number} x The independent variable for which the dependent variables will be interpolated. + * + * @param {Array} xTable The array of independent variables to use to interpolate. The values + * in this array must be in increasing order and the same value must not occur twice in the array. + * + * @param {Array} yTable The array of dependent variables to use to interpolate. For a set of three + * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}. + * + * @param {Number} yStride The number of dependent variable values in yTable corresponding to + * each independent variable value in xTable. + * + * @param {Array} [result] An existing array into which to store the result. + * + * @returns The array of interpolated values, or the result parameter if one was provided. + */ + InterpolationAlgorithm.interpolateOrderZero = function(x, xTable, yTable, yStride, result) { + throw new DeveloperError('This function defines an interface and should not be called directly.'); + }; + + return InterpolationAlgorithm; +}); \ No newline at end of file diff --git a/Source/Core/Packable.js b/Source/Core/Packable.js new file mode 100644 index 000000000000..bd94142b565d --- /dev/null +++ b/Source/Core/Packable.js @@ -0,0 +1,54 @@ +/*global define*/ +define(['../Core/DeveloperError'], function(DeveloperError) { + "use strict"; + + function throwInstantiationError() { + throw new DeveloperError('This type should not be instantiated directly.'); + } + + /** + * Base interface for objects which can store their values as packed + * elements in an array. + * + * @exports Packable + * + * @see {PackableForInterpolation} + */ + var Packable = { + + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + packedLength : undefined, + + /** + * Stores the provided instance into the provided array. + * @memberof Packable + * @function + * + * @param {Object} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + pack : throwInstantiationError, + + /** + * Retrieves an instance from a packed array. + * @memberof Packable + * @function + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Object} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + unpack : throwInstantiationError + }; + + return Packable; +}); diff --git a/Source/Core/PackableForInterpolation.js b/Source/Core/PackableForInterpolation.js new file mode 100644 index 000000000000..13daf90b8ff0 --- /dev/null +++ b/Source/Core/PackableForInterpolation.js @@ -0,0 +1,57 @@ +/*global define*/ +define(['../Core/DeveloperError'], function(DeveloperError) { + "use strict"; + + function throwInstantiationError() { + throw new DeveloperError('This type should not be instantiated directly.'); + } + + /** + * Interface for {@link Packable} objects which are interpolated in a + * different representation than their packed value. + * + * @exports PackableForInterpolation + * + * @see {Packable} + */ + var PackableForInterpolation = { + + /** + * The number of elements used to store the object into an array in its interpolatable form. + * @Type {Number} + */ + packedInterpolationLength : undefined, + + /** + * Converts a packed array into a form suitable for interpolation. + * @memberof PackableForInterpolation + * @function + * + * @param {Array} packedArray The packed array. + * @param {Number} [startingIndex=0] The index of the first element to be converted. + * @param {Number} [lastIndex=packedArray.length] The index of the last element to be converted. + * @param {Array} [result] The object into which to store the result. + * + * @exception {DeveloperError} packedArray is required. + */ + convertPackedArrayForInterpolation : throwInstantiationError, + + /** + * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}. + * @memberof PackableForInterpolation + * @function + * + * @param {Array} array The original packed array. + * @param {Array} sourceArray The converted array. + * @param {Number} [startingIndex=0] The startingIndex used to convert the array. + * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array. + * @param {Object} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + * @exception {DeveloperError} sourceArray is required. + */ + unpackInterpolationResult : throwInstantiationError + }; + + return PackableForInterpolation; +}); diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index c7eebdf00526..b0d3dfb49398 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -26,6 +26,8 @@ define([ * @param {Number} [y=0.0] The Y component. * @param {Number} [z=0.0] The Z component. * @param {Number} [w=0.0] The W component. + * + * @see PackableForInterpolation */ var Quaternion = function(x, y, z, w) { /** @@ -174,6 +176,145 @@ define([ return result; }; + var sampledQuaternionAxis = new Cartesian3(); + var sampledQuaternionRotation = new Cartesian3(); + var sampledQuaternionTempQuaternion = new Quaternion(); + var sampledQuaternionQuaternion0 = new Quaternion(); + var sampledQuaternionQuaternion0Conjugate = new Quaternion(); + + /** + * The number of elements used to pack the object into an array. + * @Type {Number} + */ + Quaternion.packedLength = 4; + + /** + * Stores the provided instance into the provided array. + * @memberof Quaternion + * + * @param {Quaternion} value The value to pack. + * @param {Array} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} array is required. + */ + Quaternion.pack = function(value, array, startingIndex) { + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.x; + array[startingIndex++] = value.y; + array[startingIndex++] = value.z; + array[startingIndex] = value.w; + }; + + /** + * Retrieves an instance from a packed array. + * @memberof Quaternion + * + * @param {Array} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Quaternion} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + */ + Quaternion.unpack = function(array, startingIndex, result) { + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Quaternion(); + } + result.x = array[startingIndex]; + result.y = array[startingIndex + 1]; + result.z = array[startingIndex + 2]; + result.w = array[startingIndex + 3]; + return result; + }; + + /** + * The number of elements used to store the object into an array in its interpolatable form. + * @Type {Number} + */ + Quaternion.packedInterpolationLength = 3; + + /** + * Converts a packed array into a form suitable for interpolation. + * @memberof Quaternion + * + * @param {Array} packedArray The packed array. + * @param {Number} [startingIndex=0] The index of the first element to be converted. + * @param {Number} [lastIndex=packedArray.length] The index of the last element to be converted. + * @param {Array} [result] The object into which to store the result. + * + * @exception {DeveloperError} packedArray is required. + */ + Quaternion.convertPackedArrayForInterpolation = function(packedArray, startingIndex, lastIndex, result) { + Quaternion.unpack(packedArray, lastIndex * 4, sampledQuaternionQuaternion0Conjugate); + sampledQuaternionQuaternion0Conjugate.conjugate(sampledQuaternionQuaternion0Conjugate); + + for ( var i = 0, len = lastIndex - startingIndex + 1; i < len; i++) { + var offset = i * 3; + Quaternion.unpack(packedArray, (startingIndex + i) * 4, sampledQuaternionTempQuaternion); + + sampledQuaternionTempQuaternion.multiply(sampledQuaternionQuaternion0Conjugate, sampledQuaternionTempQuaternion); + + if (sampledQuaternionTempQuaternion.w < 0) { + sampledQuaternionTempQuaternion.negate(sampledQuaternionTempQuaternion); + } + + sampledQuaternionTempQuaternion.getAxis(sampledQuaternionAxis); + var angle = sampledQuaternionTempQuaternion.getAngle(); + result[offset] = sampledQuaternionAxis.x * angle; + result[offset + 1] = sampledQuaternionAxis.y * angle; + result[offset + 2] = sampledQuaternionAxis.z * angle; + } + }; + + /** + * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}. + * @memberof Quaternion + * + * @param {Array} array The original packed array. + * @param {Array} sourceArray The converted array. + * @param {Number} [startingIndex=0] The startingIndex used to convert the array. + * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array. + * @param {Quaternion} [result] The object into which to store the result. + * + * @exception {DeveloperError} array is required. + * @exception {DeveloperError} sourceArray is required. + */ + Quaternion.unpackInterpolationResult = function(array, sourceArray, firstIndex, lastIndex, result) { + if (!defined(result)) { + result = new Quaternion(); + } + sampledQuaternionRotation.x = array[0]; + sampledQuaternionRotation.y = array[1]; + sampledQuaternionRotation.z = array[2]; + var magnitude = sampledQuaternionRotation.magnitude(); + + Quaternion.unpack(sourceArray, lastIndex * 4, sampledQuaternionQuaternion0); + + if (magnitude === 0) { + Quaternion.clone(Quaternion.IDENTITY, sampledQuaternionTempQuaternion); + } else { + Quaternion.fromAxisAngle(sampledQuaternionRotation, magnitude, sampledQuaternionTempQuaternion); + } + + return sampledQuaternionTempQuaternion.multiply(sampledQuaternionQuaternion0, result); + }; + /** * Duplicates a Quaternion instance. * @memberof Quaternion diff --git a/Source/Core/TimeIntervalCollection.js b/Source/Core/TimeIntervalCollection.js index 7282f44541c9..d31f772ea4bf 100644 --- a/Source/Core/TimeIntervalCollection.js +++ b/Source/Core/TimeIntervalCollection.js @@ -115,6 +115,22 @@ define([ return index >= 0 ? this._intervals[index] : undefined; }; + /** + * Returns the data for the interval which contains the specified date. + * + * @param {JulianDate} date The date to search for. + * + * @memberof TimeIntervalCollection + * + * @returns The data for the interval containing the specified date, or undefined if no such interval exists. + * + * @exception {DeveloperError} date is required. + */ + TimeIntervalCollection.prototype.findDataForIntervalContainingDate = function(date) { + var index = this.indexOf(date); + return index >= 0 ? this._intervals[index].data : undefined; + }; + /** * Returns true if the specified date is contained in the interval collection. * diff --git a/Source/DynamicScene/ColorMaterialProperty.js b/Source/DynamicScene/ColorMaterialProperty.js new file mode 100644 index 000000000000..176a51379f35 --- /dev/null +++ b/Source/DynamicScene/ColorMaterialProperty.js @@ -0,0 +1,56 @@ +/*global define*/ +define([ + '../Core/Color', + '../Core/defined', + './ConstantProperty' + ], function( + Color, + defined, + ConstantProperty) { + "use strict"; + + /** + * A {@link MaterialProperty} that maps to solid color {@link Material} uniforms. + * @alias ColorMaterialProperty + * @constructor + */ + var ColorMaterialProperty = function() { + /** + * A {@link Color} {@link Property} which determines the material's color. + * @type {Property} + * @default new ConstantProperty(Color.WHITE) + */ + this.color = new ConstantProperty(Color.WHITE); + }; + + /** + * Gets the {@link Material} type at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the type. + * @type {String} The type of material. + */ + ColorMaterialProperty.prototype.getType = function(time) { + return 'Color'; + }; + + /** + * Gets the value of the property at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + ColorMaterialProperty.prototype.getValue = function(time, result) { + if (!defined(result)) { + result = {}; + } + result.color = defined(this.color) ? this.color.getValue(time, result.color) : undefined; + return result; + }; + + return ColorMaterialProperty; +}); diff --git a/Source/DynamicScene/CompositeDynamicObjectCollection.js b/Source/DynamicScene/CompositeDynamicObjectCollection.js index a04fc359d731..9c039eafff51 100644 --- a/Source/DynamicScene/CompositeDynamicObjectCollection.js +++ b/Source/DynamicScene/CompositeDynamicObjectCollection.js @@ -7,7 +7,18 @@ define([ '../Core/TimeInterval', '../Core/DeveloperError', './DynamicObject', - './CzmlDefaults' + './DynamicBillboard', + './DynamicClock', + './DynamicEllipse', + './DynamicEllipsoid', + './DynamicCone', + './DynamicLabel', + './DynamicPath', + './DynamicPoint', + './DynamicPolygon', + './DynamicPolyline', + './DynamicPyramid', + './DynamicVector' ], function( defaultValue, defined, @@ -16,7 +27,18 @@ define([ TimeInterval, DeveloperError, DynamicObject, - CzmlDefaults) { + DynamicBillboard, + DynamicClock, + DynamicEllipse, + DynamicEllipsoid, + DynamicCone, + DynamicLabel, + DynamicPath, + DynamicPoint, + DynamicPolygon, + DynamicPolyline, + DynamicPyramid, + DynamicVector) { "use strict"; /** @@ -36,7 +58,6 @@ define([ * * @see DynamicObjectCollection * @see DynamicObject - * @see CzmlDefaults */ var CompositeDynamicObjectCollection = function(collections, mergeFunctions, cleanFunctions) { this._hash = {}; @@ -46,12 +67,12 @@ define([ /** * The array of functions which merge DynamicObject instances together. */ - this.mergeFunctions = defaultValue(mergeFunctions, CzmlDefaults.mergers); + this.mergeFunctions = defaultValue(mergeFunctions, CompositeDynamicObjectCollection.mergers); /** * The array of functions which remove data from a DynamicObject instance. */ - this.cleanFunctions = defaultValue(cleanFunctions, CzmlDefaults.cleaners); + this.cleanFunctions = defaultValue(cleanFunctions, CompositeDynamicObjectCollection.cleaners); /** * An {@link Event} that is fired whenever DynamicObjects in the collection have properties added. @@ -66,6 +87,42 @@ define([ this.setCollections(collections); }; + /** + * The standard set of mergers for processing CZML. This array is the default + * set of updater methods used by CompositeDynamicObjectCollection. + */ + CompositeDynamicObjectCollection.mergers = [DynamicClock.mergeProperties, + DynamicBillboard.mergeProperties, + DynamicEllipse.mergeProperties, + DynamicEllipsoid.mergeProperties, + DynamicCone.mergeProperties, + DynamicLabel.mergeProperties, + DynamicPath.mergeProperties, + DynamicPoint.mergeProperties, + DynamicPolygon.mergeProperties, + DynamicPolyline.mergeProperties, + DynamicPyramid.mergeProperties, + DynamicVector.mergeProperties, + DynamicObject.mergeProperties]; + + /** + * The standard set of cleaners for processing CZML. This array is the default + * set of updater methods used by CompositeDynamicObjectCollection. + */ + CompositeDynamicObjectCollection.cleaners = [DynamicBillboard.undefineProperties, + DynamicEllipse.undefineProperties, + DynamicEllipsoid.undefineProperties, + DynamicCone.undefineProperties, + DynamicLabel.undefineProperties, + DynamicPath.undefineProperties, + DynamicPoint.undefineProperties, + DynamicPolygon.undefineProperties, + DynamicPolyline.undefineProperties, + DynamicPyramid.undefineProperties, + DynamicVector.undefineProperties, + DynamicObject.undefineProperties, + DynamicClock.undefineProperties]; + /** * Computes the maximum availability of the DynamicObjects in the collection. * If the collection contains a mix of infinitely available data and non-infinite data, diff --git a/Source/DynamicScene/CompositeMaterialProperty.js b/Source/DynamicScene/CompositeMaterialProperty.js new file mode 100644 index 000000000000..557a17444201 --- /dev/null +++ b/Source/DynamicScene/CompositeMaterialProperty.js @@ -0,0 +1,80 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/TimeIntervalCollection' + ], function( + defined, + defineProperties, + DeveloperError, + TimeIntervalCollection) { + "use strict"; + + /** + * A {@link CompositeProperty} which is also a {@link MaterialProperty}. + * + * @alias CompositeMaterialProperty + * @constructor + */ + var CompositeMaterialProperty = function() { + this._intervals = new TimeIntervalCollection(); + }; + + defineProperties(CompositeMaterialProperty.prototype, { + /** + * Gets the interval collection. + * @memberof CompositeMaterialProperty.prototype + * + * @type {TimeIntervalCollection} + */ + intervals : { + get : function() { + return this._intervals; + } + } + }); + + /** + * Gets the {@link Material} type at the provided time. + * @memberof CompositeMaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the type. + * @type {String} The type of material. + */ + CompositeMaterialProperty.prototype.getType = function(time) { + if (!defined(time)) { + throw new DeveloperError('time is required'); + } + + var innerProperty = this._intervals.findDataForIntervalContainingDate(time); + if (defined(innerProperty)) { + return innerProperty.getType(time); + } + return undefined; + }; + + /** + * Gets the value of the property at the provided time. + * @memberof CompositeMaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + CompositeMaterialProperty.prototype.getValue = function(time, result) { + if (!defined(time)) { + throw new DeveloperError('time is required'); + } + + var innerProperty = this._intervals.findDataForIntervalContainingDate(time); + if (defined(innerProperty)) { + return innerProperty.getValue(time, result); + } + return undefined; + }; + + return CompositeMaterialProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/CompositePositionProperty.js b/Source/DynamicScene/CompositePositionProperty.js new file mode 100644 index 000000000000..76ad6e1e6919 --- /dev/null +++ b/Source/DynamicScene/CompositePositionProperty.js @@ -0,0 +1,102 @@ +/*global define*/ +define([ + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/TimeIntervalCollection', + '../Core/ReferenceFrame' + ], function( + defaultValue, + defined, + defineProperties, + DeveloperError, + TimeIntervalCollection, + ReferenceFrame) { + "use strict"; + + /** + * A {@link CompositeProperty} which is also a {@link PositionProperty}. + * + * @alias CompositePositionProperty + * @constructor + */ + var CompositePositionProperty = function(referenceFrame) { + this._intervals = new TimeIntervalCollection(); + this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + }; + + defineProperties(CompositePositionProperty.prototype, { + /** + * Gets the interval collection. + * @memberof CompositePositionProperty.prototype + * + * @type {TimeIntervalCollection} + */ + intervals : { + get : function() { + return this._intervals; + } + }, + /** + * Gets or sets the reference frame which this position presents itself as. + * Each PositionProperty making up this object has it's own reference frame, + * so this property merely exposes a "preferred" reference frame for clients + * to use. + * @memberof CompositePositionProperty.prototype + * + * @Type {ReferenceFrame} The preferred reference frame. + */ + referenceFrame : { + get : function() { + return this._referenceFrame; + }, + set : function(value) { + this._referenceFrame = value; + } + } + }); + + /** + * Gets the value of the property at the provided time in the fixed frame. + * @memberof CompositePositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + CompositePositionProperty.prototype.getValue = function(time, result) { + return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result); + }; + + /** + * Gets the value of the property at the provided time and in the provided reference frame. + * @memberof CompositePositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} referenceFrame is required. + */ + CompositePositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + if (!defined(referenceFrame)) { + throw new DeveloperError('referenceFrame is required.'); + } + + var innerProperty = this._intervals.findDataForIntervalContainingDate(time); + if (defined(innerProperty)) { + return innerProperty.getValueInReferenceFrame(time, referenceFrame, result); + } + return undefined; + }; + + return CompositePositionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/CompositeProperty.js b/Source/DynamicScene/CompositeProperty.js new file mode 100644 index 000000000000..db7daa3bf110 --- /dev/null +++ b/Source/DynamicScene/CompositeProperty.js @@ -0,0 +1,78 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/TimeIntervalCollection' + ], function( + defined, + defineProperties, + DeveloperError, + TimeIntervalCollection) { + "use strict"; + + /** + * A {@link Property} which is defined by a {@link TimeIntervalCollection}, where the + * data property of each {@link TimeInterval} is another Property instance which is + * evaluated at the provided time. + * + * @alias CompositeProperty + * @constructor + * + * @see CompositeMaterialProperty + * @see CompositePositionProperty + * + * @example + * var constantProperty = ...; + * var sampledProperty = ...; + * + * //Create a composite property from two previously defined properties + * //where the property is valid on August 1st, 2012 and uses a constant + * //property for the first half of the day and a sampled property for the + * //remaining half. + * var composite = new CompositeProperty(); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T00:00:00.00Z/2012-08-01T12:00:00.00Z', true, true, constantProperty)); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T12:00:00.00Z/2012-08-02T00:00:00.00Z', false, false, sampledProperty)); + */ + var CompositeProperty = function() { + this._intervals = new TimeIntervalCollection(); + }; + + defineProperties(CompositeProperty.prototype, { + /** + * Gets the interval collection. + * @memberof CompositeProperty.prototype + * + * @type {TimeIntervalCollection} + */ + intervals : { + get : function() { + return this._intervals; + } + } + }); + + /** + * Gets the value of the property at the provided time. + * @memberof CompositeProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + CompositeProperty.prototype.getValue = function(time, result) { + if (!defined(time)) { + throw new DeveloperError('time is required'); + } + + var innerProperty = this._intervals.findDataForIntervalContainingDate(time); + if (defined(innerProperty)) { + return innerProperty.getValue(time, result); + } + return undefined; + }; + + return CompositeProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/ConstantPositionProperty.js b/Source/DynamicScene/ConstantPositionProperty.js new file mode 100644 index 000000000000..852a654f7b8c --- /dev/null +++ b/Source/DynamicScene/ConstantPositionProperty.js @@ -0,0 +1,95 @@ +/*global define*/ +define([ + './ConstantProperty', + './PositionProperty', + '../Core/Cartesian3', + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/ReferenceFrame' + ], function( + ConstantProperty, + PositionProperty, + Cartesian3, + defaultValue, + defined, + defineProperties, + DeveloperError, + ReferenceFrame) { + "use strict"; + + /** + * A {@link PositionProperty} whose value does not change in respect to the + * {@link ReferenceFrame} in which is it defined. + * + * @alias ConstantPositionProperty + * @constructor + * + * @param {Cartesian3} value The property value. + * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined. + * + * @exception {DeveloperError} value is required. + * + * @example + * //Create a constant position in the inertial frame. + * var constantProperty = new ConstantPositionProperty(new Cartesian3(-4225824.0, 1261219.0, -5148934.0), ReferenceFrame.INERTIAL); + */ + var ConstantPositionProperty = function(value, referenceFrame) { + this._property = new ConstantProperty(value, Cartesian3.clone); + this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + }; + + defineProperties(ConstantPositionProperty.prototype, { + /** + * Gets the reference frame in which the position is defined. + * @memberof ConstantPositionProperty.prototype + * @Type {ReferenceFrame} + * @default ReferenceFrame.FIXED; + */ + referenceFrame : { + get : function() { + return this._referenceFrame; + } + } + }); + + /** + * Gets the value of the property at the provided time in the fixed frame. + * @memberof ConstantPositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + ConstantPositionProperty.prototype.getValue = function(time, result) { + return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result); + }; + + /** + * Gets the value of the property at the provided time and in the provided reference frame. + * @memberof ConstantPositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} referenceFrame is required. + */ + ConstantPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + if (!defined(referenceFrame)) { + throw new DeveloperError('referenceFrame is required.'); + } + var value = this._property.getValue(time, result); + return PositionProperty.convertToReferenceFrame(time, value, this._referenceFrame, referenceFrame, value); + }; + + return ConstantPositionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/ConstantProperty.js b/Source/DynamicScene/ConstantProperty.js index c6998e476280..b1a3954dd5e4 100644 --- a/Source/DynamicScene/ConstantProperty.js +++ b/Source/DynamicScene/ConstantProperty.js @@ -1,37 +1,83 @@ /*global define*/ -define(['../Core/defined' - ],function( - defined) { +define([ + '../Core/defaultValue', + '../Core/defined', + '../Core/DeveloperError', + '../Core/Enumeration' + ], function( + defaultValue, + defined, + DeveloperError, + Enumeration) { "use strict"; + function prototypeClone(value, result) { + return value.clone(result); + } + + function noClone(value, result) { + return value; + } + /** - * Represents a single value which does not change with regard to simulation time. + * A {@link Property} whose value never changes. * * @alias ConstantProperty * @constructor * - * @see DynamicProperty + * @param {Object|Number|String} value The property value. + * @param {Function} [clone=value.clone] A function which takes the value and a result parameter and clones it. + * This parameter is only required if the value is not a number or string and does not have a clone function. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} clone is a required function. + * + * @see ConstantPositionProperty + * + * @example + * //Create a constant value from a Cartesian2 instance. + * var constantProperty = new ConstantProperty(new Cartesian2(10, 12)); + * + * @example + * //Create a ConstantPropety from a user-defined object. + * var myObject = { + * value : 6 + * }; + * function cloneMyObject(value, result) { + * return { + * value : value.value + * }; + * } + * var constantProperty = new ConstantProperty(myObject, cloneMyObject); */ - var ConstantProperty = function(value) { + var ConstantProperty = function(value, clone) { + if (!defined(value)) { + throw new DeveloperError('value is required.'); + } + + if (typeof value === 'object' && !Array.isArray(value) && !(value instanceof Enumeration)) { + if (typeof value.clone !== 'function' && typeof clone !== 'function') { + throw new DeveloperError('clone is a required function.'); + } + + clone = defaultValue(clone, prototypeClone); + } + this._value = value; - this._clonable = defined(value) && typeof value.clone === 'function'; + this._clone = defaultValue(clone, noClone); }; /** - * Gets the value of the property, optionally cloning it. - * @memberof ConstantProperty + * Gets the value of the property at the provided time. + * @memberof CompositeProperty * - * @param {JulianDate} time The time for which to retrieve the value. This parameter is unused. - * @param {Object} [result] The object to store the value into if the value is clonable. If the result is omitted or the value does not implement clone, the actual value is returned. - * @returns The modified result parameter or the actual value instance if the value is not clonable. + * @param {JulianDate} time The time for which to retrieve the value. This parameter is unused since the value never changes. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. */ ConstantProperty.prototype.getValue = function(time, result) { - var value = this._value; - if (this._clonable) { - return value.clone(result); - } - return value; + return this._clone(this._value, result); }; return ConstantProperty; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/CzmlBoolean.js b/Source/DynamicScene/CzmlBoolean.js deleted file mode 100644 index f9a06fcc853d..000000000000 --- a/Source/DynamicScene/CzmlBoolean.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue' - ], function( - defaultValue) { - "use strict"; - - /** - * Provides methods for working with a boolean defined in CZML. - * - * @exports CzmlBoolean - * - * @see DynamicProperty - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlBoolean = { - /** - * Returns the packed boolean representation contained within the provided CZML interval - * or undefined if the interval does not contain boolean data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - /*jshint sub:true*/ - // boolean is a JS reserved word - return defaultValue(czmlInterval['boolean'], czmlInterval); - }, - - /** - * Since CZML booleans can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the boolean value contained within the unwrappedInterval. For booleans - * this is the unwrappedInterval itself. - * - * @param {Object} unwrappedInterval The result of CzmlBoolean.unwrapInterval. - * @returns The boolean value. - */ - getValue : function(unwrappedInterval) { - return unwrappedInterval; - } - }; - - return CzmlBoolean; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlCartesian2.js b/Source/DynamicScene/CzmlCartesian2.js deleted file mode 100644 index 1caae4deabac..000000000000 --- a/Source/DynamicScene/CzmlCartesian2.js +++ /dev/null @@ -1,98 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian2', - '../Core/defined' - ], function( - Cartesian2, - defined) { - "use strict"; - - var doublesPerValue = 2; - - /** - * Provides methods for working with a Cartesian2 defined in CZML. - * - * @exports CzmlCartesian2 - * - * @see Cartesian2 - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlCartesian2 = { - /** - * The number of doubles per packed Cartesian2 value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Cartesian2 representation contained within the provided CZML interval - * or undefined if the interval does not contain Cartesian2 data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return czmlInterval.cartesian2; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlCartesian2.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Cartesian2 instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlCartesian2.unwrapInterval. - * @param {Cartesian2} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian2 instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Cartesian2(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - return result; - }, - - /** - * Given a packed array of x and y values, extracts a Cartesian2 instance. - * - * @param {Array} array A packed array of Cartesian2 values, where every two elements represents an x,y pair. - * @param {Number} startingIndex The index into the array that contains the x value of the Cartesian2 you would like. - * @param {Cartesian2} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian2 instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Cartesian2(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - return result; - } - }; - - return CzmlCartesian2; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlCartesian3.js b/Source/DynamicScene/CzmlCartesian3.js deleted file mode 100644 index 65b60617c403..000000000000 --- a/Source/DynamicScene/CzmlCartesian3.js +++ /dev/null @@ -1,101 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/defined' - ], function( - Cartesian3, - defined) { - "use strict"; - - var doublesPerValue = 3; - - /** - * Provides methods for working with a Cartesian3 defined in CZML. - * - * @exports CzmlCartesian3 - * - * @see Cartesian3 - * @see DynamicProperty - * @see DynamicPositionProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlCartesian3 = { - /** - * The number of doubles per packed Cartesian3 value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Cartesian3 representation contained within the provided CZML interval - * or undefined if the interval does not contain Cartesian3 data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return czmlInterval.cartesian; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlCartesian3.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Cartesian3 instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlCartesian3.unwrapInterval. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - result.z = unwrappedInterval[2]; - return result; - }, - - /** - * Given a packed array of x, y, and z values, extracts a Cartesian3 instance. - * - * @param {Array} array A packed array of Cartesian3 values, where every three elements represents a Cartesian3. - * @param {Number} startingIndex The index into the array that contains the x value of the Cartesian3 you would like. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - result.z = array[startingIndex + 2]; - return result; - } - }; - - return CzmlCartesian3; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlColor.js b/Source/DynamicScene/CzmlColor.js deleted file mode 100644 index 4b37fef27750..000000000000 --- a/Source/DynamicScene/CzmlColor.js +++ /dev/null @@ -1,129 +0,0 @@ -/*global define*/ -define([ - '../Core/Color', - '../Core/defined' - ], function( - Color, - defined) { - "use strict"; - - var doublesPerValue = 4; - - /** - * Provides methods for working with a Color defined in CZML. - * - * @exports CzmlColor - * - * @see Color - * @see DynamicProperty - * @see DynamicPositionProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlColor = { - /** - * The number of doubles per packed Color value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Color representation contained within the provided CZML interval - * or undefined if the interval does not contain Color data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - var rgbaf = czmlInterval.rgbaf; - if (defined(rgbaf)) { - return rgbaf; - } - - var rgba = czmlInterval.rgba; - if (!defined(rgba)) { - return undefined; - } - - if (!this.isSampled(rgba)) { - return [Color.byteToFloat(rgba[0]), - Color.byteToFloat(rgba[1]), - Color.byteToFloat(rgba[2]), - Color.byteToFloat(rgba[3])]; - } - - var len = rgba.length; - rgbaf = new Array(len); - for ( var i = 0; i < len; i += 5) { - rgbaf[i] = rgba[i]; - rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]); - rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]); - rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]); - rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]); - } - return rgbaf; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlColor.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Color instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlColor.unwrapInterval. - * @param {Color} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Color instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Color(); - } - result.red = unwrappedInterval[0]; - result.green = unwrappedInterval[1]; - result.blue = unwrappedInterval[2]; - result.alpha = unwrappedInterval[3]; - return result; - }, - - - /** - * Given a packed array of red, green, blue, and alpha values, extracts a Color instance. - * - * @param {Array} array A packed array of Color values, where every four elements represents a Color. - * @param {Number} startingIndex The index into the array that contains the red value of the Color you would like. - * @param {Color} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Color instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Color(); - } - result.red = array[startingIndex]; - result.green = array[startingIndex + 1]; - result.blue = array[startingIndex + 2]; - result.alpha = array[startingIndex + 3]; - return result; - } - }; - return CzmlColor; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlDataSource.js b/Source/DynamicScene/CzmlDataSource.js index 9beb8d51cd92..2bfda8211c3c 100644 --- a/Source/DynamicScene/CzmlDataSource.js +++ b/Source/DynamicScene/CzmlDataSource.js @@ -1,33 +1,1112 @@ /*global define*/ define([ + '../Core/Cartesian2', + '../Core/Cartesian3', + '../Core/Cartographic', + '../Core/Color', '../Core/ClockRange', '../Core/ClockStep', + '../Core/createGuid', + '../Core/defaultValue', '../Core/defined', '../Core/DeveloperError', + '../Core/Ellipsoid', '../Core/Event', + '../Core/HermitePolynomialApproximation', '../Core/Iso8601', + '../Core/JulianDate', + '../Core/LagrangePolynomialApproximation', + '../Core/LinearApproximation', '../Core/loadJson', + '../Core/Math', + '../Core/Quaternion', + '../Core/ReferenceFrame', + '../Core/Spherical', + '../Core/TimeInterval', + '../Scene/HorizontalOrigin', + '../Scene/LabelStyle', + '../Scene/VerticalOrigin', + './CompositeMaterialProperty', + './CompositePositionProperty', + './CompositeProperty', + './ConstantPositionProperty', + './ConstantProperty', + './DynamicBillboard', './DynamicClock', - './processCzml', + './ColorMaterialProperty', + './DynamicCone', + './DynamicLabel', + './DynamicDirectionsProperty', + './DynamicEllipse', + './DynamicEllipsoid', + './GridMaterialProperty', + './ImageMaterialProperty', './DynamicObjectCollection', + './DynamicPath', + './DynamicPoint', + './DynamicPolyline', + './DynamicPolygon', + './DynamicPyramid', + './DynamicVector', + './DynamicVertexPositionsProperty', + './SampledPositionProperty', + './SampledProperty', + './TimeIntervalCollectionPositionProperty', + './TimeIntervalCollectionProperty', + '../ThirdParty/Uri', '../ThirdParty/when' ], function( + Cartesian2, + Cartesian3, + Cartographic, + Color, ClockRange, ClockStep, + createGuid, + defaultValue, defined, DeveloperError, + Ellipsoid, Event, + HermitePolynomialApproximation, Iso8601, + JulianDate, + LagrangePolynomialApproximation, + LinearApproximation, loadJson, + CesiumMath, + Quaternion, + ReferenceFrame, + Spherical, + TimeInterval, + HorizontalOrigin, + LabelStyle, + VerticalOrigin, + CompositeMaterialProperty, + CompositePositionProperty, + CompositeProperty, + ConstantPositionProperty, + ConstantProperty, + DynamicBillboard, DynamicClock, - processCzml, + ColorMaterialProperty, + DynamicCone, + DynamicLabel, + DynamicDirectionsProperty, + DynamicEllipse, + DynamicEllipsoid, + GridMaterialProperty, + ImageMaterialProperty, DynamicObjectCollection, + DynamicPath, + DynamicPoint, + DynamicPolyline, + DynamicPolygon, + DynamicPyramid, + DynamicVector, + DynamicVertexPositionsProperty, + SampledPositionProperty, + SampledProperty, + TimeIntervalCollectionPositionProperty, + TimeIntervalCollectionProperty, + Uri, when) { "use strict"; + var scratchCartesian = new Cartesian3(); + var scratchSpherical = new Spherical(); + var scratchCartographic = new Cartographic(); + + function unwrapColorInterval(czmlInterval) { + var rgbaf = czmlInterval.rgbaf; + if (defined(rgbaf)) { + return rgbaf; + } + + var rgba = czmlInterval.rgba; + if (!defined(rgba)) { + return undefined; + } + + if (rgba.length === Color.length) { + return [Color.byteToFloat(rgba[0]), Color.byteToFloat(rgba[1]), Color.byteToFloat(rgba[2]), Color.byteToFloat(rgba[3])]; + } + + var len = rgba.length; + rgbaf = new Array(len); + for ( var i = 0; i < len; i += 5) { + rgbaf[i] = rgba[i]; + rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]); + rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]); + rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]); + rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]); + } + return rgbaf; + } + + function unwrapImageInterval(czmlInterval, sourceUri) { + var result = defaultValue(czmlInterval.image, czmlInterval); + if (defined(sourceUri)) { + var baseUri = new Uri(document.location.href); + sourceUri = new Uri(sourceUri); + result = new Uri(result).resolve(sourceUri.resolve(baseUri)).toString(); + } + return result; + } + + function unwrapCartesianInterval(czmlInterval) { + if (defined(czmlInterval.cartesian)) { + return czmlInterval.cartesian; + } + + if (defined(czmlInterval.unitCartesian)) { + return czmlInterval.unitCartesian; + } + + var i; + var len; + var result; + + var unitSpherical = czmlInterval.unitSpherical; + if (defined(unitSpherical)) { + len = unitSpherical.length; + if (len === 2) { + scratchSpherical.clock = unitSpherical[0]; + scratchSpherical.cone = unitSpherical[1]; + Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); + result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; + } else { + var sphericalIt = 0; + result = new Array((len / 3) * 4); + for (i = 0; i < len; i += 4) { + result[i] = unitSpherical[sphericalIt++]; + + scratchSpherical.clock = unitSpherical[sphericalIt++]; + scratchSpherical.cone = unitSpherical[sphericalIt++]; + Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); + + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + } + return result; + } + + var cartographic = czmlInterval.cartographicRadians; + if (defined(cartographic)) { + if (cartographic.length === 3) { + scratchCartographic.longitude = cartographic[0]; + scratchCartographic.latitude = cartographic[1]; + scratchCartographic.height = cartographic[2]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; + } else { + len = cartographic.length; + result = new Array(len); + for (i = 0; i < len; i += 4) { + scratchCartographic.longitude = cartographic[i + 0]; + scratchCartographic.latitude = cartographic[i + 1]; + scratchCartographic.height = cartographic[i + 2]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + + result[i] = cartographic[i]; + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + } + return result; + } + + var cartographicDegrees = czmlInterval.cartographicDegrees; + if (!defined(cartographicDegrees)) { + return undefined; + } + + if (cartographicDegrees.length > 3) { + scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[0]); + scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]); + scratchCartographic.height = cartographicDegrees[2]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + result = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; + } else { + len = cartographicDegrees.length; + result = new Array(len); + for (i = 0; i < len; i += 4) { + scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]); + scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]); + scratchCartographic.height = cartographicDegrees[i + 3]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + + result[i] = cartographicDegrees[i]; + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + } + + return result; + } + + function unwrapInterval(type, czmlInterval, sourceUri) { + switch (type) { + case Boolean: + return defaultValue(czmlInterval.boolean, czmlInterval); + case Cartesian2: + return czmlInterval.cartesian2; + case Cartesian3: + return unwrapCartesianInterval(czmlInterval); + case Color: + return unwrapColorInterval(czmlInterval); + case HorizontalOrigin: + return HorizontalOrigin[defaultValue(czmlInterval.horizontalOrigin, czmlInterval)]; + case Image: + return unwrapImageInterval(czmlInterval, sourceUri); + case LabelStyle: + return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)]; + case Number: + return defaultValue(czmlInterval.number, czmlInterval); + case String: + return defaultValue(czmlInterval.string, czmlInterval); + case Quaternion: + return czmlInterval.unitQuaternion; + case VerticalOrigin: + return VerticalOrigin[defaultValue(czmlInterval.verticalOrigin, czmlInterval)]; + default: + throw new DeveloperError(type); + } + } + + var interpolators = { + HERMITE : HermitePolynomialApproximation, + LAGRANGE : LagrangePolynomialApproximation, + LINEAR : LinearApproximation + }; + + function updateInterpolationSettings(packetData, property) { + var interpolator = interpolators[packetData.interpolationAlgorithm]; + if (defined(interpolator)) { + property.interpolationAlgorithm = interpolator; + } + if (defined(packetData.interpolationDegree)) { + property.interpolationDegree = packetData.interpolationDegree; + } + } + + function processProperty(type, object, propertyName, packetData, constrainedInterval, sourceUri) { + var combinedInterval; + var packetInterval = packetData.interval; + if (defined(packetInterval)) { + combinedInterval = TimeInterval.fromIso8601(packetInterval); + if (defined(constrainedInterval)) { + combinedInterval = combinedInterval.intersect(constrainedInterval); + } + } else if (defined(constrainedInterval)) { + combinedInterval = constrainedInterval; + } + + var unwrappedInterval = unwrapInterval(type, packetData, sourceUri); + var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL); + var packedLength = defaultValue(type.packedLength, 1); + var unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1); + var isSampled = (typeof unwrappedInterval !== 'string') && unwrappedIntervalLength > packedLength; + + //Any time a constant value is assigned, it completely blows away anything else. + if (!isSampled && !hasInterval) { + if (defined(type.unpack)) { + object[propertyName] = new ConstantProperty(type.unpack(unwrappedInterval, 0)); + } else { + object[propertyName] = new ConstantProperty(unwrappedInterval); + } + return true; + } + + var propertyCreated = false; + var property = object[propertyName]; + + //Without an interval, any sampled value is infinite, meaning it completely + //replaces any non-sampled property that may exist. + if (isSampled && !hasInterval) { + if (!(property instanceof SampledProperty)) { + property = new SampledProperty(type); + object[propertyName] = property; + propertyCreated = true; + } + property.addSamplesPackedArray(unwrappedInterval, JulianDate.fromIso8601(packetData.epoch)); + updateInterpolationSettings(packetData, property); + return propertyCreated; + } + + var interval; + + //A constant value with an interval is normally part of a TimeIntervalCollection, + //However, if the current property is not a time-interval collection, we need + //to turn it into a Composite, preserving the old data with the new interval. + if (!isSampled && hasInterval) { + //Create a new interval for the constant value. + combinedInterval = combinedInterval.clone(); + if (defined(type.unpack)) { + combinedInterval.data = type.unpack(unwrappedInterval, 0); + } else { + combinedInterval.data = unwrappedInterval; + } + + //If no property exists, simply use a new interval collection + if (!defined(property)) { + property = new TimeIntervalCollectionProperty(); + object[propertyName] = property; + propertyCreated = true; + } + + if (property instanceof TimeIntervalCollectionProperty) { + //If we create a collection, or it already existed, use it. + property.intervals.addInterval(combinedInterval); + } else if (property instanceof CompositeProperty) { + //If the collection was already a CompositeProperty, use it. + combinedInterval.data = new ConstantProperty(combinedInterval.data); + property.intervals.addInterval(combinedInterval); + } else { + //Otherwise, create a CompositeProperty but preserve the existing data. + + //Put the old property in an infinite interval. + interval = Iso8601.MAXIMUM_INTERVAL.clone(); + interval.data = property; + + //Create the composite. + propertyCreated = true; + property = new CompositeProperty(); + object[propertyName] = property; + + //add the old property interval + property.intervals.addInterval(interval); + + //Change the new data to a ConstantProperty and add it. + combinedInterval.data = new ConstantProperty(combinedInterval.data); + property.intervals.addInterval(combinedInterval); + } + + return propertyCreated; + } + + //isSampled && hasInterval + if (!defined(property)) { + propertyCreated = true; + property = new CompositeProperty(); + object[propertyName] = property; + } + + //create a CompositeProperty but preserve the existing data. + if (!(property instanceof CompositeProperty)) { + //Put the old property in an infinite interval. + interval = Iso8601.MAXIMUM_INTERVAL.clone(); + interval.data = property; + + //Create the composite. + propertyCreated = true; + property = new CompositeProperty(); + object[propertyName] = property; + + //add the old property interval + property.intervals.addInterval(interval); + } + + //Check if the interval already exists in the composite + var intervals = property.intervals; + interval = intervals.findInterval(combinedInterval.start, combinedInterval.stop, combinedInterval.isStartIncluded, combinedInterval.isStopIncluded); + if (!defined(interval) || !(interval.data instanceof SampledProperty)) { + //If not, create a SampledProperty for it. + interval = combinedInterval.clone(); + interval.data = new SampledProperty(type); + intervals.addInterval(interval); + } + interval.data.addSamplesPackedArray(unwrappedInterval, JulianDate.fromIso8601(packetData.epoch)); + updateInterpolationSettings(packetData, interval.data); + return propertyCreated; + } + + function processPacketData(type, object, propertyName, packetData, interval, sourceUri) { + if (!defined(packetData)) { + return false; + } + + var updated = false; + if (Array.isArray(packetData)) { + for ( var i = 0, len = packetData.length; i < len; i++) { + updated = processProperty(type, object, propertyName, packetData[i], interval, sourceUri) || updated; + } + } else { + updated = processProperty(type, object, propertyName, packetData, interval, sourceUri) || updated; + } + return updated; + } + + function processPositionProperty(object, propertyName, packetData, constrainedInterval, sourceUri) { + var combinedInterval; + var packetInterval = packetData.interval; + if (defined(packetInterval)) { + combinedInterval = TimeInterval.fromIso8601(packetInterval); + if (defined(constrainedInterval)) { + combinedInterval = combinedInterval.intersect(constrainedInterval); + } + } else if (defined(constrainedInterval)) { + combinedInterval = constrainedInterval; + } + + var referenceFrame = ReferenceFrame[defaultValue(packetData.referenceFrame, "FIXED")]; + var unwrappedInterval = unwrapCartesianInterval(packetData); + var hasInterval = defined(combinedInterval) && !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL); + var packedLength = Cartesian3.packedLength; + var unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1); + var isSampled = (typeof unwrappedInterval !== 'string') && unwrappedIntervalLength > packedLength; + + //Any time a constant value is assigned, it completely blows away anything else. + if (!isSampled && !hasInterval) { + object[propertyName] = new ConstantPositionProperty(Cartesian3.unpack(unwrappedInterval), referenceFrame); + return true; + } + + var propertyCreated = false; + var property = object[propertyName]; + + //Without an interval, any sampled value is infinite, meaning it completely + //replaces any non-sampled property that may exist. + if (isSampled && !hasInterval) { + if (!(property instanceof SampledProperty) || property.referenceFrame !== referenceFrame) { + property = new SampledPositionProperty(referenceFrame); + object[propertyName] = property; + propertyCreated = true; + } + property.addSamplesPackedArray(unwrappedInterval, JulianDate.fromIso8601(packetData.epoch)); + updateInterpolationSettings(packetData, property); + return propertyCreated; + } + + var interval; + + //A constant value with an interval is normally part of a TimeIntervalCollection, + //However, if the current property is not a time-interval collection, we need + //to turn it into a Composite, preserving the old data with the new interval. + if (!isSampled && hasInterval) { + //Create a new interval for the constant value. + combinedInterval = combinedInterval.clone(); + combinedInterval.data = Cartesian3.unpack(unwrappedInterval); + + //If no property exists, simply use a new interval collection + if (!defined(property)) { + property = new TimeIntervalCollectionPositionProperty(referenceFrame); + object[propertyName] = property; + propertyCreated = true; + } + + if (property instanceof TimeIntervalCollectionPositionProperty && property.referenceFrame === referenceFrame) { + //If we create a collection, or it already existed, use it. + property.intervals.addInterval(combinedInterval); + } else if (property instanceof CompositePositionProperty) { + //If the collection was already a CompositeProperty, use it. + combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame); + property.intervals.addInterval(combinedInterval); + } else { + //Otherwise, create a CompositeProperty but preserve the existing data. + + //Put the old property in an infinite interval. + interval = Iso8601.MAXIMUM_INTERVAL.clone(); + interval.data = property; + + //Create the composite. + propertyCreated = true; + property = new CompositePositionProperty(property.referenceFrame); + object[propertyName] = property; + + //add the old property interval + property.intervals.addInterval(interval); + + //Change the new data to a ConstantProperty and add it. + combinedInterval.data = new ConstantPositionProperty(combinedInterval.data, referenceFrame); + property.intervals.addInterval(combinedInterval); + } + + return propertyCreated; + } + + //isSampled && hasInterval + if (!defined(property)) { + propertyCreated = true; + property = new CompositePositionProperty(referenceFrame); + object[propertyName] = property; + } else if (!(property instanceof CompositePositionProperty)) { + //create a CompositeProperty but preserve the existing data. + //Put the old property in an infinite interval. + interval = Iso8601.MAXIMUM_INTERVAL.clone(); + interval.data = property; + + //Create the composite. + propertyCreated = true; + property = new CompositePositionProperty(property.referenceFrame); + object[propertyName] = property; + + //add the old property interval + property.intervals.addInterval(interval); + } + + //Check if the interval already exists in the composite + var intervals = property.intervals; + interval = intervals.findInterval(combinedInterval.start, combinedInterval.stop, combinedInterval.isStartIncluded, combinedInterval.isStopIncluded); + if (!defined(interval) || !(interval.data instanceof SampledPositionProperty) || interval.data.referenceFrame !== referenceFrame) { + //If not, create a SampledProperty for it. + interval = combinedInterval.clone(); + interval.data = new SampledPositionProperty(referenceFrame); + intervals.addInterval(interval); + } + interval.data.addSamplesPackedArray(unwrappedInterval, JulianDate.fromIso8601(packetData.epoch)); + updateInterpolationSettings(packetData, interval.data); + return propertyCreated; + } + + function processPositionPacketData(object, propertyName, packetData, interval, sourceUri) { + if (!defined(packetData)) { + return false; + } + + var updated = false; + if (Array.isArray(packetData)) { + for ( var i = 0, len = packetData.length; i < len; i++) { + updated = processPositionProperty(object, propertyName, packetData[i], interval, sourceUri) || updated; + } + } else { + updated = processPositionProperty(object, propertyName, packetData, interval, sourceUri) || updated; + } + return updated; + } + + var Cartesian2WrapperProperty = function() { + this._x = new ConstantProperty(0); + this._y = new ConstantProperty(0); + }; + + Cartesian2WrapperProperty.prototype.getValue = function(time, result) { + if (!defined(result)) { + result = new Cartesian2(); + } + result.x = this._x.getValue(time); + result.y = this._y.getValue(time); + return result; + }; + + function combineIntoCartesian2(object, packetDataX, packetDataY) { + if (!defined(packetDataX) && !defined(packetDataY)) { + return object; + } + if (!(object instanceof Cartesian2WrapperProperty)) { + object = new Cartesian2WrapperProperty(); + } + processPacketData(Number, object, '_x', packetDataX); + processPacketData(Number, object, '_y', packetDataY); + return object; + } + + function processMaterialProperty(object, propertyName, packetData, constrainedInterval, sourceUri) { + var combinedInterval; + var packetInterval = packetData.interval; + if (defined(packetInterval)) { + combinedInterval = TimeInterval.fromIso8601(packetInterval); + if (defined(constrainedInterval)) { + combinedInterval = combinedInterval.intersect(constrainedInterval); + } + } else if (defined(constrainedInterval)) { + combinedInterval = constrainedInterval; + } + + combinedInterval = defaultValue(combinedInterval, Iso8601.MAXIMUM_INTERVAL); + + var propertyCreated = false; + var property = object[propertyName]; + if (!defined(property)) { + property = new CompositeMaterialProperty(); + object[propertyName] = property; + propertyCreated = true; + } + + //See if we already have data at that interval. + var thisIntervals = property.intervals; + var existingInterval = thisIntervals.findInterval(combinedInterval.start, combinedInterval.stop); + var existingMaterial; + + if (defined(existingInterval)) { + //We have an interval, but we need to make sure the + //new data is the same type of material as the old data. + existingMaterial = existingInterval.data; + } else { + //If not, create it. + existingInterval = combinedInterval.clone(); + thisIntervals.addInterval(existingInterval); + } + + var materialData; + if (defined(packetData.solidColor)) { + if (!(existingMaterial instanceof ColorMaterialProperty)) { + existingMaterial = new ColorMaterialProperty(); + } + materialData = packetData.solidColor; + processPacketData(Color, existingMaterial, 'color', materialData.color); + } else if (defined(packetData.grid)) { + if (!(existingMaterial instanceof GridMaterialProperty)) { + existingMaterial = new GridMaterialProperty(); + } + materialData = packetData.grid; + processPacketData(Color, existingMaterial, 'color', materialData.color, undefined, sourceUri); + processPacketData(Number, existingMaterial, 'cellAlpha', materialData.cellAlpha, undefined, sourceUri); + existingMaterial.lineThickness = combineIntoCartesian2(existingMaterial.lineThickness, materialData.rowThickness, materialData.columnThickness); + existingMaterial.lineCount = combineIntoCartesian2(existingMaterial.lineCount, materialData.rowCount, materialData.columnCount); + } else if (defined(packetData.image)) { + if (!(existingMaterial instanceof ImageMaterialProperty)) { + existingMaterial = new ImageMaterialProperty(); + } + materialData = packetData.image; + processPacketData(Image, existingMaterial, 'image', materialData.image, undefined, sourceUri); + existingMaterial.repeat = combineIntoCartesian2(existingMaterial.repeat, materialData.horizontalRepeat, materialData.verticalRepeat); + } + existingInterval.data = existingMaterial; + + return propertyCreated; + } + + function processMaterialPacketData(object, propertyName, packetData, interval, sourceUri){ + if (!defined(packetData)) { + return false; + } + + var updated = false; + if (Array.isArray(packetData)) { + for ( var i = 0, len = packetData.length; i < len; i++) { + updated = processMaterialProperty(object, propertyName, packetData[i], interval, sourceUri) || updated; + } + } else { + updated = processMaterialProperty(object, propertyName, packetData, interval, sourceUri) || updated; + } + return updated; + } + + function processPosition(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var positionData = packet.position; + if (!defined(positionData)) { + return false; + } + return processPositionPacketData(dynamicObject, 'position', positionData, undefined, sourceUri); + } + + function processViewFrom(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var viewFromData = packet.viewFrom; + if (!defined(viewFromData)) { + return false; + } + return processPacketData(Cartesian3, dynamicObject, 'viewFrom', viewFromData, undefined, sourceUri); + } + + function processOrientation(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var orientationData = packet.orientation; + if (!defined(orientationData)) { + return false; + } + + return processPacketData(Quaternion, dynamicObject, 'orientation', orientationData, undefined, sourceUri); + } + + function processVertexPositions(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var vertexPositionsData = packet.vertexPositions; + if (!defined(vertexPositionsData)) { + return false; + } + + var vertexPositions = dynamicObject.vertexPositions; + var propertyCreated = !defined(dynamicObject.vertexPositions); + if (propertyCreated) { + dynamicObject.vertexPositions = vertexPositions = new DynamicVertexPositionsProperty(); + } + vertexPositions.processCzmlIntervals(vertexPositionsData, undefined, dynamicObjectCollection); + return propertyCreated; + } + + function processAvailability(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var availability = packet.availability; + if (!defined(availability)) { + return false; + } + + var propertyChanged = false; + var interval = TimeInterval.fromIso8601(availability); + if (defined(interval)) { + propertyChanged = dynamicObject._setAvailability(interval); + } + return propertyChanged; + } + + function processBillboard(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var billboardData = packet.billboard; + if (!defined(billboardData)) { + return false; + } + + var interval = billboardData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var billboard = dynamicObject.billboard; + var billboardUpdated = !defined(billboard); + if (billboardUpdated) { + dynamicObject.billboard = billboard = new DynamicBillboard(); + } + + billboardUpdated = processPacketData(Color, billboard, 'color', billboardData.color, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Cartesian3, billboard, 'eyeOffset', billboardData.eyeOffset, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(HorizontalOrigin, billboard, 'horizontalOrigin', billboardData.horizontalOrigin, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Image, billboard, 'image', billboardData.image, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Cartesian2, billboard, 'pixelOffset', billboardData.pixelOffset, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Number, billboard, 'scale', billboardData.scale, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Number, billboard, 'rotation', billboardData.rotation, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Cartesian3, billboard, 'alignedAxis', billboardData.alignedAxis, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(Boolean, billboard, 'show', billboardData.show, interval, sourceUri) || billboardUpdated; + billboardUpdated = processPacketData(VerticalOrigin, billboard, 'verticalOrigin', billboardData.verticalOrigin, interval, sourceUri) || billboardUpdated; + + return billboardUpdated; + } + + function processClock(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var clockUpdated = false; + var clockPacket = packet.clock; + if (defined(clockPacket)) { + if (dynamicObject.id === 'document') { + var clock = dynamicObject.clock; + if (!defined(clock)) { + clock = new DynamicClock(); + dynamicObject.clock = clock; + clockUpdated = true; + } + + if (defined(clockPacket.interval)) { + var interval = TimeInterval.fromIso8601(clockPacket.interval); + if (defined(interval)) { + clock.startTime = interval.start; + clock.stopTime = interval.stop; + } + } + if (defined(clockPacket.currentTime)) { + clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime); + } + if (defined(clockPacket.range)) { + clock.clockRange = ClockRange[clockPacket.range]; + } + if (defined(clockPacket.step)) { + clock.clockStep = ClockStep[clockPacket.step]; + } + if (defined(clockPacket.multiplier)) { + clock.multiplier = clockPacket.multiplier; + } + } + } + + return clockUpdated; + } + + function processCone(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var coneData = packet.cone; + if (!defined(coneData)) { + return false; + } + + var interval = coneData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var cone = dynamicObject.cone; + var coneUpdated = !defined(cone); + if (coneUpdated) { + dynamicObject.cone = cone = new DynamicCone(); + } + + coneUpdated = processPacketData(Boolean, cone, 'show', coneData.show, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'radius', coneData.radius, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Boolean, cone, 'showIntersection', coneData.showIntersection, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Color, cone, 'intersectionColor', coneData.intersectionColor, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'intersectionWidth', coneData.intersectionWidth, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'innerHalfAngle', coneData.innerHalfAngle, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'outerHalfAngle', coneData.outerHalfAngle, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'minimumClockAngle', coneData.minimumClockAngle, interval, sourceUri) || coneUpdated; + coneUpdated = processPacketData(Number, cone, 'maximumClockAngle', coneData.maximumClockAngle, interval, sourceUri) || coneUpdated; + coneUpdated = processMaterialPacketData(cone, 'capMaterial', coneData.capMaterial, interval, sourceUri); + coneUpdated = processMaterialPacketData(cone, 'innerMaterial', coneData.innerMaterial, interval, sourceUri); + coneUpdated = processMaterialPacketData(cone, 'outerMaterial', coneData.outerMaterial, interval, sourceUri); + coneUpdated = processMaterialPacketData(cone, 'silhouetteMaterial', coneData.silhouetteMaterial, interval, sourceUri); + return coneUpdated; + } + + function processEllipse(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var ellipseData = packet.ellipse; + if (!defined(ellipseData)) { + return false; + } + + var interval = ellipseData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var ellipse = dynamicObject.ellipse; + var ellipseUpdated = !defined(ellipse); + if (ellipseUpdated) { + dynamicObject.ellipse = ellipse = new DynamicEllipse(); + } + + ellipseUpdated = processPacketData(Number, ellipse, 'bearing', ellipseData.bearing, interval, sourceUri) || ellipseUpdated; + ellipseUpdated = processPacketData(Number, ellipse, 'semiMajorAxis', ellipseData.semiMajorAxis, interval, sourceUri) || ellipseUpdated; + ellipseUpdated = processPacketData(Number, ellipse, 'semiMinorAxis', ellipseData.semiMinorAxis, interval, sourceUri) || ellipseUpdated; + + return ellipseUpdated; + } + + function processEllipsoid(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var ellipsoidData = packet.ellipsoid; + if (!defined(ellipsoidData)) { + return false; + } + + var interval = ellipsoidData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var ellipsoid = dynamicObject.ellipsoid; + var ellipsoidUpdated = !defined(ellipsoid); + if (ellipsoidUpdated) { + dynamicObject.ellipsoid = ellipsoid = new DynamicEllipsoid(); + } + + ellipsoidUpdated = processPacketData(Boolean, ellipsoid, 'show', ellipsoidData.show, interval, sourceUri) || ellipsoidUpdated; + ellipsoidUpdated = processPacketData(Cartesian3, ellipsoid, 'radii', ellipsoidData.radii, interval, sourceUri) || ellipsoidUpdated; + ellipsoidUpdated = processMaterialPacketData(ellipsoid, 'material', ellipsoidData.material, interval, sourceUri); + return ellipsoidUpdated; + } + + function processLabel(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var labelData = packet.label; + if (!defined(labelData)) { + return false; + } + + var interval = labelData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var label = dynamicObject.label; + var labelUpdated = !defined(label); + if (labelUpdated) { + dynamicObject.label = label = new DynamicLabel(); + } + + labelUpdated = processPacketData(Color, label, 'fillColor', labelData.fillColor, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Color, label, 'outlineColor', labelData.outlineColor, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Number, label, 'outlineWidth', labelData.outlineWidth, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Cartesian3, label, 'eyeOffset', labelData.eyeOffset, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(HorizontalOrigin, label, 'horizontalOrigin', labelData.horizontalOrigin, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(String, label, 'text', labelData.text, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Cartesian2, label, 'pixelOffset', labelData.pixelOffset, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Number, label, 'scale', labelData.scale, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(Boolean, label, 'show', labelData.show, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(VerticalOrigin, label, 'verticalOrigin', labelData.verticalOrigin, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(String, label, 'font', labelData.font, interval, sourceUri) || labelUpdated; + labelUpdated = processPacketData(LabelStyle, label, 'style', labelData.style, interval, sourceUri) || labelUpdated; + + return labelUpdated; + } + + function processPath(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var pathData = packet.path; + if (!defined(pathData)) { + return false; + } + + var interval = pathData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var path = dynamicObject.path; + var pathUpdated = !defined(path); + if (pathUpdated) { + dynamicObject.path = path = new DynamicPath(); + } + + pathUpdated = processPacketData(Color, path, 'color', pathData.color, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Number, path, 'width', pathData.width, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Color, path, 'outlineColor', pathData.outlineColor, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Number, path, 'outlineWidth', pathData.outlineWidth, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Boolean, path, 'show', pathData.show, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Number, path, 'resolution', pathData.resolution, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Number, path, 'leadTime', pathData.leadTime, interval, sourceUri) || pathUpdated; + pathUpdated = processPacketData(Number, path, 'trailTime', pathData.trailTime, interval, sourceUri) || pathUpdated; + return pathUpdated; + } + + function processPoint(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var pointData = packet.point; + if (!defined(pointData)) { + return false; + } + + var interval = pointData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var point = dynamicObject.point; + var pointUpdated = !defined(point); + if (pointUpdated) { + dynamicObject.point = point = new DynamicPoint(); + } + + pointUpdated = processPacketData(Color, point, 'color', pointData.color, interval, sourceUri) || pointUpdated; + pointUpdated = processPacketData(Number, point, 'pixelSize', pointData.pixelSize, interval, sourceUri) || pointUpdated; + pointUpdated = processPacketData(Color, point, 'outlineColor', pointData.outlineColor, interval, sourceUri) || pointUpdated; + pointUpdated = processPacketData(Number, point, 'outlineWidth', pointData.outlineWidth, interval, sourceUri) || pointUpdated; + pointUpdated = processPacketData(Boolean, point, 'show', pointData.show, interval, sourceUri) || pointUpdated; + + return pointUpdated; + } + + function processPolygon(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var polygonData = packet.polygon; + if (!defined(polygonData)) { + return false; + } + + var interval = polygonData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var polygon = dynamicObject.polygon; + var polygonUpdated = !defined(polygon); + if (polygonUpdated) { + dynamicObject.polygon = polygon = new DynamicPolygon(); + } + + polygonUpdated = processPacketData(Boolean, polygon, 'show', polygonData.show, interval, sourceUri) || polygonUpdated; + polygonUpdated = processMaterialPacketData(polygon, 'material', polygonData.material, interval, sourceUri); + return polygonUpdated; + } + + function processPolyline(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var polylineData = packet.polyline; + if (!defined(polylineData)) { + return false; + } + + var interval = polylineData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var polyline = dynamicObject.polyline; + var polylineUpdated = !defined(polyline); + if (polylineUpdated) { + dynamicObject.polyline = polyline = new DynamicPolyline(); + } + + polylineUpdated = processPacketData(Color, polyline, 'color', polylineData.color, interval, sourceUri) || polylineUpdated; + polylineUpdated = processPacketData(Number, polyline, 'width', polylineData.width, interval, sourceUri) || polylineUpdated; + polylineUpdated = processPacketData(Color, polyline, 'outlineColor', polylineData.outlineColor, interval, sourceUri) || polylineUpdated; + polylineUpdated = processPacketData(Number, polyline, 'outlineWidth', polylineData.outlineWidth, interval, sourceUri) || polylineUpdated; + polylineUpdated = processPacketData(Boolean, polyline, 'show', polylineData.show, interval, sourceUri) || polylineUpdated; + return polylineUpdated; + } + + function processPyramid(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var pyramidData = packet.pyramid; + if (!defined(pyramidData)) { + return false; + } + + var interval = pyramidData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var pyramid = dynamicObject.pyramid; + var pyramidUpdated = !defined(pyramid); + if (pyramidUpdated) { + dynamicObject.pyramid = pyramid = new DynamicPyramid(); + } + + pyramidUpdated = processPacketData(Boolean, pyramid, 'show', pyramidData.show, interval, sourceUri) || pyramidUpdated; + pyramidUpdated = processPacketData(Number, pyramid, 'radius', pyramidData.radius, interval, sourceUri) || pyramidUpdated; + pyramidUpdated = processPacketData(Boolean, pyramid, 'showIntersection', pyramidData.showIntersection, interval, sourceUri) || pyramidUpdated; + pyramidUpdated = processPacketData(Color, pyramid, 'intersectionColor', pyramidData.intersectionColor, interval, sourceUri) || pyramidUpdated; + pyramidUpdated = processPacketData(Number, pyramid, 'intersectionWidth', pyramidData.intersectionWidth, interval, sourceUri) || pyramidUpdated; + pyramidUpdated = processMaterialPacketData(pyramid, 'material', pyramidData.material, interval, sourceUri); + + if (defined(pyramidData.directions)) { + var directions = pyramid.directions; + if (!defined(directions)) { + pyramid.directions = directions = new DynamicDirectionsProperty(); + pyramidUpdated = true; + } + directions.processCzmlIntervals(pyramidData.directions, interval); + } + + return pyramidUpdated; + } + + function processVector(dynamicObject, packet, dynamicObjectCollection, sourceUri) { + var vectorData = packet.vector; + if (!defined(vectorData)) { + return false; + } + + var interval = vectorData.interval; + if (defined(interval)) { + interval = TimeInterval.fromIso8601(interval); + } + + var vector = dynamicObject.vector; + var vectorUpdated = !defined(vector); + if (vectorUpdated) { + dynamicObject.vector = vector = new DynamicVector(); + } + + vectorUpdated = processPacketData(Color, vector, 'color', vectorData.color, interval, sourceUri) || vectorUpdated; + vectorUpdated = processPacketData(Boolean, vector, 'show', vectorData.show, interval, sourceUri) || vectorUpdated; + vectorUpdated = processPacketData(Number, vector, 'width', vectorData.width, interval, sourceUri) || vectorUpdated; + vectorUpdated = processPacketData(Cartesian3, vector, 'direction', vectorData.direction, interval, sourceUri) || vectorUpdated; + vectorUpdated = processPacketData(Number, vector, 'length', vectorData.length, interval, sourceUri) || vectorUpdated; + + return vectorUpdated; + } + + function processCzmlPacket(packet, dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri) { + var objectId = packet.id; + if (!defined(objectId)) { + objectId = createGuid(); + } + + if (packet['delete'] === true) { + dynamicObjectCollection.removeObject(objectId); + } else { + var object = dynamicObjectCollection.getOrCreateObject(objectId); + for ( var i = updaterFunctions.length - 1; i > -1; i--) { + if (updaterFunctions[i](object, packet, dynamicObjectCollection, sourceUri) && !defined(updatedObjectsHash[objectId])) { + updatedObjectsHash[objectId] = true; + updatedObjects.push(object); + } + } + } + } + function loadCzml(dataSource, czml, sourceUri) { var dynamicObjectCollection = dataSource._dynamicObjectCollection; - processCzml(czml, dynamicObjectCollection, sourceUri); + CzmlDataSource._processCzml(czml, dynamicObjectCollection, sourceUri); var availability = dynamicObjectCollection.computeAvailability(); var clock; @@ -67,6 +1146,29 @@ define([ this._timeVarying = true; }; + /** + * Gets the array of CZML processing functions. + * @memberof CzmlDataSource + * @type Array + */ + CzmlDataSource.updaters = [processClock,// + processBillboard, // + processEllipse, // + processEllipsoid, // + processCone, // + processLabel, // + processPath, // + processPoint, // + processPolygon, // + processPolyline, // + processPyramid, // + processVector, // + processPosition, // + processViewFrom, // + processOrientation, // + processVertexPositions, // + processAvailability]; + /** * Gets an event that will be raised when non-time-varying data changes * or if the return value of getIsTimeVarying changes. @@ -200,5 +1302,25 @@ define([ }); }; + CzmlDataSource._processCzml = function(czml, dynamicObjectCollection, sourceUri, updaterFunctions) { + var updatedObjects = []; + var updatedObjectsHash = {}; + updaterFunctions = defined(updaterFunctions) ? updaterFunctions : CzmlDataSource.updaters; + + if (Array.isArray(czml)) { + for ( var i = 0, len = czml.length; i < len; i++) { + processCzmlPacket(czml[i], dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri); + } + } else { + processCzmlPacket(czml, dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri); + } + + if (updatedObjects.length > 0) { + dynamicObjectCollection.objectPropertiesChanged.raiseEvent(dynamicObjectCollection, updatedObjects); + } + + return updatedObjects; + }; + return CzmlDataSource; }); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlDefaults.js b/Source/DynamicScene/CzmlDefaults.js deleted file mode 100644 index 8b84bab58e38..000000000000 --- a/Source/DynamicScene/CzmlDefaults.js +++ /dev/null @@ -1,153 +0,0 @@ -/*global define*/ -define([ - './DynamicObject', - './DynamicBillboard', - './DynamicClock', - './DynamicEllipse', - './DynamicEllipsoid', - './DynamicCone', - './DynamicLabel', - './DynamicPath', - './DynamicPoint', - './DynamicPolygon', - './DynamicPolyline', - './DynamicPyramid', - './DynamicVector', - './DynamicBillboardVisualizer', - './DynamicEllipsoidVisualizer', - './DynamicConeVisualizerUsingCustomSensor', //CZML_TODO Replace with './DynamicConeVisualizer', once ComplexConicSensor works. - './DynamicLabelVisualizer', - './DynamicPathVisualizer', - './DynamicPointVisualizer', - './DynamicPolygonVisualizer', - './DynamicPolylineVisualizer', - './DynamicPyramidVisualizer', - './DynamicVectorVisualizer' - ], function( - DynamicObject, - DynamicBillboard, - DynamicClock, - DynamicEllipse, - DynamicEllipsoid, - DynamicCone, - DynamicLabel, - DynamicPath, - DynamicPoint, - DynamicPolygon, - DynamicPolyline, - DynamicPyramid, - DynamicVector, - DynamicBillboardVisualizer, - DynamicEllipsoidVisualizer, - DynamicConeVisualizer, - DynamicLabelVisualizer, - DynamicPathVisualizer, - DynamicPointVisualizer, - DynamicPolygonVisualizer, - DynamicPolylineVisualizer, - DynamicPyramidVisualizer, - DynamicVectorVisualizer) { - "use strict"; - - /** - * Helper class which provides the default set of CZML processing methods - * needed to visualize the complete CZML standard. There's no reason to - * access this class directly, as it just holds the defaults used by - * DynamicObjectCollection, CompositeDynamicObjectCollection, and VisualizerCollection. - * - * @exports CzmlDefaults - * - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see VisualizerCollection#createCzmlDefaultsCollection - */ - var CzmlDefaults = { - //Any change to updaters needs to be reflected in the DynamicObject constructor, - //which has the superset of all properties created by the various updaters. - /** - * The standard set of updaters for processing CZML. This array is the default - * set of updater methods used by DynamicObjectCollection. - * @see DynamicObjectCollection - */ - updaters : [DynamicClock.processCzmlPacket, - DynamicBillboard.processCzmlPacket, - DynamicEllipse.processCzmlPacket, - DynamicEllipsoid.processCzmlPacket, - DynamicCone.processCzmlPacket, - DynamicLabel.processCzmlPacket, - DynamicPath.processCzmlPacket, - DynamicPoint.processCzmlPacket, - DynamicPolygon.processCzmlPacket, - DynamicPolyline.processCzmlPacket, - DynamicPyramid.processCzmlPacket, - DynamicVector.processCzmlPacket, - DynamicObject.processCzmlPacketPosition, - DynamicObject.processCzmlPacketViewFrom, - DynamicObject.processCzmlPacketOrientation, - DynamicObject.processCzmlPacketVertexPositions, - DynamicObject.processCzmlPacketAvailability], - - /** - * The standard set of mergers for processing CZML. This array is the default - * set of updater methods used by CompositeDynamicObjectCollection. - * - * @see CompositeDynamicObjectCollection - */ - mergers : [DynamicClock.mergeProperties, - DynamicBillboard.mergeProperties, - DynamicEllipse.mergeProperties, - DynamicEllipsoid.mergeProperties, - DynamicCone.mergeProperties, - DynamicLabel.mergeProperties, - DynamicPath.mergeProperties, - DynamicPoint.mergeProperties, - DynamicPolygon.mergeProperties, - DynamicPolyline.mergeProperties, - DynamicPyramid.mergeProperties, - DynamicVector.mergeProperties, - DynamicObject.mergeProperties], - - /** - * The standard set of cleaners for processing CZML. This array is the default - * set of updater methods used by CompositeDynamicObjectCollection. - * - * @see CompositeDynamicObjectCollection - */ - cleaners : [DynamicBillboard.undefineProperties, - DynamicEllipse.undefineProperties, - DynamicEllipsoid.undefineProperties, - DynamicCone.undefineProperties, - DynamicLabel.undefineProperties, - DynamicPath.undefineProperties, - DynamicPoint.undefineProperties, - DynamicPolygon.undefineProperties, - DynamicPolyline.undefineProperties, - DynamicPyramid.undefineProperties, - DynamicVector.undefineProperties, - DynamicObject.undefineProperties, - DynamicClock.undefineProperties], - - /** - * Creates an array containing the standard CZML visualizers, - * configured for the provided scene. - * - * @param scene The scene being used for visualization. - * @returns {Array} The CZML standard visualizers. - * @see VisualizerCollection#createCzmlDefaultsCollection - */ - createVisualizers : function(scene) { - return [new DynamicBillboardVisualizer(scene), - new DynamicEllipsoidVisualizer(scene), - new DynamicConeVisualizer(scene), - new DynamicLabelVisualizer(scene), - new DynamicPointVisualizer(scene), - new DynamicPolygonVisualizer(scene), - new DynamicPolylineVisualizer(scene), - new DynamicPyramidVisualizer(scene), - new DynamicVectorVisualizer(scene), - new DynamicPathVisualizer(scene)]; - } - }; - - return CzmlDefaults; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlDirection.js b/Source/DynamicScene/CzmlDirection.js deleted file mode 100644 index 7962461fb750..000000000000 --- a/Source/DynamicScene/CzmlDirection.js +++ /dev/null @@ -1,138 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/defined', - '../Core/Spherical', - '../Core/Math', - '../Core/Ellipsoid' - ], function( - Cartesian3, - defined, - Spherical, - CesiumMath, - Ellipsoid) { - "use strict"; - - var doublesPerValue = 3; - var scratchCartesian = new Cartesian3(); - var scratchSpherical = new Spherical(); - - /** - * Provides methods for working with a direction defined in CZML. - * - * @exports CzmlDirection - * - * @see Cartesian3 - * @see Spherical - * @see DynamicProperty - * @see DynamicDirectionProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlDirection = { - /** - * The number of doubles per packed Cartesian3 value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Cartesian3 representation contained within the provided CZML interval - * or undefined if the interval does not contain Cartesian3 data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - var unitCartesian = czmlInterval.unitCartesian; - if (defined(unitCartesian)) { - return unitCartesian; - } - - var unitSpherical = czmlInterval.unitSpherical; - if (defined(unitSpherical)) { - var len = unitSpherical.length; - if (len === 2) { - scratchSpherical.clock = unitSpherical[0]; - scratchSpherical.cone = unitSpherical[1]; - Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); - unitCartesian = [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; - } else { - var sphericalIt = 0; - unitCartesian = new Array((len / 3) * 4); - for ( var i = 0; i < len; i += 4) { - unitCartesian[i] = unitSpherical[sphericalIt++]; - - scratchSpherical.clock = unitSpherical[sphericalIt++]; - scratchSpherical.cone = unitSpherical[sphericalIt++]; - Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); - - unitCartesian[i + 1] = scratchCartesian.x; - unitCartesian[i + 2] = scratchCartesian.y; - unitCartesian[i + 3] = scratchCartesian.z; - } - } - } - return unitCartesian; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlDirection.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Cartesian3 instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlDirection.unwrapInterval. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - result.z = unwrappedInterval[2]; - return result; - }, - - /** - * Given a packed array of x, y, and z values, extracts a Cartesian3 instance. - * - * @param {Array} array A packed array of Cartesian3 values, where every three elements represents a Cartesian3. - * @param {Number} startingIndex The index into the array that contains the x value of the Cartesian3 you would like. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - result.z = array[startingIndex + 2]; - return result; - } - }; - - return CzmlDirection; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlHorizontalOrigin.js b/Source/DynamicScene/CzmlHorizontalOrigin.js deleted file mode 100644 index e053f8033c94..000000000000 --- a/Source/DynamicScene/CzmlHorizontalOrigin.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue', - '../Scene/HorizontalOrigin' - ], function( - defaultValue, - HorizontalOrigin) { - "use strict"; - - /** - * Provides methods for working with a horizontal origin defined in CZML. - * - * @exports CzmlHorizontalOrigin - * - * @see HorizontalOrigin - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlHorizontalOrigin = { - /** - * Returns the packed enum representation contained within the provided CZML interval - * or undefined if the interval does not contain enum data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return defaultValue(czmlInterval.horizontalOrigin, czmlInterval); - }, - - /** - * Since enums can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the HorizontalOrigin contained within the unwrappedInterval. - * - * @param {Object} unwrappedInterval The result of CzmlHorizontalOrigin.unwrapInterval. - * @returns The HorizontalOrigin value. - */ - getValue : function(unwrappedInterval) { - return HorizontalOrigin[unwrappedInterval]; - } - }; - - return CzmlHorizontalOrigin; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlImage.js b/Source/DynamicScene/CzmlImage.js deleted file mode 100644 index fb36f2264359..000000000000 --- a/Source/DynamicScene/CzmlImage.js +++ /dev/null @@ -1,68 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue', - '../Core/defined', - '../ThirdParty/Uri' - ], function( - defaultValue, - defined, - Uri) { - "use strict"; - - /** - * Provides methods for working with a image defined in CZML. - * - * @exports CzmlImage - * - * @see DynamicProperty - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlImage - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlImage = { - /** - * Returns the packed image representation contained within the provided CZML interval - * or undefined if the interval does not contain image data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval, sourceUri) { - var result = defaultValue(czmlInterval.image, czmlInterval); - if (defined(sourceUri)) { - var baseUri = new Uri(document.location.href); - sourceUri = new Uri(sourceUri); - result = new Uri(result).resolve(sourceUri.resolve(baseUri)).toString(); - } - return result; - }, - - /** - * Since CZML images can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the image value contained within the unwrappedInterval. For images - * this is the unwrappedInterval itself. - * - * @param {Object} unwrappedInterval The result of CzmlImage.unwrapInterval. - * @returns The image value. - */ - getValue : function(unwrappedInterval) { - return unwrappedInterval; - } - }; - - return CzmlImage; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlLabelStyle.js b/Source/DynamicScene/CzmlLabelStyle.js deleted file mode 100644 index 8997a4c10282..000000000000 --- a/Source/DynamicScene/CzmlLabelStyle.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue', - '../Scene/LabelStyle' - ], function( - defaultValue, - LabelStyle) { - "use strict"; - - /** - * Provides methods for working with a label style defined in CZML. - * - * @exports CzmlLabelStyle - * - * @see LabelStyle - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlLabelStyle = { - /** - * Returns the packed enum representation contained within the provided CZML interval - * or undefined if the interval does not contain enum data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return defaultValue(czmlInterval.labelStyle, czmlInterval); - }, - - /** - * Since enums can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the LabelStyle contained within the unwrappedInterval. - * - * @param {Object} unwrappedInterval The result of CzmlLabelStyle.unwrapInterval. - * @returns The LabelStyle value. - */ - getValue : function(unwrappedInterval) { - return LabelStyle[unwrappedInterval]; - } - }; - - return CzmlLabelStyle; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlNumber.js b/Source/DynamicScene/CzmlNumber.js deleted file mode 100644 index 7005a022b44d..000000000000 --- a/Source/DynamicScene/CzmlNumber.js +++ /dev/null @@ -1,84 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue' - ], function( - defaultValue) { - "use strict"; - - var doublesPerValue = 1; - - /** - * Provides methods for working with a number defined in CZML. - * - * @exports CzmlNumber - * - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlNumber = { - /** - * The number of doubles per packed value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed numerical representation contained within the provided CZML interval - * or undefined if the interval does not contain numerical data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return defaultValue(czmlInterval.number, czmlInterval); - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlNumber.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval); - }, - - /** - * Returns the numerical value contained within the unwrappedInterval. For numbers - * this is the unwrappedInterval itself. - * - * @param {Object} unwrappedInterval The result of CzmlNumber.unwrapInterval. - * @returns The boolean value. - */ - getValue : function(unwrappedInterval) { - return unwrappedInterval; - }, - - /** - * Given a packed array of numerical values, returns the number at the given index.. - * - * @param {Array} array An array of numbers. - * @param {Number} startingIndex The index into the array that contains the value you would like. - * @returns The value at the specified index. - */ - getValueFromArray : function(array, startingIndex) { - return array[startingIndex]; - } - }; - - return CzmlNumber; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlPosition.js b/Source/DynamicScene/CzmlPosition.js deleted file mode 100644 index 5059884f3c5d..000000000000 --- a/Source/DynamicScene/CzmlPosition.js +++ /dev/null @@ -1,168 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/Cartographic', - '../Core/defined', - '../Core/Math', - '../Core/Ellipsoid' - ], function( - Cartesian3, - Cartographic, - defined, - CesiumMath, - Ellipsoid) { - "use strict"; - - var doublesPerValue = 3; - var scratchCartesian = new Cartesian3(); - var scratchCartographic = new Cartographic(); - - /** - * Provides methods for working with a position defined in CZML. - * - * @exports CzmlPosition - * - * @see Cartesian3 - * @see Cartographic - * @see DynamicProperty - * @see DynamicPositionProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlPosition = { - /** - * The number of doubles per packed Cartesian3 value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Cartesian3 representation contained within the provided CZML interval - * or undefined if the interval does not contain Cartesian3 data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - var cartesian = czmlInterval.cartesian; - if (defined(cartesian)) { - return cartesian; - } - - var i; - var len; - var tmp = scratchCartesian; - var cartographic = czmlInterval.cartographicRadians; - if (defined(cartographic)) { - if (!this.isSampled(cartographic)) { - scratchCartographic.longitude = cartographic[0]; - scratchCartographic.latitude = cartographic[1]; - scratchCartographic.height = cartographic[2]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, tmp); - cartesian = [tmp.x, tmp.y, tmp.z]; - } else { - len = cartographic.length; - cartesian = new Array(len); - for (i = 0; i < len; i += 4) { - scratchCartographic.longitude = cartographic[i + 1]; - scratchCartographic.latitude = cartographic[i + 2]; - scratchCartographic.height = cartographic[i + 3]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, tmp); - - cartesian[i] = cartographic[i]; - cartesian[i + 1] = tmp.x; - cartesian[i + 2] = tmp.y; - cartesian[i + 3] = tmp.z; - } - } - } else { - var cartographicDegrees = czmlInterval.cartographicDegrees; - if (!defined(cartographicDegrees)) { - return undefined; - } - - if (!this.isSampled(cartographicDegrees)) { - scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[0]); - scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]); - scratchCartographic.height = cartographicDegrees[2]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, tmp); - cartesian = [tmp.x, tmp.y, tmp.z]; - } else { - len = cartographicDegrees.length; - cartesian = new Array(len); - for (i = 0; i < len; i += 4) { - scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]); - scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]); - scratchCartographic.height = cartographicDegrees[i + 3]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, tmp); - - cartesian[i] = cartographicDegrees[i]; - cartesian[i + 1] = tmp.x; - cartesian[i + 2] = tmp.y; - cartesian[i + 3] = tmp.z; - } - } - } - return cartesian; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlPosition.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Cartesian3 instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlPosition.unwrapInterval. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - result.z = unwrappedInterval[2]; - return result; - }, - - /** - * Given a packed array of x, y, and z values, extracts a Cartesian3 instance. - * - * @param {Array} array A packed array of Cartesian3 values, where every three elements represents a Cartesian3. - * @param {Number} startingIndex The index into the array that contains the x value of the Cartesian3 you would like. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - result.z = array[startingIndex + 2]; - return result; - } - }; - - return CzmlPosition; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlString.js b/Source/DynamicScene/CzmlString.js deleted file mode 100644 index bbfa7be806f0..000000000000 --- a/Source/DynamicScene/CzmlString.js +++ /dev/null @@ -1,58 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue' - ], function( - defaultValue) { - "use strict"; - - /** - * Provides methods for working with a string defined in CZML. - * - * @exports CzmlString - * - * @see DynamicProperty - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlString = { - /** - * Returns the packed string representation contained within the provided CZML interval - * or undefined if the interval does not contain string data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return defaultValue(czmlInterval.string, czmlInterval); - }, - - /** - * Since CZML strings can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the string value contained within the unwrappedInterval. For strings - * this is the unwrappedInterval itself. - * - * @param {Object} unwrappedInterval The result of CzmlString.unwrapInterval. - * @returns The string value. - */ - getValue : function(unwrappedInterval) { - return unwrappedInterval; - } - }; - - return CzmlString; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlUnitCartesian3.js b/Source/DynamicScene/CzmlUnitCartesian3.js deleted file mode 100644 index a1bdd9e4af93..000000000000 --- a/Source/DynamicScene/CzmlUnitCartesian3.js +++ /dev/null @@ -1,101 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/defined' - ], function( - Cartesian3, - defined) { - "use strict"; - - var doublesPerValue = 3; - - /** - * Provides methods for working with a unit Cartesian3 defined in CZML. - * - * @exports CzmlUnitCartesian3 - * - * @see Cartesian3 - * @see DynamicProperty - * @see DynamicPositionProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlUnitCartesian3 = { - /** - * The number of doubles per packed Cartesian3 value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Cartesian3 representation contained within the provided CZML interval - * or undefined if the interval does not contain Cartesian3 data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return czmlInterval.unitCartesian; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlUnitCartesian3.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Cartesian3 instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlUnitCartesian3.unwrapInterval. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - result.z = unwrappedInterval[2]; - return result.normalize(result); - }, - - /** - * Given a packed array of x, y, and z values, extracts a Cartesian3 instance. - * - * @param {Array} array A packed array of Cartesian3 values, where every three elements represents a Cartesian3. - * @param {Number} startingIndex The index into the array that contains the x value of the Cartesian3 you would like. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Cartesian3 instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Cartesian3(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - result.z = array[startingIndex + 2]; - return result.normalize(result); - } - }; - - return CzmlUnitCartesian3; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlUnitQuaternion.js b/Source/DynamicScene/CzmlUnitQuaternion.js deleted file mode 100644 index 26b98d543309..000000000000 --- a/Source/DynamicScene/CzmlUnitQuaternion.js +++ /dev/null @@ -1,174 +0,0 @@ -/*global define*/ -define([ - '../Core/Quaternion', - '../Core/defined', - '../Core/Cartesian3' - ], function( - Quaternion, - defined, - Cartesian3) { - "use strict"; - - var doublesPerCartesian = 3; - var doublesPerQuaternion = 4; - var axis = new Cartesian3(); - var rotationVector = new Cartesian3(); - var tmpQuaternion = new Quaternion(); - var quaternion0 = new Quaternion(); - var quaternion0Conjugate = new Quaternion(); - - /** - * Provides methods for working with a unit Quaternion defined in CZML. - * - * @exports CzmlUnitQuaternion - * - * @see Quaternion - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - */ - var CzmlUnitQuaternion = { - /** - * The number of doubles per packed Quaternion value. - */ - doublesPerValue : doublesPerQuaternion, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerCartesian, - - /** - * Returns the packed Quaternion representation contained within the provided CZML interval - * or undefined if the interval does not contain Quaternion data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return czmlInterval.unitQuaternion; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlUnitQuaternion.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerQuaternion; - }, - - /** - * Given a packed array of x, y, z, and w values, creates a packed array of - * Cartesian3 axis-angle rotations suitable for interpolation. - * - * @param {Array} sourceArray The packed array of quaternion values. - * @param {Array} destinationArray The array to store the packed axis-angle rotations. - * @param {Number} firstIndex The index of the first element to be packed. - * @param {Number} lastIndex The index of the last element to be packed. - */ - packValuesForInterpolation : function(sourceArray, destinationArray, firstIndex, lastIndex) { - CzmlUnitQuaternion.getValueFromArray(sourceArray, lastIndex * doublesPerQuaternion, quaternion0Conjugate); - quaternion0Conjugate.conjugate(quaternion0Conjugate); - - for ( var i = 0, len = lastIndex - firstIndex + 1; i < len; i++) { - var offset = i * doublesPerCartesian; - CzmlUnitQuaternion.getValueFromArray(sourceArray, (firstIndex + i) * doublesPerQuaternion, tmpQuaternion); - - tmpQuaternion.multiply(quaternion0Conjugate, tmpQuaternion); - - if (tmpQuaternion.w < 0) { - tmpQuaternion.negate(tmpQuaternion); - } - - tmpQuaternion.getAxis(axis); - var angle = tmpQuaternion.getAngle(); - destinationArray[offset] = axis.x * angle; - destinationArray[offset + 1] = axis.y * angle; - destinationArray[offset + 2] = axis.z * angle; - } - }, - - /** - * Given a non-sampled unwrapped interval, returns a Quaternion instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlUnitQuaternion.unwrapInterval. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Quaternion instance if result was not defined. - */ - getValue : function(unwrappedInterval, result) { - if (!defined(result)) { - result = new Quaternion(); - } - result.x = unwrappedInterval[0]; - result.y = unwrappedInterval[1]; - result.z = unwrappedInterval[2]; - result.w = unwrappedInterval[3]; - return result.normalize(result); - }, - - /** - * Given a packed array of x, y, z, and w values, extracts a Quaternion instance. - * - * @param {Array} array A packed array of Quaternion values, where every four elements represents a Cartesian3. - * @param {Number} startingIndex The index into the array that contains the x value of the Quaternion you would like. - * @param {Cartesian3} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Quaternion instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, result) { - if (!defined(result)) { - result = new Quaternion(); - } - result.x = array[startingIndex]; - result.y = array[startingIndex + 1]; - result.z = array[startingIndex + 2]; - result.w = array[startingIndex + 3]; - return result.normalize(result); - }, - - /** - * Given a packed array of axis-angle rotations returned from CzmlUnitQuaternion.packValuesForInterpolation, - * converts the desired index into a unit Quaternion. - * - * @param {Array} array The array containing the packed axis-angle rotations. - * @param {Quaternion} result The object to store the result in, if undefined a new instance will be created. - * @param {Array} sourceArray The source array of the original Quaternion values previously passed to CzmlUnitQuaternion.packValuesForInterpolation. - * @param {Number} firstIndex The index previously passed to CzmlUnitQuaternion.packValuesForInterpolation. - * @param {Number} lastIndex The index previously passed to CzmlUnitQuaternion.packValuesForInterpolation - * @returns The modified result parameter or a new Quaternion instance if result was not defined. - */ - getValueFromInterpolationResult : function(array, result, sourceArray, firstIndex, lastIndex) { - if (!defined(result)) { - result = new Quaternion(); - } - rotationVector.x = array[0]; - rotationVector.y = array[1]; - rotationVector.z = array[2]; - var magnitude = rotationVector.magnitude(); - - CzmlUnitQuaternion.getValueFromArray(sourceArray, lastIndex * doublesPerQuaternion, quaternion0); - - if (magnitude === 0) { - //Can't just use Quaternion.IDENTITY here because tmpQuaternion may be modified in the future. - tmpQuaternion.x = tmpQuaternion.y = tmpQuaternion.z = 0.0; - tmpQuaternion.w = 1.0; - } else { - Quaternion.fromAxisAngle(rotationVector, magnitude, tmpQuaternion); - } - - return result.normalize(tmpQuaternion.multiply(quaternion0, result), result); - } - }; - - return CzmlUnitQuaternion; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlUnitSpherical.js b/Source/DynamicScene/CzmlUnitSpherical.js deleted file mode 100644 index 71bb11bd591e..000000000000 --- a/Source/DynamicScene/CzmlUnitSpherical.js +++ /dev/null @@ -1,100 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Spherical' - ], function( - defined, - Spherical) { - "use strict"; - - var doublesPerValue = 2; - - /** - * Provides methods for working with a unit Spherical defined in CZML. - * - * @exports CzmlUnitSpherical - * - * @see Spherical - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlVerticalOrigin - */ - var CzmlUnitSpherical = { - /** - * The number of doubles per packed Spherical value. - */ - doublesPerValue : doublesPerValue, - - /** - * The number of doubles per packed value used for interpolation. - */ - doublesPerInterpolationValue : doublesPerValue, - - /** - * Returns the packed Spherical representation contained within the provided CZML interval - * or undefined if the interval does not contain Spherical data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return czmlInterval.unitSpherical; - }, - - /** - * Returns true if this interval represents data that should be interpolated by the client - * or false if it's a single value. - * - * @param {Object} unwrappedInterval The result of CzmlUnitSpherical.unwrapInterval. - */ - isSampled : function(unwrappedInterval) { - return Array.isArray(unwrappedInterval) && unwrappedInterval.length > doublesPerValue; - }, - - /** - * Given a non-sampled unwrapped interval, returns a Spherical instance of the data. - * - * @param {Object} unwrappedInterval The result of CzmlUnitSpherical.unwrapInterval. - * @param {Spherical} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Spherical instance if result was not defined. - */ - getValue : function(unwrappedInterval, spherical) { - if (!defined(spherical)) { - spherical = new Spherical(); - } - spherical.clock = unwrappedInterval[0]; - spherical.cone = unwrappedInterval[1]; - spherical.magnitude = 1.0; - return spherical; - }, - - /** - * Given a packed array of clock and cone values, extracts a Spherical instance. - * - * @param {Array} array A packed array of Spherical values, where every two elements represents a Spherical. - * @param {Number} startingIndex The index into the array that contains the clock value of the Spherical you would like. - * @param {Spherical} result The object to store the result in, if undefined a new instance will be created. - * @returns The modified result parameter or a new Spherical instance if result was not defined. - */ - getValueFromArray : function(array, startingIndex, spherical) { - if (!defined(spherical)) { - spherical = new Spherical(); - } - spherical.clock = array[startingIndex]; - spherical.cone = array[startingIndex + 1]; - spherical.magnitude = 1.0; - return spherical; - } - }; - - return CzmlUnitSpherical; -}); \ No newline at end of file diff --git a/Source/DynamicScene/CzmlVerticalOrigin.js b/Source/DynamicScene/CzmlVerticalOrigin.js deleted file mode 100644 index 2c5b4d67b9af..000000000000 --- a/Source/DynamicScene/CzmlVerticalOrigin.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global define*/ -define([ - '../Core/defaultValue', - '../Scene/VerticalOrigin' - ], function( - defaultValue, - VerticalOrigin) { - "use strict"; - - /** - * Provides methods for working with a vertical origin defined in CZML. - * - * @exports CzmlVerticalOrigin - * - * @see VerticalOrigin - * @see DynamicProperty - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - */ - var CzmlVerticalOrigin = { - /** - * Returns the packed enum representation contained within the provided CZML interval - * or undefined if the interval does not contain enum data. - * - * @param {Object} czmlInterval The CZML interval to unwrap. - */ - unwrapInterval : function(czmlInterval) { - return defaultValue(czmlInterval.verticalOrigin, czmlInterval); - }, - - /** - * Since enums can not be sampled, this method always returns false. - */ - isSampled : function() { - return false; - }, - - /** - * Returns the VerticalOrigin contained within the unwrappedInterval. - * - * @param {Object} unwrappedInterval The result of CzmlVerticalOrigin.unwrapInterval. - * @returns The VerticalOrigin value. - */ - getValue : function(unwrappedInterval) { - return VerticalOrigin[unwrappedInterval]; - } - }; - - return CzmlVerticalOrigin; -}); \ No newline at end of file diff --git a/Source/DynamicScene/DataSource.js b/Source/DynamicScene/DataSource.js index eae546eb92e3..fa8986c27f91 100644 --- a/Source/DynamicScene/DataSource.js +++ b/Source/DynamicScene/DataSource.js @@ -21,6 +21,7 @@ define(['../Core/DeveloperError' * Gets an event that will be raised when non-time-Varying data changes * or if the return value of getIsTimeVarying changes. * @memberof DataSource + * @function * * @returns {Event} The event. */ @@ -29,6 +30,7 @@ define(['../Core/DeveloperError' /** * Gets an event that will be raised if an error is encountered during processing. * @memberof DataSource + * @function * * @returns {Event} The event. */ @@ -37,6 +39,7 @@ define(['../Core/DeveloperError' /** * Gets the top level clock associated with this data source, or undefined if no clock exists. * @memberof DataSource + * @function * * @returns {DynamicClock} The clock associated with this data source, or undefined if none exists. */ @@ -45,6 +48,7 @@ define(['../Core/DeveloperError' /** * Gets the DynamicObjectCollection generated by this data source. * @memberof DataSource + * @function * * @returns {DynamicObjectCollection} The collection of objects generated by this data source. */ @@ -54,6 +58,7 @@ define(['../Core/DeveloperError' * Gets a value indicating if the data varies with simulation time. If the return value of * this function changes, the changed event will be raised. * @memberof DataSource + * @function * * @returns {Boolean} True if the data is varies with simulation time, false otherwise. */ diff --git a/Source/DynamicScene/DynamicBillboard.js b/Source/DynamicScene/DynamicBillboard.js index 92389811397f..72886732fa33 100644 --- a/Source/DynamicScene/DynamicBillboard.js +++ b/Source/DynamicScene/DynamicBillboard.js @@ -1,251 +1,78 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlCartesian2', - './CzmlCartesian3', - './CzmlNumber', - './CzmlImage', - './CzmlHorizontalOrigin', - './CzmlVerticalOrigin', - './CzmlColor', - './DynamicProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlCartesian2, - CzmlCartesian3, - CzmlNumber, - CzmlImage, - CzmlHorizontalOrigin, - CzmlVerticalOrigin, - CzmlColor, - DynamicProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic billboard, typically used in conjunction with DynamicBillboardVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic billboard. * * @alias DynamicBillboard * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicBillboardVisualizer - * @see VisualizerCollection - * @see Billboard - * @see BillboardCollection - * @see CzmlDefaults */ var DynamicBillboard = function() { /** - * A DynamicProperty of type CzmlImage which determines the billboard's texture. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the string {@link Property} specifying the URL of the billboard's texture. + * @type {Property} */ this.image = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the billboard's scale. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the billboard's scale. + * @type {Property} */ this.scale = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the billboard's rotation. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the billboard's rotation. + * @type {Property} */ this.rotation = undefined; /** - * A DynamicProperty of type CzmlCartesian3 which determines the billboard's aligned axis. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian3} {@link Property} specifying the billboard rotation's aligned axis. + * @type {Property} */ this.alignedAxis = undefined; /** - * A DynamicProperty of type CzmlHorizontalOrigin which determines the billboard's horizontal origin. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link HorizontalOrigin} {@link Property} specifying the billboard's horizontal origin. + * @type {Property} */ this.horizontalOrigin = undefined; /** - * A DynamicProperty of type CzmlVerticalHorigin which determines the billboard's vertical origin. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link VerticalOrigin} {@link Property} specifying the billboard's vertical origin. + * @type {Property} */ this.verticalOrigin = undefined; /** - * A DynamicProperty of type CzmlColor which determines the billboard's color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the billboard's color. + * @type {Property} */ this.color = undefined; /** - * A DynamicProperty of type CzmlCartesian3 which determines the billboard's eye offset. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian3} {@link Property} specifying the billboard's eye offset. + * @type {Property} */ this.eyeOffset = undefined; /** - * A DynamicProperty of type CzmlCartesian2 which determines the billboard's pixel offset. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian2} {@link Property} specifying the billboard's pixel offset. + * @type {Property} */ this.pixelOffset = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the billboard's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the billboard's visibility. + * @type {Property} */ this.show = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's billboard. - * If the DynamicObject does not have a billboard, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * @memberof DynamicBillboard - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the billboard data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The collection into which objects are being loaded. - * @param {String} [sourceUri] The originating url of the CZML being processed. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicBillboard.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection, sourceUri) { - var billboardData = packet.billboard; - if (!defined(billboardData)) { - return false; - } - - var billboardUpdated = false; - var billboard = dynamicObject.billboard; - billboardUpdated = !defined(billboard); - if (billboardUpdated) { - dynamicObject.billboard = billboard = new DynamicBillboard(); - } - - var interval = billboardData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(billboardData.color)) { - var color = billboard.color; - if (!defined(color)) { - billboard.color = color = new DynamicProperty(CzmlColor); - billboardUpdated = true; - } - color.processCzmlIntervals(billboardData.color, interval); - } - - if (defined(billboardData.eyeOffset)) { - var eyeOffset = billboard.eyeOffset; - if (!defined(eyeOffset)) { - billboard.eyeOffset = eyeOffset = new DynamicProperty(CzmlCartesian3); - billboardUpdated = true; - } - eyeOffset.processCzmlIntervals(billboardData.eyeOffset, interval); - } - - if (defined(billboardData.horizontalOrigin)) { - var horizontalOrigin = billboard.horizontalOrigin; - if (!defined(horizontalOrigin)) { - billboard.horizontalOrigin = horizontalOrigin = new DynamicProperty(CzmlHorizontalOrigin); - billboardUpdated = true; - } - horizontalOrigin.processCzmlIntervals(billboardData.horizontalOrigin, interval); - } - - if (defined(billboardData.image)) { - var image = billboard.image; - if (!defined(image)) { - billboard.image = image = new DynamicProperty(CzmlImage); - billboardUpdated = true; - } - image.processCzmlIntervals(billboardData.image, interval, sourceUri); - } - - if (defined(billboardData.pixelOffset)) { - var pixelOffset = billboard.pixelOffset; - if (!defined(pixelOffset)) { - billboard.pixelOffset = pixelOffset = new DynamicProperty(CzmlCartesian2); - billboardUpdated = true; - } - pixelOffset.processCzmlIntervals(billboardData.pixelOffset, interval); - } - - if (defined(billboardData.scale)) { - var scale = billboard.scale; - if (!defined(scale)) { - billboard.scale = scale = new DynamicProperty(CzmlNumber); - billboardUpdated = true; - } - scale.processCzmlIntervals(billboardData.scale, interval); - } - - if (defined(billboardData.rotation)) { - var rotation = billboard.rotation; - if (!defined(rotation)) { - billboard.rotation = rotation = new DynamicProperty(CzmlNumber); - billboardUpdated = true; - } - rotation.processCzmlIntervals(billboardData.rotation, interval); - } - - if (defined(billboardData.alignedAxis)) { - var alignedAxis = billboard.alignedAxis; - if (!defined(alignedAxis)) { - billboard.alignedAxis = alignedAxis = new DynamicProperty(CzmlCartesian3); - billboardUpdated = true; - } - alignedAxis.processCzmlIntervals(billboardData.alignedAxis, interval); - } - - if (defined(billboardData.show)) { - var show = billboard.show; - if (!defined(show)) { - billboard.show = show = new DynamicProperty(CzmlBoolean); - billboardUpdated = true; - } - show.processCzmlIntervals(billboardData.show, interval); - } - - if (defined(billboardData.verticalOrigin)) { - var verticalOrigin = billboard.verticalOrigin; - if (!defined(verticalOrigin)) { - billboard.verticalOrigin = verticalOrigin = new DynamicProperty(CzmlVerticalOrigin); - billboardUpdated = true; - } - verticalOrigin.processCzmlIntervals(billboardData.verticalOrigin, interval); - } - - return billboardUpdated; - }; - /** * Given two DynamicObjects, takes the billboard properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * @memberof DynamicBillboard * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicBillboard.mergeProperties = function(targetObject, objectToMerge) { var billboardToMerge = objectToMerge.billboard; @@ -271,13 +98,9 @@ define([ /** * Given a DynamicObject, undefines the billboard associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * @memberof DynamicBillboard * * @param {DynamicObject} dynamicObject The DynamicObject to remove the billboard from. - * - * @see CzmlDefaults */ DynamicBillboard.undefineProperties = function(dynamicObject) { dynamicObject.billboard = undefined; diff --git a/Source/DynamicScene/DynamicBillboardVisualizer.js b/Source/DynamicScene/DynamicBillboardVisualizer.js index 0a0f8db3b1ef..86cf13982b27 100644 --- a/Source/DynamicScene/DynamicBillboardVisualizer.js +++ b/Source/DynamicScene/DynamicBillboardVisualizer.js @@ -272,7 +272,7 @@ define([ return; } - position = positionProperty.getValueCartesian(time, position); + position = positionProperty.getValue(time, position); if (defined(position)) { billboard.setPosition(position); } diff --git a/Source/DynamicScene/DynamicClock.js b/Source/DynamicScene/DynamicClock.js index f394bdeb5bfe..af67ebd07b47 100644 --- a/Source/DynamicScene/DynamicClock.js +++ b/Source/DynamicScene/DynamicClock.js @@ -1,18 +1,14 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/Iso8601', '../Core/ClockRange', '../Core/ClockStep', - '../Core/defined', - '../Core/JulianDate' + '../Core/defined' ], function( - TimeInterval, Iso8601, ClockRange, ClockStep, - defined, - JulianDate) { + defined) { "use strict"; /** @@ -88,58 +84,6 @@ define([ return result; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's clock. - * @memberof DynamicClock - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the clock data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The collection into which objects are being loaded. - * @param {String} [sourceUri] The originating url of the CZML being processed. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicClock.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection, sourceUri) { - var clockUpdated = false; - var clockPacket = packet.clock; - if (defined(clockPacket)) { - if (dynamicObject.id === 'document') { - var clock = dynamicObject.clock; - if (!defined(clock)) { - clock = new DynamicClock(); - dynamicObject.clock = clock; - clockUpdated = true; - } - - if (defined(clockPacket.interval)) { - var interval = TimeInterval.fromIso8601(clockPacket.interval); - if (defined(interval)) { - clock.startTime = interval.start; - clock.stopTime = interval.stop; - } - } - if (defined(clockPacket.currentTime)) { - clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime); - } - if (defined(clockPacket.range)) { - clock.clockRange = ClockRange[clockPacket.range]; - } - if (defined(clockPacket.step)) { - clock.clockStep = ClockStep[clockPacket.step]; - } - if (defined(clockPacket.multiplier)) { - clock.multiplier = clockPacket.multiplier; - } - } - } - - return clockUpdated; - }; - /** * Given two DynamicObjects, takes the clock properties from the second * and assigns them to the first. @@ -147,8 +91,6 @@ define([ * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicClock.mergeProperties = function(targetObject, objectToMerge) { var clockToMerge = objectToMerge.clock; @@ -171,13 +113,9 @@ define([ /** * Given a DynamicObject, undefines the clock associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * @memberof DynamicClock * * @param {DynamicObject} dynamicObject The DynamicObject to remove the clock from. - * - * @see CzmlDefaults */ DynamicClock.undefineProperties = function(dynamicObject) { dynamicObject.clock = undefined; diff --git a/Source/DynamicScene/DynamicColorMaterial.js b/Source/DynamicScene/DynamicColorMaterial.js deleted file mode 100644 index c12f56315dd0..000000000000 --- a/Source/DynamicScene/DynamicColorMaterial.js +++ /dev/null @@ -1,81 +0,0 @@ -/*global define*/ -define([ - './DynamicProperty', - './CzmlColor', - '../Core/defined', - '../Scene/Material' - ], function( - DynamicProperty, - CzmlColor, - defined, - Material) { - "use strict"; - - /** - * A utility class for processing CZML color materials. - * @alias DynamicColorMaterial - * @constructor - */ - var DynamicColorMaterial = function() { - /** - * A DynamicProperty of type CzmlColor which determines the material's color. - * @type {DynamicProperty} - * @default undefined - */ - this.color = undefined; - }; - - /** - * Returns true if the provided CZML interval contains color material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML color material data, false otherwise. - */ - DynamicColorMaterial.isMaterial = function(czmlInterval) { - return defined(czmlInterval) && defined(czmlInterval.solidColor); - }; - - /** - * Returns true if the provided CZML interval contains color material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML color material data, false otherwise. - */ - DynamicColorMaterial.prototype.isMaterial = DynamicColorMaterial.isMaterial; - - /** - * Provided a CZML interval containing color material data, processes the - * interval into a new or existing instance of this class. - * - * @param {Object} czmlInterval The interval to process. - * @param {DynamicColorMaterial} [existingMaterial] The DynamicColorMaterial to modify. - */ - DynamicColorMaterial.prototype.processCzmlIntervals = function(czmlInterval) { - var materialData = czmlInterval.solidColor; - if (defined(materialData)) { - if (defined(materialData.color)) { - var color = this.color; - if (!defined(color)) { - this.color = color = new DynamicProperty(CzmlColor); - } - color.processCzmlIntervals(materialData.color); - } - } - }; - - /** - * Gets a Color Material that represents this dynamic material at the provided time. - * - * @param {JulianDate} time The desired time. - * @param {Context} context The context in which this material exists. - * @param {Material} [existingMaterial] An existing material to be modified. If the material is undefined or not a Color Material, a new instance is created. - * @returns The modified existingMaterial parameter or a new Color Material instance if existingMaterial was undefined or not a Color Material. - */ - DynamicColorMaterial.prototype.getValue = function(time, context, existingMaterial) { - if (!defined(existingMaterial) || (existingMaterial.type !== Material.ColorType)) { - existingMaterial = Material.fromType(context, Material.ColorType); - } - existingMaterial.uniforms.color = this.color.getValue(time, existingMaterial.uniforms.color); - return existingMaterial; - }; - - return DynamicColorMaterial; -}); diff --git a/Source/DynamicScene/DynamicCone.js b/Source/DynamicScene/DynamicCone.js index cc6dbdb71cff..d12bc7ca8d18 100644 --- a/Source/DynamicScene/DynamicCone.js +++ b/Source/DynamicScene/DynamicCone.js @@ -1,283 +1,92 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlNumber', - './CzmlColor', - './DynamicProperty', - './DynamicMaterialProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlNumber, - CzmlColor, - DynamicProperty, - DynamicMaterialProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic cone, typically used in conjunction with DynamicConeVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic cone. * * @alias DynamicCone * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicConeVisualizer - * @see VisualizerCollection - * @see ComplexConicSensor - * @see CzmlDefaults */ var DynamicCone = function() { /** - * A DynamicProperty of type CzmlNumber which determines the cone's minimum clock-angle. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the cone's minimum clock angle. + * @type {Property} */ this.minimumClockAngle = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the cone's maximum clock-angle. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the cone's maximum clock angle. + * @type {Property} */ this.maximumClockAngle = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the cone's inner half-angle. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the cone's inner half-angle. + * @type {Property} */ this.innerHalfAngle = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the cone's outer half-angle. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the cone's outer half-angle. + * @type {Property} */ this.outerHalfAngle = undefined; /** - * A DynamicMaterialProperty which determines the cone's cap material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the the cone's cap material. + * @type {MaterialProperty} */ this.capMaterial = undefined; /** - * A DynamicMaterialProperty which determines the cone's inner material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the the cone's inner material. + * @type {MaterialProperty} */ this.innerMaterial = undefined; /** - * A DynamicMaterialProperty which determines the cone's outer material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the the cone's outer material. + * @type {MaterialProperty} */ this.outerMaterial = undefined; /** - * A DynamicMaterialProperty which determines the cone's silhouette material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the the cone's silhouette material. + * @type {MaterialProperty} */ this.silhouetteMaterial = undefined; /** - * A DynamicProperty of type CzmlColor which determines the color of the line formed by the intersection of the cone and other central bodies. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the color of the line formed by the intersection of the cone and other central bodies. + * @type {Property} */ this.intersectionColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the approximate pixel width of the line formed by the intersection of the cone and other central bodies. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the width of the line formed by the intersection of the cone and other central bodies. + * @type {Property} */ this.intersectionWidth = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the cone's intersection visibility - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the visibility of the line formed by the intersection of the cone and other central bodies. + * @type {Property} */ this.showIntersection = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the cone's radius. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the radius of the cone's projection. + * @type {Property} */ this.radius = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the cone's visibility - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the visibility of the cone. + * @type {Property} */ this.show = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's cone. - * If the DynamicObject does not have a cone, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the cone data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicCone.processCzmlPacket = function(dynamicObject, packet) { - var coneData = packet.cone; - if (!defined(coneData)) { - return false; - } - - var coneUpdated = false; - var cone = dynamicObject.cone; - coneUpdated = !defined(cone); - if (coneUpdated) { - dynamicObject.cone = cone = new DynamicCone(); - } - - var interval = coneData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(coneData.show)) { - var show = cone.show; - if (!defined(show)) { - cone.show = show = new DynamicProperty(CzmlBoolean); - coneUpdated = true; - } - show.processCzmlIntervals(coneData.show, interval); - } - - if (defined(coneData.innerHalfAngle)) { - var innerHalfAngle = cone.innerHalfAngle; - if (!defined(innerHalfAngle)) { - cone.innerHalfAngle = innerHalfAngle = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - innerHalfAngle.processCzmlIntervals(coneData.innerHalfAngle, interval); - } - - if (defined(coneData.outerHalfAngle)) { - var outerHalfAngle = cone.outerHalfAngle; - if (!defined(outerHalfAngle)) { - cone.outerHalfAngle = outerHalfAngle = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - outerHalfAngle.processCzmlIntervals(coneData.outerHalfAngle, interval); - } - - if (defined(coneData.minimumClockAngle)) { - var minimumClockAngle = cone.minimumClockAngle; - if (!defined(minimumClockAngle)) { - cone.minimumClockAngle = minimumClockAngle = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - minimumClockAngle.processCzmlIntervals(coneData.minimumClockAngle, interval); - } - - if (defined(coneData.maximumClockAngle)) { - var maximumClockAngle = cone.maximumClockAngle; - if (!defined(maximumClockAngle)) { - cone.maximumClockAngle = maximumClockAngle = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - maximumClockAngle.processCzmlIntervals(coneData.maximumClockAngle, interval); - } - - if (defined(coneData.radius)) { - var radius = cone.radius; - if (!defined(radius)) { - cone.radius = radius = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - radius.processCzmlIntervals(coneData.radius, interval); - } - - if (defined(coneData.showIntersection)) { - var showIntersection = cone.showIntersection; - if (!defined(showIntersection)) { - cone.showIntersection = showIntersection = new DynamicProperty(CzmlBoolean); - coneUpdated = true; - } - showIntersection.processCzmlIntervals(coneData.showIntersection, interval); - } - - if (defined(coneData.intersectionColor)) { - var intersectionColor = cone.intersectionColor; - if (!defined(intersectionColor)) { - cone.intersectionColor = intersectionColor = new DynamicProperty(CzmlColor); - coneUpdated = true; - } - intersectionColor.processCzmlIntervals(coneData.intersectionColor, interval); - } - - if (defined(coneData.intersectionWidth)) { - var intersectionWidth = cone.intersectionWidth; - if (!defined(intersectionWidth)) { - cone.intersectionWidth = intersectionWidth = new DynamicProperty(CzmlNumber); - coneUpdated = true; - } - intersectionWidth.processCzmlIntervals(coneData.intersectionWidth, interval); - } - - if (defined(coneData.capMaterial)) { - var capMaterial = cone.capMaterial; - if (!defined(capMaterial)) { - cone.capMaterial = capMaterial = new DynamicMaterialProperty(); - coneUpdated = true; - } - capMaterial.processCzmlIntervals(coneData.capMaterial, interval); - } - - if (defined(coneData.innerMaterial)) { - var innerMaterial = cone.innerMaterial; - if (!defined(innerMaterial)) { - cone.innerMaterial = innerMaterial = new DynamicMaterialProperty(); - coneUpdated = true; - } - innerMaterial.processCzmlIntervals(coneData.innerMaterial, interval); - } - - if (defined(coneData.outerMaterial)) { - var outerMaterial = cone.outerMaterial; - if (!defined(outerMaterial)) { - cone.outerMaterial = outerMaterial = new DynamicMaterialProperty(); - coneUpdated = true; - } - outerMaterial.processCzmlIntervals(coneData.outerMaterial, interval); - } - - if (defined(coneData.silhouetteMaterial)) { - var silhouetteMaterial = cone.silhouetteMaterial; - if (!defined(silhouetteMaterial)) { - cone.silhouetteMaterial = silhouetteMaterial = new DynamicMaterialProperty(); - coneUpdated = true; - } - silhouetteMaterial.processCzmlIntervals(coneData.silhouetteMaterial, interval); - } - - return coneUpdated; - }; - /** * Given two DynamicObjects, takes the cone properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicCone.mergeProperties = function(targetObject, objectToMerge) { var coneToMerge = objectToMerge.cone; @@ -306,12 +115,8 @@ define([ /** * Given a DynamicObject, undefines the cone associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the cone from. - * - * @see CzmlDefaults */ DynamicCone.undefineProperties = function(dynamicObject) { dynamicObject.cone = undefined; diff --git a/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js b/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js index d19d3fd89c39..cd02d78f858c 100644 --- a/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js +++ b/Source/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js @@ -2,7 +2,6 @@ define([ '../Core/Cartesian3', '../Core/Color', - '../Core/defaultValue', '../Core/defined', '../Core/destroyObject', '../Core/DeveloperError', @@ -12,11 +11,11 @@ define([ '../Core/Matrix4', '../Core/Spherical', '../Scene/CustomSensorVolume', - '../Scene/Material' + '../Scene/Material', + './MaterialProperty' ], function( Cartesian3, Color, - defaultValue, defined, destroyObject, DeveloperError, @@ -26,7 +25,8 @@ define([ Matrix4, Spherical, CustomSensorVolume, - Material) { + Material, + MaterialProperty) { "use strict"; //CZML_TODO DynamicConeVisualizerUsingCustomSensor is a temporary workaround @@ -350,7 +350,7 @@ define([ } } - var position = positionProperty.getValueCartesian(time, cachedPosition); + var position = positionProperty.getValue(time, cachedPosition); var orientation = orientationProperty.getValue(time, cachedOrientation); if (defined(position) && @@ -362,10 +362,7 @@ define([ cone._visualizerOrientation = orientation.clone(cone._visualizerOrientation); } - var material = dynamicCone.outerMaterial; - if (defined(material)) { - cone.material = material.getValue(time, context, cone.material); - } + cone.material = MaterialProperty.getValue(time, context, dynamicCone.outerMaterial, cone.material); property = dynamicCone.intersectionColor; if (defined(property)) { diff --git a/Source/DynamicScene/DynamicDirectionsProperty.js b/Source/DynamicScene/DynamicDirectionsProperty.js index 5e40bc5b16b9..6ef7b2654e13 100644 --- a/Source/DynamicScene/DynamicDirectionsProperty.js +++ b/Source/DynamicScene/DynamicDirectionsProperty.js @@ -36,7 +36,7 @@ define([ } } - ValueHolder.prototype.getValueSpherical = function() { + ValueHolder.prototype.getValue = function() { var sphericals = this.spherical; if (!defined(sphericals)) { sphericals = []; @@ -49,51 +49,13 @@ define([ return sphericals; }; - ValueHolder.prototype.getValueCartesian = function() { - var cartesians = this.cartesian; - if (!defined(cartesians)) { - cartesians = []; - this.cartesian = cartesians; - var sphericals = this.spherical; - for ( var i = 0, len = sphericals.length; i < len; i++) { - cartesians.push(Cartesian3.fromSpherical(sphericals[i])); - } - } - return cartesians; - }; - /** - * A dynamic property which maintains an array of directions that can change over time. - * The directions can be represented as both Cartesian and Spherical coordinates. - * Rather than creating instances of this object directly, it's typically - * created and managed via loading CZML data into a DynamicObjectCollection. - * Instances of this type are exposed via DynamicObject and it's sub-objects - * and are responsible for interpreting and interpolating the data for visualization. - *

- * - * @alias DynamicDirectionsProperty - * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see ReferenceProperty - * @see DynamicMaterialProperty - * @see DynamicPositionProperty - * @see DynamicVertexPositionsProperty + * @private */ var DynamicDirectionsProperty = function() { this._propertyIntervals = new TimeIntervalCollection(); }; - /** - * Processes the provided CZML interval or intervals into this property. - * - * @memberof DynamicDirectionsProperty - * - * @param {Object} czmlIntervals The CZML data to process. - * @param {TimeInterval} [constrainedInterval] Constrains the processing so that any times outside of this interval are ignored. - * @param {DynamicObjectCollection} dynamicObjectCollection The DynamicObjectCollection to be used as a target for resolving links within this property. - */ DynamicDirectionsProperty.prototype.processCzmlIntervals = function(czmlIntervals, constrainedInterval, dynamicObjectCollection) { if (Array.isArray(czmlIntervals)) { for ( var i = 0, len = czmlIntervals.length; i < len; i++) { @@ -104,34 +66,12 @@ define([ } }; - /** - * Retrieves the values at the supplied time as Spherical coordinates. - * @memberof DynamicDirectionsProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @returns An array of spherical coordinates for the provided time. - */ - DynamicDirectionsProperty.prototype.getValueSpherical = function(time) { - var interval = this._propertyIntervals.findIntervalContainingDate(time); - if (!defined(interval)) { - return undefined; - } - return interval.data.getValueSpherical(); - }; - - /** - * Retrieves the values at the supplied time as unit cartesian coordinates. - * @memberof DynamicDirectionsProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @returns An array of unit cartesian coordinates for the provided time. - */ - DynamicDirectionsProperty.prototype.getValueCartesian = function(time) { + DynamicDirectionsProperty.prototype.getValue = function(time) { var interval = this._propertyIntervals.findIntervalContainingDate(time); if (!defined(interval)) { return undefined; } - return interval.data.getValueCartesian(); + return interval.data.getValue(); }; function addCzmlInterval(dynamicDirectionsProperty, czmlInterval, constrainedInterval, dynamicObjectCollection) { @@ -160,4 +100,4 @@ define([ } return DynamicDirectionsProperty; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/DynamicEllipse.js b/Source/DynamicScene/DynamicEllipse.js index d19111905bdd..759c7050970a 100644 --- a/Source/DynamicScene/DynamicEllipse.js +++ b/Source/DynamicScene/DynamicEllipse.js @@ -1,56 +1,39 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', '../Core/defined', '../Core/Cartesian3', '../Core/Ellipsoid', - '../Core/Shapes', - './CzmlNumber', - './DynamicProperty' + '../Core/Shapes' ], function ( - TimeInterval, defaultValue, defined, Cartesian3, Ellipsoid, - Shapes, - CzmlNumber, - DynamicProperty) { + Shapes) { "use strict"; /** - * Represents a time-dynamic ellipse, typically used in conjunction with DynamicEllipseVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic ellipse. * * @alias DynamicEllipse * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicEllipseVisualizer - * @see VisualizerCollection - * @see CzmlDefaults */ var DynamicEllipse = function() { /** - * A DynamicProperty of type CzmlNumber which determines the ellipse's semiMajorAxis. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the ellipse's semi-major-axis. + * @type {Property} */ this.semiMajorAxis = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the ellipse's semiMinorAxis. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the ellipse's semi-minor-axis. + * @type {Property} */ this.semiMinorAxis = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the bearing of the ellipse. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the ellipse's bearing. + * @type {Property} */ this.bearing = undefined; @@ -61,81 +44,12 @@ define([ this._cachedVertexPositions = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's ellipse. - * If the DynamicObject does not have a ellipse, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the ellipse data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObject} dynamicObjectCollection The DynamicObjectCollection to which the DynamicObject belongs. - * - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicEllipse.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection) { - var ellipseData = packet.ellipse; - if (!defined(ellipseData)) { - return false; - } - - var ellipseUpdated = false; - var ellipse = dynamicObject.ellipse; - ellipseUpdated = !defined(ellipse); - if (ellipseUpdated) { - dynamicObject.ellipse = ellipse = new DynamicEllipse(); - } - - var interval = ellipseData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(ellipseData.bearing)) { - var bearing = ellipse.bearing; - if (!defined(bearing)) { - ellipse.bearing = bearing = new DynamicProperty(CzmlNumber); - ellipseUpdated = true; - } - bearing.processCzmlIntervals(ellipseData.bearing, interval); - } - - if (defined(ellipseData.semiMajorAxis)) { - var semiMajorAxis = ellipse.semiMajorAxis; - if (!defined(semiMajorAxis)) { - ellipse.semiMajorAxis = semiMajorAxis = new DynamicProperty(CzmlNumber); - ellipseUpdated = true; - } - semiMajorAxis.processCzmlIntervals(ellipseData.semiMajorAxis, interval); - } - - if (defined(ellipseData.semiMinorAxis)) { - var semiMinorAxis = ellipse.semiMinorAxis; - if (!defined(semiMinorAxis)) { - ellipse.semiMinorAxis = semiMinorAxis = new DynamicProperty(CzmlNumber); - ellipseUpdated = true; - } - semiMinorAxis.processCzmlIntervals(ellipseData.semiMinorAxis, interval); - } - - return ellipseUpdated; - }; - /** * Given two DynamicObjects, takes the ellipse properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicEllipse.mergeProperties = function(targetObject, objectToMerge) { var ellipseToMerge = objectToMerge.ellipse; @@ -154,12 +68,8 @@ define([ /** * Given a DynamicObject, undefines the ellipse associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the ellipse from. - * - * @see CzmlDefaults */ DynamicEllipse.undefineProperties = function(dynamicObject) { dynamicObject.ellipse = undefined; diff --git a/Source/DynamicScene/DynamicEllipsoid.js b/Source/DynamicScene/DynamicEllipsoid.js index c037f645f358..70ae052898d0 100644 --- a/Source/DynamicScene/DynamicEllipsoid.js +++ b/Source/DynamicScene/DynamicEllipsoid.js @@ -1,133 +1,42 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlCartesian3', - './DynamicProperty', - './DynamicMaterialProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlCartesian3, - DynamicProperty, - DynamicMaterialProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic ellipsoid, typically used in conjunction with DynamicEllipsoidVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic ellipsoid. * * @alias DynamicEllipsoid * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicEllipsoidVisualizer - * @see VisualizerCollection - * @see CustomSensor - * @see CzmlDefaults */ var DynamicEllipsoid = function() { /** - * A DynamicProperty of type CzmlBoolean which determines the ellipsoid's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the visibility of the ellipsoid. + * @type {Property} */ this.show = undefined; /** - * A DynamicProperty of type CzmlCartesian3 which determines the ellipsoid's radii. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian3} {@link Property} specifying the radii of the ellipsoid. + * @type {Property} */ this.radii = undefined; /** - * A DynamicMaterialProperty which determines the material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the appearance of the ellipsoid. + * @type {MaterialProperty} */ this.material = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's ellipsoid. - * If the DynamicObject does not have a ellipsoid, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the ellipsoid data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObject} dynamicObjectCollection The DynamicObjectCollection to which the DynamicObject belongs. - * - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicEllipsoid.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection) { - var ellipsoidData = packet.ellipsoid; - if (!defined(ellipsoidData)) { - return false; - } - - var ellipsoidUpdated = false; - var ellipsoid = dynamicObject.ellipsoid; - ellipsoidUpdated = !defined(ellipsoid); - if (ellipsoidUpdated) { - dynamicObject.ellipsoid = ellipsoid = new DynamicEllipsoid(); - } - - var interval = ellipsoidData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(ellipsoidData.show)) { - var show = ellipsoid.show; - if (!defined(show)) { - ellipsoid.show = show = new DynamicProperty(CzmlBoolean); - ellipsoidUpdated = true; - } - show.processCzmlIntervals(ellipsoidData.show, interval); - } - - if (defined(ellipsoidData.radii)) { - var radii = ellipsoid.radii; - if (!defined(radii)) { - ellipsoid.radii = radii = new DynamicProperty(CzmlCartesian3); - ellipsoidUpdated = true; - } - radii.processCzmlIntervals(ellipsoidData.radii, interval); - } - - if (defined(ellipsoidData.material)) { - var material = ellipsoid.material; - if (!defined(material)) { - ellipsoid.material = material = new DynamicMaterialProperty(); - ellipsoidUpdated = true; - } - material.processCzmlIntervals(ellipsoidData.material, interval); - } - - return ellipsoidUpdated; - }; - /** * Given two DynamicObjects, takes the ellipsoid properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicEllipsoid.mergeProperties = function(targetObject, objectToMerge) { var ellipsoidToMerge = objectToMerge.ellipsoid; @@ -146,12 +55,8 @@ define([ /** * Given a DynamicObject, undefines the ellipsoid associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the ellipsoid from. - * - * @see CzmlDefaults */ DynamicEllipsoid.undefineProperties = function(dynamicObject) { dynamicObject.ellipsoid = undefined; diff --git a/Source/DynamicScene/DynamicEllipsoidVisualizer.js b/Source/DynamicScene/DynamicEllipsoidVisualizer.js index ff855a70a8ca..2f09a250ddad 100644 --- a/Source/DynamicScene/DynamicEllipsoidVisualizer.js +++ b/Source/DynamicScene/DynamicEllipsoidVisualizer.js @@ -7,7 +7,8 @@ define([ '../Core/Matrix3', '../Core/Matrix4', '../Scene/EllipsoidPrimitive', - '../Scene/Material' + '../Scene/Material', + './MaterialProperty' ], function( defaultValue, defined, @@ -16,7 +17,8 @@ define([ Matrix3, Matrix4, EllipsoidPrimitive, - Material) { + Material, + MaterialProperty) { "use strict"; var matrix3Scratch = new Matrix3(); @@ -240,7 +242,7 @@ define([ ellipsoid.radii = radiiProperty.getValue(time, ellipsoid.radii); - position = defaultValue(positionProperty.getValueCartesian(time, position), ellipsoid._visualizerPosition); + position = defaultValue(positionProperty.getValue(time, position), ellipsoid._visualizerPosition); orientation = defaultValue(orientationProperty.getValue(time, orientation), ellipsoid._visualizerOrientation); if (defined(position) && @@ -252,10 +254,7 @@ define([ ellipsoid._visualizerOrientation = orientation.clone(ellipsoid._visualizerOrientation); } - var material = dynamicEllipsoid.material; - if (defined(material)) { - ellipsoid.material = material.getValue(time, context, ellipsoid.material); - } + ellipsoid.material = MaterialProperty.getValue(time, context, dynamicEllipsoid.material, ellipsoid.material); } DynamicEllipsoidVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, dynamicObjects) { diff --git a/Source/DynamicScene/DynamicGridMaterial.js b/Source/DynamicScene/DynamicGridMaterial.js deleted file mode 100644 index 10977d30f42c..000000000000 --- a/Source/DynamicScene/DynamicGridMaterial.js +++ /dev/null @@ -1,210 +0,0 @@ -/*global define*/ -define([ - './DynamicProperty', - './CzmlColor', - './CzmlNumber', - '../Core/defined', - '../Scene/Material' - ], function( - DynamicProperty, - CzmlColor, - CzmlNumber, - defined, - Material) { - "use strict"; - - /** - * A utility class for processing CZML grid materials. - * @alias DynamicGridMaterial - * @constructor - */ - var DynamicGridMaterial = function() { - /** - * A DynamicProperty of type CzmlColor which determines the grid's color. - * @type {DynamicProperty} - * @default undefined - */ - this.color = undefined; - - /** - * A DynamicProperty of type CzmlNumber which determines the grid cells alpha value, when combined with the color alpha. - * @type {DynamicProperty} - * @default undefined - */ - this.cellAlpha = undefined; - - /** - * A DynamicProperty of type CzmlNumber which determines the number of horizontal rows. - * @type {DynamicProperty} - * @default undefined - */ - this.rowCount = undefined; - - /** - * A DynamicProperty of type CzmlNumber which determines the number of vertical columns. - * @type {DynamicProperty} - * @default undefined - */ - this.columnCount = undefined; - - /** - * A DynamicProperty of type CzmlNumber which determines the width of each horizontal line, in pixels. - * @type {DynamicProperty} - * @default undefined - */ - this.rowThickness = undefined; - - /** - * A DynamicProperty of type CzmlNumber which determines the width of each vertical line, in pixels. - * @type {DynamicProperty} - * @default undefined - */ - this.columnThickness = undefined; - }; - - /** - * Returns true if the provided CZML interval contains grid material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML grid material data, false otherwise. - */ - DynamicGridMaterial.isMaterial = function(czmlInterval) { - return defined(czmlInterval.grid); - }; - - /** - * Returns true if the provided CZML interval contains grid material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML grid material data, false otherwise. - */ - DynamicGridMaterial.prototype.isMaterial = DynamicGridMaterial.isMaterial; - - /** - * Provided a CZML interval containing grid material data, processes the - * interval into a new or existing instance of this class. - * - * @param {Object} czmlInterval The interval to process. - * @param {String} [sourceUri] The originating url of the CZML being processed. - * @returns The modified existingMaterial parameter or a new DynamicGridMaterial instance if existingMaterial was undefined or not a DynamicGridMaterial. - */ - DynamicGridMaterial.prototype.processCzmlIntervals = function(czmlInterval, sourceUri) { - var materialData = czmlInterval.grid; - if (!defined(materialData)) { - return; - } - - if (defined(materialData.color)) { - var color = this.color; - if (!defined(color)) { - this.color = color = new DynamicProperty(CzmlColor); - } - color.processCzmlIntervals(materialData.color, undefined, sourceUri); - } - - if (defined(materialData.cellAlpha)) { - var cellAlpha = this.cellAlpha; - if (!defined(cellAlpha)) { - this.cellAlpha = cellAlpha = new DynamicProperty(CzmlNumber); - } - cellAlpha.processCzmlIntervals(materialData.cellAlpha, undefined, sourceUri); - } - - if (defined(materialData.rowCount)) { - var rowCount = this.rowCount; - if (!defined(rowCount)) { - this.rowCount = rowCount = new DynamicProperty(CzmlNumber); - } - rowCount.processCzmlIntervals(materialData.rowCount, undefined, sourceUri); - } - - if (defined(materialData.columnCount)) { - var columnCount = this.columnCount; - if (!defined(columnCount)) { - this.columnCount = columnCount = new DynamicProperty(CzmlNumber); - } - columnCount.processCzmlIntervals(materialData.columnCount, undefined, sourceUri); - } - - if (defined(materialData.rowThickness)) { - var rowThickness = this.rowThickness; - if (!defined(rowThickness)) { - this.rowThickness = rowThickness = new DynamicProperty(CzmlNumber); - } - rowThickness.processCzmlIntervals(materialData.rowThickness, undefined, sourceUri); - } - - if (defined(materialData.columnThickness)) { - var columnThickness = this.columnThickness; - if (!defined(columnThickness)) { - this.columnThickness = columnThickness = new DynamicProperty(CzmlNumber); - } - columnThickness.processCzmlIntervals(materialData.columnThickness, undefined, sourceUri); - } - }; - - /** - * Gets an Grid Material that represents this dynamic material at the provided time. - * - * @param {JulianDate} time The desired time. - * @param {Context} context The context in which this material exists. - * @param {Material} [existingMaterial] An existing material to be modified. If the material is undefined or not an Grid Material, a new instance is created. - * @returns The modified existingMaterial parameter or a new Grid Material instance if existingMaterial was undefined or not a Grid Material. - */ - DynamicGridMaterial.prototype.getValue = function(time, context, existingMaterial) { - if (!defined(existingMaterial) || (existingMaterial.type !== Material.GridType)) { - existingMaterial = Material.fromType(context, Material.GridType); - } - - var property = this.color; - if (defined(property)) { - property.getValue(time, existingMaterial.uniforms.color); - } - - property = this.cellAlpha; - if (defined(property)) { - var cellAlpha = property.getValue(time); - if (defined(cellAlpha)) { - existingMaterial.uniforms.cellAlpha = cellAlpha; - } - } - - var lineCount = existingMaterial.uniforms.lineCount; - - property = this.rowCount; - if (defined(property)) { - var rowCount = property.getValue(time); - if (defined(rowCount)) { - lineCount.x = rowCount; - } - } - - property = this.columnCount; - if (defined(property)) { - var columnCount = property.getValue(time); - if (defined(columnCount)) { - lineCount.y = columnCount; - } - } - - var lineThickness = existingMaterial.uniforms.lineThickness; - - property = this.rowThickness; - if (defined(property)) { - var rowThickness = property.getValue(time); - if (defined(rowThickness)) { - lineThickness.x = rowThickness; - } - } - - property = this.columnThickness; - if (defined(property)) { - var columnThickness = property.getValue(time); - if (defined(columnThickness)) { - lineThickness.y = columnThickness; - } - } - - return existingMaterial; - }; - - return DynamicGridMaterial; -}); diff --git a/Source/DynamicScene/DynamicImageMaterial.js b/Source/DynamicScene/DynamicImageMaterial.js deleted file mode 100644 index 568bc9735371..000000000000 --- a/Source/DynamicScene/DynamicImageMaterial.js +++ /dev/null @@ -1,141 +0,0 @@ -/*global define*/ -define([ - './DynamicProperty', - './CzmlImage', - './CzmlNumber', - '../Core/defined', - '../Scene/Material' - ], function( - DynamicProperty, - CzmlImage, - CzmlNumber, - defined, - Material) { - "use strict"; - - /** - * A utility class for processing CZML image materials. - * @alias DynamicImageMaterial - * @constructor - */ - var DynamicImageMaterial = function() { - /** - * A DynamicProperty of type CzmlNumber which determines the material's image. - * @type {DynamicProperty} - * @default undefined - */ - this.image = undefined; - /** - * A DynamicProperty of type CzmlNumber which determines the material's vertical repeat. - * @type {DynamicProperty} - * @default undefined - */ - this.verticalRepeat = undefined; - /** - * A DynamicProperty of type CzmlNumber which determines the material's horizontal repeat. - * - * @type {DynamicProperty} - * @default undefined - */ - this.horizontalRepeat = undefined; - }; - - /** - * Returns true if the provided CZML interval contains image material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML image material data, false otherwise. - */ - DynamicImageMaterial.isMaterial = function(czmlInterval) { - return defined(czmlInterval.image); - }; - - /** - * Returns true if the provided CZML interval contains image material data. - * @param czmlInterval The CZML interval to check. - * @returns {Boolean} true if the interval contains CZML image material data, false otherwise. - */ - DynamicImageMaterial.prototype.isMaterial = DynamicImageMaterial.isMaterial; - - /** - * Provided a CZML interval containing image material data, processes the - * interval into a new or existing instance of this class. - * - * @param {Object} czmlInterval The interval to process. - * @param {String} [sourceUri] The originating url of the CZML being processed. - * @returns The modified existingMaterial parameter or a new DynamicImageMaterial instance if existingMaterial was undefined or not a DynamicImageMaterial. - */ - DynamicImageMaterial.prototype.processCzmlIntervals = function(czmlInterval, sourceUri) { - var materialData = czmlInterval.image; - if (!defined(materialData)) { - return; - } - - if (defined(materialData.image)) { - var image = this.image; - if (!defined(image)) { - this.image = image = new DynamicProperty(CzmlImage); - } - image.processCzmlIntervals(materialData.image, undefined, sourceUri); - } - - if (defined(materialData.verticalRepeat)) { - var verticalRepeat = this.verticalRepeat; - if (!defined(verticalRepeat)) { - this.verticalRepeat = verticalRepeat = new DynamicProperty(CzmlNumber); - } - verticalRepeat.processCzmlIntervals(materialData.verticalRepeat); - } - - if (defined(materialData.horizontalRepeat)) { - var horizontalRepeat = this.horizontalRepeat; - if (!defined(horizontalRepeat)) { - this.horizontalRepeat = horizontalRepeat = new DynamicProperty(CzmlNumber); - } - horizontalRepeat.processCzmlIntervals(materialData.horizontalRepeat); - } - }; - - /** - * Gets an Image Material that represents this dynamic material at the provided time. - * - * @param {JulianDate} time The desired time. - * @param {Context} context The context in which this material exists. - * @param {Material} [existingMaterial] An existing material to be modified. If the material is undefined or not an Image Material, a new instance is created. - * @returns The modified existingMaterial parameter or a new Image Material instance if existingMaterial was undefined or not a Image Material. - */ - DynamicImageMaterial.prototype.getValue = function(time, context, existingMaterial) { - if (!defined(existingMaterial) || (existingMaterial.type !== Material.ImageType)) { - existingMaterial = Material.fromType(context, Material.ImageType); - } - - var xRepeat; - var property = this.verticalRepeat; - if (defined(property)) { - xRepeat = property.getValue(time); - if (defined(xRepeat)) { - existingMaterial.uniforms.repeat.x = xRepeat; - } - } - - var yRepeat; - property = this.horizontalRepeat; - if (defined(property)) { - yRepeat = property.getValue(time); - if (defined(yRepeat)) { - existingMaterial.uniforms.repeat.y = yRepeat; - } - } - - property = this.image; - if (defined(property)) { - var url = this.image.getValue(time); - if (defined(url) && existingMaterial.currentUrl !== url) { - existingMaterial.currentUrl = url; - existingMaterial.uniforms.image = url; - } - } - return existingMaterial; - }; - - return DynamicImageMaterial; -}); diff --git a/Source/DynamicScene/DynamicLabel.js b/Source/DynamicScene/DynamicLabel.js index 2e70b3c2bdd9..2c503eddc3a1 100644 --- a/Source/DynamicScene/DynamicLabel.js +++ b/Source/DynamicScene/DynamicLabel.js @@ -1,278 +1,86 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlCartesian2', - './CzmlCartesian3', - './CzmlNumber', - './CzmlString', - './CzmlHorizontalOrigin', - './CzmlVerticalOrigin', - './CzmlLabelStyle', - './CzmlColor', - './DynamicProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlCartesian2, - CzmlCartesian3, - CzmlNumber, - CzmlString, - CzmlHorizontalOrigin, - CzmlVerticalOrigin, - CzmlLabelStyle, - CzmlColor, - DynamicProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic label, typically used in conjunction with DynamicLabelVisualizer and - * DynamicObjectCollection to visualize CZML. - * + * An optionally time-dynamic label. * @alias DynamicLabel * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicLabelVisualizer - * @see VisualizerCollection - * @see Label - * @see LabelCollection - * @see CzmlDefaults */ var DynamicLabel = function() { /** - * A DynamicProperty of type CzmlString which determines the label's text. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the string {@link Property} specifying the the label's text. + * @type {Property} */ this.text = undefined; /** - * A DynamicProperty of type CzmlString which determines the label's font. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the string {@link Property} specifying the the label's font. + * @type {Property} */ this.font = undefined; /** - * A DynamicProperty of type CzmlLabelStyle which determines the label's style. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link LabelStyle} {@link Property} specifying the the label's style. + * @type {Property} */ this.style = undefined; /** - * A DynamicProperty of type CzmlColor which determines the label's fill color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the label's fill color. + * @type {Property} */ this.fillColor = undefined; /** - * A DynamicProperty of type CzmlColor which determines the label's outline color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the label's outline color. + * @type {Property} */ this.outlineColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the label's outline width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the label outline's width. + * @type {Property} */ this.outlineWidth = undefined; /** - * A DynamicProperty of type CzmlHorizontalOrigin which determines the label's horizontal origin. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link HorizontalOrigin} {@link Property} specifying the label's horizontal origin. + * @type {Property} */ this.horizontalOrigin = undefined; /** - * A DynamicProperty of type CzmlVerticalOrigin which determines the label's vertical origin. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link VerticalOrigin} {@link Property} specifying the label's vertical origin. + * @type {Property} */ this.verticalOrigin = undefined; /** - * A DynamicProperty of type CzmlCartesian3 which determines the label's eye offset. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian3} {@link Property} specifying the label's eye offset. + * @type {Property} */ this.eyeOffset = undefined; /** - * A DynamicProperty of type CzmlCartesian2 which determines the label's pixel offset. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian2} {@link Property} specifying the label's pixel offset. + * @type {Property} */ this.pixelOffset = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the label's scale. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the label's scale. + * @type {Property} */ this.scale = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the label's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the label's visibility. + * @type {Property} */ this.show = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's label. - * If the DynamicObject does not have a label, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the label data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicLabel.processCzmlPacket = function(dynamicObject, packet) { - var labelData = packet.label; - if (!defined(labelData)) { - return false; - } - - var labelUpdated = false; - var label = dynamicObject.label; - labelUpdated = !defined(label); - if (labelUpdated) { - dynamicObject.label = label = new DynamicLabel(); - } - - var interval = labelData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(labelData.fillColor)) { - var fillColor = label.fillColor; - if (!defined(fillColor)) { - label.fillColor = fillColor = new DynamicProperty(CzmlColor); - labelUpdated = true; - } - fillColor.processCzmlIntervals(labelData.fillColor, interval); - } - - if (defined(labelData.outlineColor)) { - var outlineColor = label.outlineColor; - if (!defined(outlineColor)) { - label.outlineColor = outlineColor = new DynamicProperty(CzmlColor); - labelUpdated = true; - } - outlineColor.processCzmlIntervals(labelData.outlineColor, interval); - } - - if (defined(labelData.outlineWidth)) { - var outlineWidth = label.outlineWidth; - if (!defined(outlineWidth)) { - label.outlineWidth = outlineWidth = new DynamicProperty(CzmlNumber); - labelUpdated = true; - } - outlineWidth.processCzmlIntervals(labelData.outlineWidth, interval); - } - - if (defined(labelData.eyeOffset)) { - var eyeOffset = label.eyeOffset; - if (!defined(eyeOffset)) { - label.eyeOffset = eyeOffset = new DynamicProperty(CzmlCartesian3); - labelUpdated = true; - } - eyeOffset.processCzmlIntervals(labelData.eyeOffset, interval); - } - - if (defined(labelData.horizontalOrigin)) { - var horizontalOrigin = label.horizontalOrigin; - if (!defined(horizontalOrigin)) { - label.horizontalOrigin = horizontalOrigin = new DynamicProperty(CzmlHorizontalOrigin); - labelUpdated = true; - } - horizontalOrigin.processCzmlIntervals(labelData.horizontalOrigin, interval); - } - - if (defined(labelData.text)) { - var text = label.text; - if (!defined(text)) { - label.text = text = new DynamicProperty(CzmlString); - labelUpdated = true; - } - text.processCzmlIntervals(labelData.text, interval); - } - - if (defined(labelData.pixelOffset)) { - var pixelOffset = label.pixelOffset; - if (!defined(pixelOffset)) { - label.pixelOffset = pixelOffset = new DynamicProperty(CzmlCartesian2); - labelUpdated = true; - } - pixelOffset.processCzmlIntervals(labelData.pixelOffset, interval); - } - - if (defined(labelData.scale)) { - var scale = label.scale; - if (!defined(scale)) { - label.scale = scale = new DynamicProperty(CzmlNumber); - labelUpdated = true; - } - scale.processCzmlIntervals(labelData.scale, interval); - } - - if (defined(labelData.show)) { - var show = label.show; - if (!defined(show)) { - label.show = show = new DynamicProperty(CzmlBoolean); - labelUpdated = true; - } - show.processCzmlIntervals(labelData.show, interval); - } - - if (defined(labelData.verticalOrigin)) { - var verticalOrigin = label.verticalOrigin; - if (!defined(verticalOrigin)) { - label.verticalOrigin = verticalOrigin = new DynamicProperty(CzmlVerticalOrigin); - labelUpdated = true; - } - verticalOrigin.processCzmlIntervals(labelData.verticalOrigin, interval); - } - - if (defined(labelData.font)) { - var font = label.font; - if (!defined(font)) { - label.font = font = new DynamicProperty(CzmlString); - labelUpdated = true; - } - font.processCzmlIntervals(labelData.font, interval); - } - - if (defined(labelData.style)) { - var style = label.style; - if (!defined(style)) { - label.style = style = new DynamicProperty(CzmlLabelStyle); - labelUpdated = true; - } - style.processCzmlIntervals(labelData.style, interval); - } - return labelUpdated; - }; - /** * Given two DynamicObjects, takes the label properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicLabel.mergeProperties = function(targetObject, objectToMerge) { var labelToMerge = objectToMerge.label; @@ -300,12 +108,8 @@ define([ /** * Given a DynamicObject, undefines the label associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the label from. - * - * @see CzmlDefaults */ DynamicLabel.undefineProperties = function(dynamicObject) { dynamicObject.label = undefined; diff --git a/Source/DynamicScene/DynamicLabelVisualizer.js b/Source/DynamicScene/DynamicLabelVisualizer.js index b656d4a4fd37..8b322169c92e 100644 --- a/Source/DynamicScene/DynamicLabelVisualizer.js +++ b/Source/DynamicScene/DynamicLabelVisualizer.js @@ -247,7 +247,7 @@ define([ label.setText(text); } - position = positionProperty.getValueCartesian(time, position); + position = positionProperty.getValue(time, position); if (defined(position)) { label.setPosition(position); } @@ -349,4 +349,4 @@ define([ }; return DynamicLabelVisualizer; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/DynamicMaterialProperty.js b/Source/DynamicScene/DynamicMaterialProperty.js deleted file mode 100644 index 3b16d92cf309..000000000000 --- a/Source/DynamicScene/DynamicMaterialProperty.js +++ /dev/null @@ -1,127 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/TimeInterval', - '../Core/TimeIntervalCollection', - '../Core/Iso8601', - './DynamicColorMaterial', - './DynamicImageMaterial', - './DynamicGridMaterial' - ], function( - defined, - TimeInterval, - TimeIntervalCollection, - Iso8601, - DynamicColorMaterial, - DynamicImageMaterial, - DynamicGridMaterial) { - "use strict"; - - var potentialMaterials = [DynamicColorMaterial, DynamicImageMaterial, DynamicGridMaterial]; - - /** - * A dynamic property which stores data for multiple types of materials - * associated with the same property over time. Rather than creating instances - * of this object directly, it's typically created and managed via loading CZML - * data into a DynamicObjectCollection. - * - * @alias DynamicMaterialProperty - * @internalconstructor - * - * @see DynamicObject - * @see DynamicProperty - * @see ReferenceProperty - * @see DynamicPositionProperty - * @see DynamicDirectionsProperty - * @see DynamicVertexPositionsProperty - */ - var DynamicMaterialProperty = function() { - this._intervals = new TimeIntervalCollection(); - }; - - - /** - * Processes the provided CZML interval or intervals into this property. - * @memberof DynamicMaterialProperty - * - * @param {Object} czmlIntervals The CZML data to process. - * @param {TimeInterval} [constrainedInterval] Constrains the processing so that any times outside of this interval are ignored. - * @param {String} [sourceUri] The originating url of the CZML being processed. - */ - DynamicMaterialProperty.prototype.processCzmlIntervals = function(czmlIntervals, constrainedInterval, sourceUri) { - if (Array.isArray(czmlIntervals)) { - for ( var i = 0, len = czmlIntervals.length; i < len; i++) { - addCzmlInterval(this, czmlIntervals[i], constrainedInterval, sourceUri); - } - } else { - addCzmlInterval(this, czmlIntervals, constrainedInterval, sourceUri); - } - }; - - /** - * Returns the value of the property at the specified time. - * @memberof DynamicMaterialProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @param {Context} [context] The context in which the material exists. - * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. - * @returns The modified result parameter or a new instance if the result parameter was not supplied. - */ - DynamicMaterialProperty.prototype.getValue = function(time, context, existingMaterial) { - var value = this._intervals.findIntervalContainingDate(time); - var material = defined(value) ? value.data : undefined; - if (defined(material)) { - return material.getValue(time, context, existingMaterial); - } - return existingMaterial; - }; - - function addCzmlInterval(dynamicMaterialProperty, czmlInterval, constrainedInterval, sourceUri) { - var iso8601Interval = czmlInterval.interval; - if (!defined(iso8601Interval)) { - iso8601Interval = Iso8601.MAXIMUM_INTERVAL.clone(); - } else { - iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - } - - if (defined(constrainedInterval)) { - iso8601Interval = iso8601Interval.intersect(constrainedInterval); - } - - //See if we already have data at that interval. - var thisIntervals = dynamicMaterialProperty._intervals; - var existingInterval = thisIntervals.findInterval(iso8601Interval.start, iso8601Interval.stop); - var foundMaterial = false; - var existingMaterial; - - if (defined(existingInterval)) { - //We have an interval, but we need to make sure the - //new data is the same type of material as the old data. - existingMaterial = existingInterval.data; - foundMaterial = existingMaterial.isMaterial(czmlInterval); - } else { - //If not, create it. - existingInterval = iso8601Interval; - thisIntervals.addInterval(existingInterval); - } - - //If the new data was a different type, look for a handler for this type. - if (foundMaterial === false) { - for ( var i = 0, len = potentialMaterials.length; i < len; i++) { - var PotentialMaterial = potentialMaterials[i]; - foundMaterial = PotentialMaterial.isMaterial(czmlInterval); - if (foundMaterial) { - existingInterval.data = existingMaterial = new PotentialMaterial(); - break; - } - } - } - - //We could handle the data, prcess it. - if (foundMaterial) { - existingMaterial.processCzmlIntervals(czmlInterval, sourceUri); - } - } - - return DynamicMaterialProperty; -}); \ No newline at end of file diff --git a/Source/DynamicScene/DynamicObject.js b/Source/DynamicScene/DynamicObject.js index 05b91fb6169c..c26a529a8794 100644 --- a/Source/DynamicScene/DynamicObject.js +++ b/Source/DynamicScene/DynamicObject.js @@ -5,28 +5,18 @@ define([ '../Core/defined', '../Core/DeveloperError', '../Core/JulianDate', - '../Core/TimeInterval', - './DynamicProperty', - './DynamicPositionProperty', - './DynamicVertexPositionsProperty', - './CzmlUnitQuaternion', - './CzmlCartesian3' + '../Core/TimeInterval' ], function( createGuid, defaultValue, defined, DeveloperError, JulianDate, - TimeInterval, - DynamicProperty, - DynamicPositionProperty, - DynamicVertexPositionsProperty, - CzmlUnitQuaternion, - CzmlCartesian3) { + TimeInterval) { "use strict"; /** - * DynamicObject instances are the primary data store for processed CZML data. + * DynamicObject instances are the primary data store for processed data. * They are used primarily by the visualizers to create and maintain graphic * primitives that represent the DynamicObject's properties at a specific time. * @alias DynamicObject @@ -34,18 +24,8 @@ define([ * * @param {Object} [id] A unique identifier for this object. If no id is provided, a GUID is generated. * - * @see DynamicProperty - * @see DynamicPositionProperty - * @see DynamicVertexiPositionsProperty + * @see Property * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * @see DynamicBillboard - * @see DynamicCone - * @see DynamicLabel - * @see DynamicPoint - * @see DynamicPolygon - * @see DynamicPolyline - * @see DynamicPyramid */ var DynamicObject = function(id) { this._cachedAvailabilityDate = undefined; @@ -60,11 +40,6 @@ define([ */ this.id = id; - //Add standard CZML properties. Even though they won't all be used - //for each object, having the superset explicitly listed here will allow the - //compiler to optimize this class. It also allows us to document them. - //Any changes to this list should coincide with changes to CzmlDefaults.updaters - /** * The availability TimeInterval, if any, associated with this object. * If availability is undefined, it is assumed that this object's @@ -78,14 +53,14 @@ define([ /** * Gets or sets the position. - * @type {DynamicPositionProperty} + * @type {PositionProperty} * @default undefined */ this.position = undefined; /** * Gets or sets the orientation. - * @type {DynamicProperty} + * @type {Property} * @default undefined */ this.orientation = undefined; @@ -162,7 +137,7 @@ define([ /** * Gets or sets the vertex positions. - * @type {DynamicVertexPositionsProperty} + * @type {Property} * @default undefined */ this.vertexPositions = undefined; @@ -227,156 +202,13 @@ define([ } }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's position - * property. This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the position data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if the property was newly created while processing the packet, false otherwise. - * - * @see DynamicPositionProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicObject.processCzmlPacketPosition = function(dynamicObject, packet) { - var positionData = packet.position; - if (!defined(positionData)) { - return false; - } - - var position = dynamicObject.position; - var propertyCreated = !defined(position); - if (propertyCreated) { - dynamicObject.position = position = new DynamicPositionProperty(); - } - position.processCzmlIntervals(positionData); - return propertyCreated; - }; - - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's viewFrom - * property. This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the viewFrom data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if the property was newly created while processing the packet, false otherwise. - * - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicObject.processCzmlPacketViewFrom = function(dynamicObject, packet) { - var viewFromData = packet.viewFrom; - if (!defined(viewFromData)) { - return false; - } - - var viewFrom = dynamicObject.viewFrom; - var propertyCreated = !defined(viewFrom); - if (propertyCreated) { - dynamicObject.viewFrom = viewFrom = new DynamicProperty(CzmlCartesian3); - } - viewFrom.processCzmlIntervals(viewFromData); - return propertyCreated; - }; - - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's orientation - * property. This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the orientation data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if the property was newly created while processing the packet, false otherwise. - * - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicObject.processCzmlPacketOrientation = function(dynamicObject, packet) { - var orientationData = packet.orientation; - if (!defined(orientationData)) { - return false; - } - - var orientation = dynamicObject.orientation; - var propertyCreated = !defined(orientation); - if (propertyCreated) { - dynamicObject.orientation = orientation = new DynamicProperty(CzmlUnitQuaternion); - } - orientation.processCzmlIntervals(orientationData); - return propertyCreated; - }; - - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's vertexPositions - * property. This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the vertexPositions data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObjectCollection} dynamicObjectCollection The collection to use to resolve any CZML properly links. - * @returns {Boolean} true if the property was newly created while processing the packet, false otherwise. - * - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicObject.processCzmlPacketVertexPositions = function(dynamicObject, packet, dynamicObjectCollection) { - var vertexPositionsData = packet.vertexPositions; - if (!defined(vertexPositionsData)) { - return false; - } - - var vertexPositions = dynamicObject.vertexPositions; - var propertyCreated = !defined(dynamicObject.vertexPositions); - if (propertyCreated) { - dynamicObject.vertexPositions = vertexPositions = new DynamicVertexPositionsProperty(); - } - vertexPositions.processCzmlIntervals(vertexPositionsData, undefined, dynamicObjectCollection); - return propertyCreated; - }; - - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's availability - * property. This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the availability data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if the property was newly created while processing the packet, false otherwise. - * - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicObject.processCzmlPacketAvailability = function(dynamicObject, packet) { - var availability = packet.availability; - if (!defined(availability)) { - return false; - } - - var propertyChanged = false; - var interval = TimeInterval.fromIso8601(availability); - if (defined(interval)) { - propertyChanged = dynamicObject._setAvailability(interval); - } - return propertyChanged; - }; - /** * Given two DynamicObjects, takes the position, orientation, vertexPositions and availability * properties from the second and assigns them to the first, assuming such properties did not - * already exist. This method is not normally called directly, but is part of the array of CZML - * processing functions that is passed into the CompositeDynamicObjectCollection constructor. + * already exist. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicObject.mergeProperties = function(targetObject, objectToMerge) { targetObject.position = defaultValue(targetObject.position, objectToMerge.position); @@ -395,8 +227,6 @@ define([ * CZML processing functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the billboard from. - * - * @see CzmlDefaults */ DynamicObject.undefineProperties = function(dynamicObject) { dynamicObject.position = undefined; diff --git a/Source/DynamicScene/DynamicObjectView.js b/Source/DynamicScene/DynamicObjectView.js index 3ce5ae6955c0..1d7f617d6b52 100644 --- a/Source/DynamicScene/DynamicObjectView.js +++ b/Source/DynamicScene/DynamicObjectView.js @@ -33,7 +33,7 @@ define([ SceneMode) { "use strict"; - function update2D(that, camera, objectChanged, offset, positionProperty, time, projection) { + function update2D(that, camera, objectChanged, offset, positionProperty, time, ellipsoid, projection) { var viewDistance; var scene = that.scene; var modeChanged = scene.mode !== that._mode; @@ -48,8 +48,9 @@ define([ viewDistance = camera.position.z; } - var cartographic = positionProperty.getValueCartographic(time, that._lastCartographic); - if (defined(cartographic)) { + var cartesian = positionProperty.getValue(time, that._lastCartesian); + if (defined(cartesian)) { + var cartographic = ellipsoid.cartesianToCartographic(cartesian, that._lastCartographic); //We are assigning the position of the camera, not of the object, so modify the height appropriately. cartographic.height = viewDistance; if (objectChanged || modeChanged) { @@ -85,14 +86,14 @@ define([ function update3D(that, camera, objectChanged, offset, positionProperty, time, ellipsoid) { update3DController(that, camera, objectChanged, offset); - var cartesian = positionProperty.getValueCartesian(time, that._lastCartesian); + var cartesian = positionProperty.getValue(time, that._lastCartesian); if (defined(cartesian)) { var successful = false; // The time delta was determined based on how fast satellites move compared to vehicles near the surface. // Slower moving vehicles will most likely default to east-north-up, while faster ones will be LVLH. var deltaTime = time.addSeconds(0.01); - var deltaCartesian = positionProperty.getValueCartesian(deltaTime, update3DCartesian3Scratch1); + var deltaCartesian = positionProperty.getValue(deltaTime, update3DCartesian3Scratch1); if (defined(deltaCartesian) && !Cartesian3.equalsEpsilon(cartesian, deltaCartesian, CesiumMath.EPSILON6)) { var toInertial = Transforms.computeFixedToIcrfMatrix(time, update3DMatrix3Scratch1); var toInertialDelta = Transforms.computeFixedToIcrfMatrix(deltaTime, update3DMatrix3Scratch2); @@ -169,8 +170,10 @@ define([ update3DController(that, camera, objectChanged, offset); //The swizzling here is intentional because ColumbusView uses a different coordinate system. - var cartographic = positionProperty.getValueCartographic(time, that._lastCartographic); - if (defined(cartographic)) { + var cartesian = positionProperty.getValue(time, that._lastCartesian); + if (defined(cartesian)) { + var cartographic = ellipsoid.cartesianToCartographic(cartesian, that._lastCartographic); + var projectedPosition = projection.project(cartographic); updateColumbusCartesian4.x = projectedPosition.z; updateColumbusCartesian4.y = projectedPosition.x; @@ -360,7 +363,7 @@ define([ var mode = scene.mode; if (mode === SceneMode.SCENE2D) { - update2D(this, scene.getCamera(), objectChanged, offset, positionProperty, time, scene.scene2D.projection); + update2D(this, scene.getCamera(), objectChanged, offset, positionProperty, time, ellipsoid, scene.scene2D.projection); } else if (mode === SceneMode.SCENE3D) { update3D(this, scene.getCamera(), objectChanged, offset, positionProperty, time, ellipsoid); } else if (mode === SceneMode.COLUMBUS_VIEW) { diff --git a/Source/DynamicScene/DynamicPath.js b/Source/DynamicScene/DynamicPath.js index f3ae7e49c2ab..a0c748d8d583 100644 --- a/Source/DynamicScene/DynamicPath.js +++ b/Source/DynamicScene/DynamicPath.js @@ -1,206 +1,66 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlNumber', - './CzmlColor', - './DynamicProperty'], -function( - TimeInterval, + '../Core/defined' + ], function( defaultValue, - defined, - CzmlBoolean, - CzmlNumber, - CzmlColor, - DynamicProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic path, typically used in conjunction with DynamicPathVisualizer and - * DynamicObjectCollection to visualize CZML. - * + * A time-dynamic path representing the visualization of a moving object. * @alias DynamicPath * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicPathVisualizer - * @see VisualizerCollection - * @see Polyline - * @see CzmlDefaults */ var DynamicPath = function() { /** - * A DynamicProperty of type CzmlColor which determines the line's color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the path's color. + * @type {Property} */ this.color = undefined; /** - * A DynamicProperty of type CzmlColor which determines the line's outline color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the path's outline color. + * @type {Property} */ this.outlineColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the line's outline width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the path's outline width. + * @type {Property} */ this.outlineWidth = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the lines's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the path's visibility. + * @type {Property} */ this.show = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the line's width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the path's width. + * @type {Property} */ this.width = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the maximum step size, in seconds, to take when sampling the position. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the maximum step size, in seconds, to take when sampling the position. + * @type {Property} */ this.resolution = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the number of seconds in front of the object to show. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the number of seconds in front of the object to show. + * @type {Property} */ this.leadTime = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the the number of seconds behind the object to show. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the number of seconds behind the object to show. + * @type {Property} */ this.trailTime = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's path. - * If the DynamicObject does not have a path, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the path data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicPath.processCzmlPacket = function(dynamicObject, packet) { - var pathData = packet.path; - if (!defined(pathData)) { - return false; - } - - var pathUpdated = false; - var path = dynamicObject.path; - pathUpdated = !defined(path); - if (pathUpdated) { - dynamicObject.path = path = new DynamicPath(); - } - - var interval = pathData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(pathData.color)) { - var color = path.color; - if (!defined(color)) { - path.color = color = new DynamicProperty(CzmlColor); - pathUpdated = true; - } - color.processCzmlIntervals(pathData.color, interval); - } - - if (defined(pathData.width)) { - var width = path.width; - if (!defined(width)) { - path.width = width = new DynamicProperty(CzmlNumber); - pathUpdated = true; - } - width.processCzmlIntervals(pathData.width, interval); - } - - if (defined(pathData.resolution)) { - var resolution = path.resolution; - if (!defined(resolution)) { - path.resolution = resolution = new DynamicProperty(CzmlNumber); - pathUpdated = true; - } - resolution.processCzmlIntervals(pathData.resolution, interval); - } - - if (defined(pathData.outlineColor)) { - var outlineColor = path.outlineColor; - if (!defined(outlineColor)) { - path.outlineColor = outlineColor = new DynamicProperty(CzmlColor); - pathUpdated = true; - } - outlineColor.processCzmlIntervals(pathData.outlineColor, interval); - } - - if (defined(pathData.outlineWidth)) { - var outlineWidth = path.outlineWidth; - if (!defined(outlineWidth)) { - path.outlineWidth = outlineWidth = new DynamicProperty(CzmlNumber); - pathUpdated = true; - } - outlineWidth.processCzmlIntervals(pathData.outlineWidth, interval); - } - - if (defined(pathData.show)) { - var show = path.show; - if (!defined(show)) { - path.show = show = new DynamicProperty(CzmlBoolean); - pathUpdated = true; - } - show.processCzmlIntervals(pathData.show, interval); - } - - if (defined(pathData.leadTime)) { - var leadTime = path.leadTime; - if (!defined(leadTime)) { - path.leadTime = leadTime = new DynamicProperty(CzmlNumber); - pathUpdated = true; - } - leadTime.processCzmlIntervals(pathData.leadTime, interval); - } - - if (defined(pathData.trailTime)) { - var trailTime = path.trailTime; - if (!defined(trailTime)) { - path.trailTime = trailTime = new DynamicProperty(CzmlNumber); - pathUpdated = true; - } - trailTime.processCzmlIntervals(pathData.trailTime, interval); - } - - return pathUpdated; - }; - /** * Given two DynamicObjects, takes the path properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicPath.mergeProperties = function(targetObject, objectToMerge) { var pathToMerge = objectToMerge.path; @@ -224,12 +84,8 @@ function( /** * Given a DynamicObject, undefines the path associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the path from. - * - * @see CzmlDefaults */ DynamicPath.undefineProperties = function(dynamicObject) { dynamicObject.path = undefined; diff --git a/Source/DynamicScene/DynamicPathVisualizer.js b/Source/DynamicScene/DynamicPathVisualizer.js index 0ab42733bb18..d7bf7712cae2 100644 --- a/Source/DynamicScene/DynamicPathVisualizer.js +++ b/Source/DynamicScene/DynamicPathVisualizer.js @@ -9,6 +9,9 @@ define([ '../Core/Color', '../Core/Transforms', '../Core/ReferenceFrame', + './SampledPositionProperty', + './CompositePositionProperty', + './TimeIntervalCollectionPositionProperty', '../Scene/Material', '../Scene/SceneMode', '../Scene/PolylineCollection' @@ -22,11 +25,178 @@ define([ Color, Transforms, ReferenceFrame, + SampledPositionProperty, + CompositePositionProperty, + TimeIntervalCollectionPositionProperty, Material, SceneMode, PolylineCollection) { "use strict"; + function subSampleSampledProperty(property, start, stop, updateTime, referenceFrame, maximumStep, startingIndex, result) { + var times = property._property._times; + + var r = startingIndex; + //Always step exactly on start (but only use it if it exists.) + var tmp; + tmp = property.getValueInReferenceFrame(start, referenceFrame, result[r]); + if (defined(tmp)) { + result[r++] = tmp; + } + + var steppedOnNow = !defined(updateTime) || updateTime.lessThanOrEquals(start) || updateTime.greaterThanOrEquals(stop); + + //Iterate over all interval times and add the ones that fall in our + //time range. Note that times can contain data outside of + //the intervals range. This is by design for use with interpolation. + var t = 0; + var len = times.length; + var current = times[t]; + var loopStop = stop; + var sampling = false; + var sampleStepsToTake; + var sampleStepsTaken; + var sampleStepSize; + + while (t < len) { + if (!steppedOnNow && current.greaterThanOrEquals(updateTime)) { + tmp = property.getValueInReferenceFrame(updateTime, referenceFrame, result[r]); + if (defined(tmp)) { + result[r++] = tmp; + } + steppedOnNow = true; + } + if (current.greaterThan(start) && current.lessThan(loopStop) && !current.equals(updateTime)) { + tmp = property.getValueInReferenceFrame(current, referenceFrame, result[r]); + if (defined(tmp)) { + result[r++] = tmp; + } + } + + if (t < (len - 1)) { + if (!sampling) { + var next = times[t + 1]; + var secondsUntilNext = current.getSecondsDifference(next); + sampling = secondsUntilNext > maximumStep; + + if (sampling) { + sampleStepsToTake = Math.floor(secondsUntilNext / maximumStep); + sampleStepsTaken = 0; + sampleStepSize = secondsUntilNext / Math.max(sampleStepsToTake, 2); + sampleStepsToTake = Math.max(sampleStepsToTake - 2, 1); + } + } + + if (sampling && sampleStepsTaken < sampleStepsToTake) { + current = current.addSeconds(sampleStepSize); + sampleStepsTaken++; + continue; + } + } + sampling = false; + t++; + current = times[t]; + } + + //Always step exactly on stop (but only use it if it exists.) + tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[r]); + if (defined(tmp)) { + result[r++] = tmp; + } + + return r; + } + + function subSampleGenericProperty(property, start, stop, updateTime, referenceFrame, maximumStep, startingIndex, result) { + var tmp; + var i = 0; + var index = startingIndex; + var time = start; + var steppedOnNow = !defined(updateTime) || updateTime.lessThanOrEquals(start) || updateTime.greaterThanOrEquals(stop); + while (time.lessThan(stop)) { + if (!steppedOnNow && time.greaterThanOrEquals(updateTime)) { + steppedOnNow = true; + tmp = property.getValueInReferenceFrame(updateTime, referenceFrame, result[index]); + if (defined(tmp)) { + result[index] = tmp; + index++; + } + } + tmp = property.getValueInReferenceFrame(time, referenceFrame, result[index]); + if (defined(tmp)) { + result[index] = tmp; + index++; + } + i++; + time = start.addSeconds(maximumStep * i); + } + //Always sample stop. + tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[index]); + if (defined(tmp)) { + result[index] = tmp; + index++; + } + return index; + } + + function subSampleIntervalProperty(property, start, stop, updateTime, referenceFrame, maximumStep, startingIndex, result) { + var index = startingIndex; + var intervals = property.getIntervals(); + for ( var i = 0; i < intervals.getLength(); i++) { + var interval = intervals.get(0); + if (interval.start.lessThanOrEquals(stop)) { + var tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[index]); + if (defined(tmp)) { + result[index] = tmp; + index++; + } + } + } + return index; + } + + function subSampleCompositeProperty(property, start, stop, updateTime, referenceFrame, maximumStep, startingIndex, result) { + var index = startingIndex; + var intervals = property.getIntervals(); + for ( var i = 0; i < intervals.getLength(); i++) { + var interval = intervals.get(0); + if (interval.start.lessThanOrEquals(stop)) { + var intervalProperty = interval.data; + if (intervalProperty instanceof SampledPositionProperty) { + index = subSampleSampledProperty(intervalProperty, interval.start, interval.stop, updateTime, referenceFrame, maximumStep, index, result); + } else if (intervalProperty instanceof CompositePositionProperty) { + index = subSampleCompositeProperty(intervalProperty, interval.start, interval.stop, updateTime, referenceFrame, maximumStep, index, result); + } else if (intervalProperty instanceof TimeIntervalCollectionPositionProperty) { + index = subSampleIntervalProperty(intervalProperty, interval.start, interval.stop, updateTime, referenceFrame, maximumStep, index, result); + } else { + //Fallback to generic sampling. + index = subSampleGenericProperty(intervalProperty, interval.start, interval.stop, updateTime, referenceFrame, maximumStep, index, result); + } + } + } + return index; + } + + function subSample(property, start, stop, updateTime, referenceFrame, maximumStep, result) { + if (!defined(result)) { + result = []; + } + + var length = 0; + if (property instanceof SampledPositionProperty) { + length = subSampleSampledProperty(property, start, stop, updateTime, referenceFrame, maximumStep, 0, result); + } else if (property instanceof CompositePositionProperty) { + length = subSampleCompositeProperty(property, start, stop, updateTime, referenceFrame, maximumStep, 0, result); + } else if (property instanceof TimeIntervalCollectionPositionProperty) { + length = subSampleCompositeProperty(property, start, stop, updateTime, referenceFrame, maximumStep, 0, result); + } else { + //Fallback to generic sampling. + length = subSampleGenericProperty(property, start, stop, updateTime, referenceFrame, maximumStep, 0, result); + } + result.length = length; + return result; + } + var toFixedScratch = new Matrix3(); var PolylineUpdater = function(scene, referenceFrame) { this._unusedIndexes = []; @@ -160,7 +330,7 @@ define([ resolution = property.getValue(time); } - polyline.setPositions(positionProperty._getValueRangeInReferenceFrame(sampleStart, sampleStop, time, this._referenceFrame, resolution, polyline.getPositions())); + polyline.setPositions(subSample(positionProperty, sampleStart, sampleStop, time, this._referenceFrame, resolution, polyline.getPositions())); property = dynamicPath.color; if (defined(property)) { @@ -313,7 +483,7 @@ define([ var frameToVisualize = ReferenceFrame.FIXED; if (this._scene.mode === SceneMode.SCENE3D) { - frameToVisualize = positionProperty._getReferenceFrame(); + frameToVisualize = positionProperty.referenceFrame; } var currentUpdater = this._updaters[frameToVisualize]; diff --git a/Source/DynamicScene/DynamicPoint.js b/Source/DynamicScene/DynamicPoint.js index 1129d86142a5..4383b2ad4252 100644 --- a/Source/DynamicScene/DynamicPoint.js +++ b/Source/DynamicScene/DynamicPoint.js @@ -1,156 +1,51 @@ /*global define*/ define([ '../Core/defined', - '../Core/TimeInterval', - '../Core/defaultValue', - './CzmlBoolean', - './CzmlNumber', - './CzmlColor', - './DynamicProperty' + '../Core/defaultValue' ], function( defined, - TimeInterval, - defaultValue, - CzmlBoolean, - CzmlNumber, - CzmlColor, - DynamicProperty) { + defaultValue) { "use strict"; /** - * Represents a time-dynamic point, typically used in conjunction with DynamicPointVisualizer and - * DynamicObjectCollection to visualize CZML. - * + * An optionally time-dynamic billboard. * @alias DynamicPoint * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicPointVisualizer - * @see VisualizerCollection - * @see Billboard - * @see BillboardCollection - * @see CzmlDefaults */ var DynamicPoint = function() { /** - * A DynamicProperty of type CzmlColor which determines the point's color. - * @type DynamicProperty + * Gets or sets the {@link Color} {@link Property} specifying the the point's color. + * @type {Property} */ this.color = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the point's pixel size. - * @type DynamicProperty + * Gets or sets the numeric {@link Property} specifying the point's size in pixels. + * @type {Property} */ this.pixelSize = undefined; /** - * A DynamicProperty of type CzmlColor which determines the point's outline color. - * @type DynamicProperty + * Gets or sets the {@link Color} {@link Property} specifying the the point's outline color. + * @type {Property} */ this.outlineColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the point's outline width. - * @type DynamicProperty + * Gets or sets the numeric {@link Property} specifying the the point's outline width. + * @type {Property} */ this.outlineWidth = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the point's visibility. - * @type DynamicProperty + * Gets or sets the boolean {@link Property} specifying the point's visibility. + * @type {Property} */ this.show = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's point. - * If the DynamicObject does not have a point, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the point data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicPoint.processCzmlPacket = function(dynamicObject, packet) { - var pointData = packet.point; - if (!defined(pointData)) { - return false; - } - - var pointUpdated = false; - var point = dynamicObject.point; - pointUpdated = !defined(point); - if (pointUpdated) { - dynamicObject.point = point = new DynamicPoint(); - } - - var interval = pointData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(pointData.color)) { - var color = point.color; - if (!defined(color)) { - point.color = color = new DynamicProperty(CzmlColor); - pointUpdated = true; - } - color.processCzmlIntervals(pointData.color, interval); - } - - if (defined(pointData.pixelSize)) { - var pixelSize = point.pixelSize; - if (!defined(pixelSize)) { - point.pixelSize = pixelSize = new DynamicProperty(CzmlNumber); - pointUpdated = true; - } - pixelSize.processCzmlIntervals(pointData.pixelSize, interval); - } - - if (defined(pointData.outlineColor)) { - var outlineColor = point.outlineColor; - if (!defined(outlineColor)) { - point.outlineColor = outlineColor = new DynamicProperty(CzmlColor); - pointUpdated = true; - } - outlineColor.processCzmlIntervals(pointData.outlineColor, interval); - } - - if (defined(pointData.outlineWidth)) { - var outlineWidth = point.outlineWidth; - if (!defined(outlineWidth)) { - point.outlineWidth = outlineWidth = new DynamicProperty(CzmlNumber); - pointUpdated = true; - } - outlineWidth.processCzmlIntervals(pointData.outlineWidth, interval); - } - - if (defined(pointData.show)) { - var show = point.show; - if (!defined(show)) { - point.show = show = new DynamicProperty(CzmlBoolean); - pointUpdated = true; - } - show.processCzmlIntervals(pointData.show, interval); - } - return pointUpdated; - }; - /** * Given two DynamicObjects, takes the point properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicPoint.mergeProperties = function(targetObject, objectToMerge) { var pointToMerge = objectToMerge.point; @@ -171,16 +66,12 @@ define([ /** * Given a DynamicObject, undefines the point associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the point from. - * - * @see CzmlDefaults */ DynamicPoint.undefineProperties = function(dynamicObject) { dynamicObject.point = undefined; }; return DynamicPoint; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/DynamicPointVisualizer.js b/Source/DynamicScene/DynamicPointVisualizer.js index c89d2b38f878..ea0890d842f8 100644 --- a/Source/DynamicScene/DynamicPointVisualizer.js +++ b/Source/DynamicScene/DynamicPointVisualizer.js @@ -227,7 +227,7 @@ define([ billboard.setShow(true); - position = positionProperty.getValueCartesian(time, position); + position = positionProperty.getValue(time, position); if (defined(position)) { billboard.setPosition(position); } @@ -322,4 +322,4 @@ define([ }; return DynamicPointVisualizer; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/DynamicPolygon.js b/Source/DynamicScene/DynamicPolygon.js index f2a6b1add21b..ff4922fdad6d 100644 --- a/Source/DynamicScene/DynamicPolygon.js +++ b/Source/DynamicScene/DynamicPolygon.js @@ -1,115 +1,37 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './DynamicProperty', - './DynamicMaterialProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - DynamicProperty, - DynamicMaterialProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic polygon, typically used in conjunction with DynamicPolygonVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic polygon. * * @alias DynamicPolygon * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicPolygonVisualizer - * @see VisualizerCollection - * @see Polygon - * @see CzmlDefaults */ var DynamicPolygon = function() { /** - * A DynamicProperty of type CzmlBoolean which determines the polygon's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the polygon's visibility. + * @type {Property} */ this.show = undefined; /** - * A DynamicMaterialProperty which determines the polygon's material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the appearance of the polygon. + * @type {MaterialProperty} */ this.material = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's polygon. - * If the DynamicObject does not have a polygon, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the polygon data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObjectCollection} [dynamicObjectCollection] The collection into which objects are being loaded. - * @param {String} [sourceUri] The originating url of the CZML being processed. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicPolygon.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection, sourceUri) { - var polygonData = packet.polygon; - if (!defined(polygonData)) { - return false; - } - - var polygonUpdated = false; - var polygon = dynamicObject.polygon; - polygonUpdated = !defined(polygon); - if (polygonUpdated) { - dynamicObject.polygon = polygon = new DynamicPolygon(); - } - - var interval = polygonData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(polygonData.show)) { - var show = polygon.show; - if (!defined(show)) { - polygon.show = show = new DynamicProperty(CzmlBoolean); - polygonUpdated = true; - } - show.processCzmlIntervals(polygonData.show, interval); - } - - if (defined(polygonData.material)) { - var material = polygon.material; - if (!defined(material)) { - polygon.material = material = new DynamicMaterialProperty(); - polygonUpdated = true; - } - material.processCzmlIntervals(polygonData.material, interval, sourceUri); - } - return polygonUpdated; - }; - /** * Given two DynamicObjects, takes the polygon properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicPolygon.mergeProperties = function(targetObject, objectToMerge) { var polygonToMerge = objectToMerge.polygon; @@ -127,12 +49,8 @@ define([ /** * Given a DynamicObject, undefines the polygon associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the polygon from. - * - * @see CzmlDefaults */ DynamicPolygon.undefineProperties = function(dynamicObject) { dynamicObject.polygon = undefined; diff --git a/Source/DynamicScene/DynamicPolygonVisualizer.js b/Source/DynamicScene/DynamicPolygonVisualizer.js index 18c81d695b27..9afe1b3ea1ba 100644 --- a/Source/DynamicScene/DynamicPolygonVisualizer.js +++ b/Source/DynamicScene/DynamicPolygonVisualizer.js @@ -5,14 +5,16 @@ define([ '../Core/DeveloperError', '../Core/destroyObject', '../Scene/Polygon', - '../Scene/Material' + '../Scene/Material', + './MaterialProperty' ], function( Cartesian3, defined, DeveloperError, destroyObject, Polygon, - Material) { + Material, + MaterialProperty) { "use strict"; /** @@ -224,9 +226,9 @@ define([ var vertexPositions; if (hasVertexPostions) { - vertexPositions = vertexPositionsProperty.getValueCartesian(time); + vertexPositions = vertexPositionsProperty.getValue(time); } else { - vertexPositions = ellipseProperty.getValue(time, positionProperty.getValueCartesian(time, cachedPosition)); + vertexPositions = ellipseProperty.getValue(time, positionProperty.getValue(time, cachedPosition)); } if (polygon._visualizerPositions !== vertexPositions && // @@ -236,10 +238,7 @@ define([ polygon._visualizerPositions = vertexPositions; } - var material = dynamicPolygon.material; - if (defined(material)) { - polygon.material = material.getValue(time, context, polygon.material); - } + polygon.material = MaterialProperty.getValue(time, context, dynamicPolygon.material, polygon.material); } DynamicPolygonVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, dynamicObjects) { diff --git a/Source/DynamicScene/DynamicPolyline.js b/Source/DynamicScene/DynamicPolyline.js index 222ed8106cd3..a08d6e13f976 100644 --- a/Source/DynamicScene/DynamicPolyline.js +++ b/Source/DynamicScene/DynamicPolyline.js @@ -1,160 +1,51 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlNumber', - './CzmlColor', - './DynamicProperty'], + '../Core/defined'], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlNumber, - CzmlColor, - DynamicProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic polyline, typically used in conjunction with DynamicPolylineVisualizer and - * DynamicObjectCollection to visualize CZML. - * + * An optionally time-dynamic polyline. * @alias DynamicPolyline * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicPolylineVisualizer - * @see VisualizerCollection - * @see Polyline - * @see CzmlDefaults */ var DynamicPolyline = function() { /** - * A DynamicProperty of type CzmlColor which determines the line's color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the line's color. + * @type {Property} */ this.color = undefined; /** - * A DynamicProperty of type CzmlColor which determines the line's outline color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the line's outline color. + * @type {Property} */ this.outlineColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the line's outline width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the line's outline width. + * @type {Property} */ this.outlineWidth = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the lines's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the line's visibility. + * @type {Property} */ this.show = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the line's width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the line's width. + * @type {Property} */ this.width = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's polyline. - * If the DynamicObject does not have a polyline, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the polyline data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicPolyline.processCzmlPacket = function(dynamicObject, packet) { - var polylineData = packet.polyline; - if (!defined(polylineData)) { - return false; - } - - var polylineUpdated = false; - var polyline = dynamicObject.polyline; - polylineUpdated = !defined(polyline); - if (polylineUpdated) { - dynamicObject.polyline = polyline = new DynamicPolyline(); - } - - var interval = polylineData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(polylineData.color)) { - var color = polyline.color; - if (!defined(color)) { - polyline.color = color = new DynamicProperty(CzmlColor); - polylineUpdated = true; - } - color.processCzmlIntervals(polylineData.color, interval); - } - - if (defined(polylineData.width)) { - var width = polyline.width; - if (!defined(width)) { - polyline.width = width = new DynamicProperty(CzmlNumber); - polylineUpdated = true; - } - width.processCzmlIntervals(polylineData.width, interval); - } - - if (defined(polylineData.outlineColor)) { - var outlineColor = polyline.outlineColor; - if (!defined(outlineColor)) { - polyline.outlineColor = outlineColor = new DynamicProperty(CzmlColor); - polylineUpdated = true; - } - outlineColor.processCzmlIntervals(polylineData.outlineColor, interval); - } - - if (defined(polylineData.outlineWidth)) { - var outlineWidth = polyline.outlineWidth; - if (!defined(outlineWidth)) { - polyline.outlineWidth = outlineWidth = new DynamicProperty(CzmlNumber); - polylineUpdated = true; - } - outlineWidth.processCzmlIntervals(polylineData.outlineWidth, interval); - } - - if (defined(polylineData.show)) { - var show = polyline.show; - if (!defined(show)) { - polyline.show = show = new DynamicProperty(CzmlBoolean); - polylineUpdated = true; - } - show.processCzmlIntervals(polylineData.show, interval); - } - return polylineUpdated; - }; - /** * Given two DynamicObjects, takes the polyline properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicPolyline.mergeProperties = function(targetObject, objectToMerge) { var polylineToMerge = objectToMerge.polyline; @@ -175,12 +66,8 @@ function( /** * Given a DynamicObject, undefines the polyline associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the polyline from. - * - * @see CzmlDefaults */ DynamicPolyline.undefineProperties = function(dynamicObject) { dynamicObject.polyline = undefined; diff --git a/Source/DynamicScene/DynamicPolylineVisualizer.js b/Source/DynamicScene/DynamicPolylineVisualizer.js index e546282d6f26..7f8cec01e3aa 100644 --- a/Source/DynamicScene/DynamicPolylineVisualizer.js +++ b/Source/DynamicScene/DynamicPolylineVisualizer.js @@ -233,9 +233,9 @@ define([ var vertexPositions; if (defined(ellipseProperty)) { - vertexPositions = ellipseProperty.getValue(time, positionProperty.getValueCartesian(time, cachedPosition)); + vertexPositions = ellipseProperty.getValue(time, positionProperty.getValue(time, cachedPosition)); } else { - vertexPositions = vertexPositionsProperty.getValueCartesian(time); + vertexPositions = vertexPositionsProperty.getValue(time); } if (defined(vertexPositions) && polyline._visualizerPositions !== vertexPositions) { diff --git a/Source/DynamicScene/DynamicPositionProperty.js b/Source/DynamicScene/DynamicPositionProperty.js deleted file mode 100644 index 53615f231913..000000000000 --- a/Source/DynamicScene/DynamicPositionProperty.js +++ /dev/null @@ -1,499 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/DeveloperError', - '../Core/Ellipsoid', - '../Core/Iso8601', - '../Core/JulianDate', - '../Core/Matrix3', - '../Core/ReferenceFrame', - '../Core/TimeInterval', - '../Core/TimeIntervalCollection', - '../Core/Transforms', - './CzmlPosition', - './DynamicProperty' - ], function( - defined, - DeveloperError, - Ellipsoid, - Iso8601, - JulianDate, - Matrix3, - ReferenceFrame, - TimeInterval, - TimeIntervalCollection, - Transforms, - CzmlPosition, - DynamicProperty) { - "use strict"; - - var scratchMatrix3 = new Matrix3(); - var wgs84 = Ellipsoid.WGS84; - - function convertToFixed(time, value) { - var icrfToFixed = Transforms.computeIcrfToFixedMatrix(time, scratchMatrix3); - if (!defined(icrfToFixed)) { - icrfToFixed = Transforms.computeTemeToPseudoFixedMatrix(time, scratchMatrix3); - } - return icrfToFixed.multiplyByVector(value, value); - } - - /** - * A dynamic property which stores both Cartesian and Cartographic data - * and can convert and return the desired type of data for a desired time. - * Rather than creating instances of this object directly, it's typically - * created and managed via loading CZML data into a DynamicObjectCollection. - * Instances of this type are exposed via DynamicObject and it's sub-objects - * and are responsible for interpreting and interpolating the data for visualization. - * - * @alias DynamicPositionProperty - * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see ReferenceProperty - * @see DynamicMaterialProperty - * @see DynamicDirectionsProperty - * @see DynamicVertexPositionsProperty - */ - var DynamicPositionProperty = function() { - this._dynamicProperties = []; - this._propertyIntervals = new TimeIntervalCollection(); - this._cachedTime = undefined; - this._cachedInterval = undefined; - }; - - /** - * Processes the provided CZML interval or intervals into this property. - * - * @memberof DynamicPositionProperty - * - * @param {Object} czmlIntervals The CZML data to process. - * @param {TimeInterval} [constrainedInterval] Constrains the processing so that any times outside of this interval are ignored. - */ - DynamicPositionProperty.prototype.processCzmlIntervals = function(czmlIntervals, constrainedInterval) { - if (Array.isArray(czmlIntervals)) { - for ( var i = 0, len = czmlIntervals.length; i < len; i++) { - this._addCzmlInterval(czmlIntervals[i], constrainedInterval); - } - } else { - this._addCzmlInterval(czmlIntervals, constrainedInterval); - } - }; - - /** - * Retrieves the value of the object at the supplied time as a Cartographic. - * @memberof DynamicPositionProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @param {Cartographic} [result] The object to store the result onto, if undefined a new instance will be created. - * @returns The modified result property, or a new instance if result was undefined. - */ - DynamicPositionProperty.prototype.getValueCartographic = function(time, result) { - if (!defined(time)) { - throw new DeveloperError('time is required.'); - } - - var interval = this._cachedInterval; - if (!JulianDate.equals(this._cachedTime, time)) { - this._cachedTime = JulianDate.clone(time, this._cachedTime); - if (!defined(interval) || !interval.contains(time)) { - interval = this._propertyIntervals.findIntervalContainingDate(time); - this._cachedInterval = interval; - } - } - - if (!defined(interval)) { - return undefined; - } - var property = interval.data; - result = interval.cachedValue = property.getValue(time, interval.cachedValue); - if (defined(result)) { - if (interval.data.referenceFrame === ReferenceFrame.INERTIAL) { - result = convertToFixed(time, result); - } - result = wgs84.cartesianToCartographic(result); - } - return result; - }; - - /** - * Retrieves the value of the object at the supplied time as a Cartesian3. - * @memberof DynamicPositionProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @param {Cartesian3} [result] The object to store the result onto, if undefined a new instance will be created. - * @returns The modified result property, or a new instance if result was undefined. - */ - DynamicPositionProperty.prototype.getValueCartesian = function(time, result) { - if (!defined(time)) { - throw new DeveloperError('time is required.'); - } - - var interval = this._cachedInterval; - if (!JulianDate.equals(this._cachedTime, time)) { - this._cachedTime = JulianDate.clone(time, this._cachedTime); - if (!defined(interval) || !interval.contains(time)) { - interval = this._propertyIntervals.findIntervalContainingDate(time); - this._cachedInterval = interval; - } - } - - if (!defined(interval)) { - return undefined; - } - var property = interval.data; - result = property.getValue(time, result); - if (interval.data.referenceFrame === ReferenceFrame.INERTIAL) { - return convertToFixed(time, result); - } - return result; - }; - - /** - * Retrieves all values in the provided time range. Rather than sampling, this - * method returns the actual data points used in the source data, with the exception - * of start, stop and currentTime parameters, which will be sampled. - * - * @param {JulianDate} start The first time to retrieve values for. - * @param {JulianDate} stop The last time to retrieve values for . - * @param {JulianDate} [currentTime] If provided, causes the algorithm to always sample the provided time, assuming it is between start and stop. - * @param {Array} [result] The array into which to store the result. - * @returns The modified result array or a new instance if one was not provided. - */ - DynamicPositionProperty.prototype.getValueRangeCartesian = function(start, stop, currentTime, result) { - if (!defined(start)) { - throw new DeveloperError('start is required'); - } - - if (!defined(stop)) { - throw new DeveloperError('stop is required'); - } - - if (!defined(result)) { - result = []; - } - - var propertyIntervals = this._propertyIntervals; - - var startIndex = defined(start) ? propertyIntervals.indexOf(start) : 0; - var stopIndex = defined(stop) ? propertyIntervals.indexOf(stop) : propertyIntervals.length - 1; - if (startIndex < 0) { - startIndex = ~startIndex; - } - - if (startIndex === propertyIntervals.getLength()) { - result.length = 0; - return result; - } - - if (stopIndex < 0) { - stopIndex = ~stopIndex; - if (stopIndex !== propertyIntervals.getLength()) { - result.length = 0; - return result; - } - stopIndex -= 1; - } - - var r = 0; - //Always step exactly on start (but only use it if it exists.) - var tmp; - tmp = this.getValueCartesian(start, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - - var steppedOnNow = !defined(currentTime) || currentTime.lessThan(start) || currentTime.greaterThan(stop); - for ( var i = startIndex; i < stopIndex + 1; i++) { - var current; - var interval = propertyIntervals.get(i); - var nextInterval = propertyIntervals.get(i + 1); - var loopStop = stop; - if (defined(nextInterval) && stop.greaterThan(nextInterval.start)) { - loopStop = nextInterval.start; - } - var property = interval.data; - var currentInterval = property._intervals.get(0); - var times = currentInterval.data.times; - if (defined(times)) { - //Iterate over all interval times and add the ones that fall in our - //time range. Note that times can contain data outside of - //the intervals range. This is by design for use with interpolation. - var t; - for (t = 0; t < times.length; t++) { - current = times[t]; - if (!steppedOnNow && current.greaterThanOrEquals(currentTime)) { - tmp = property.getValue(currentTime, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - steppedOnNow = true; - } - if (current.greaterThan(start) && current.lessThan(loopStop)) { - tmp = property.getValue(current, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - } - } - } else { - //If times is undefined, it's because the interval contains a single position - //at which it stays for the duration of the interval. - current = interval.start; - - //We don't need to actually step on now in this case, since the next value - //will be the same; but we do still need to check for it. - steppedOnNow = steppedOnNow || current.greaterThanOrEquals(currentTime); - - //Finally, get the value at this non-sampled interval. - if (current.lessThan(loopStop)) { - tmp = property.getValue(current, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - } - } - } - - //Always step exactly on stop (but only use it if it exists.) - tmp = this.getValueCartesian(stop, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - - result.length = r; - return result; - }; - - DynamicPositionProperty.prototype._addCzmlInterval = function(czmlInterval, constrainedInterval) { - this._cachedTime = undefined; - this._cachedInterval = undefined; - - var iso8601Interval = czmlInterval.interval, property, unwrappedInterval; - if (!defined(iso8601Interval)) { - iso8601Interval = Iso8601.MAXIMUM_INTERVAL.clone(); - } else { - iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - } - - if (defined(constrainedInterval)) { - iso8601Interval = iso8601Interval.intersect(constrainedInterval); - } - - //See if we already have data at that interval. - var thisIntervals = this._propertyIntervals; - var existingInterval = thisIntervals.findInterval(iso8601Interval.start, iso8601Interval.stop); - - if (defined(existingInterval)) { - //If so, see if the new data is the same type. - property = existingInterval.data; - if (defined(property)) { - unwrappedInterval = CzmlPosition.unwrapInterval(czmlInterval); - } - } else { - //If not, create it. - existingInterval = iso8601Interval; - thisIntervals.addInterval(existingInterval); - } - - if (!defined(unwrappedInterval)) { - unwrappedInterval = CzmlPosition.unwrapInterval(czmlInterval); - if (defined(unwrappedInterval)) { - property = new DynamicProperty(CzmlPosition); - this._dynamicProperties.push(property); - existingInterval.data = property; - property.referenceFrame = ReferenceFrame.FIXED; - } - } - - //We could handle the data, add it to the property. - if (defined(unwrappedInterval)) { - if (defined(czmlInterval.referenceFrame)) { - existingInterval.data.referenceFrame = ReferenceFrame[czmlInterval.referenceFrame]; - } - property._addCzmlIntervalUnwrapped(iso8601Interval.start, iso8601Interval.stop, unwrappedInterval, czmlInterval.epoch, czmlInterval.interpolationAlgorithm, czmlInterval.interpolationDegree); - } - }; - - DynamicPositionProperty.prototype._getReferenceFrame = function() { - var propertyIntervals = this._propertyIntervals; - if (propertyIntervals.getLength() > 0) { - return propertyIntervals.get(0).data.referenceFrame; - } - return undefined; - }; - - DynamicPositionProperty.prototype._getValueInReferenceFrame = function(time, referenceFrame, result) { - if (!defined(time)) { - throw new DeveloperError('time is required.'); - } - - var interval = this._cachedInterval; - if (!JulianDate.equals(this._cachedTime, time)) { - this._cachedTime = JulianDate.clone(time, this._cachedTime); - if (!defined(interval) || !interval.contains(time)) { - interval = this._propertyIntervals.findIntervalContainingDate(time); - this._cachedInterval = interval; - } - } - - if (!defined(interval)) { - return undefined; - } - var property = interval.data; - result = property.getValue(time, result); - - if (interval.data.referenceFrame !== referenceFrame) { - if (referenceFrame === ReferenceFrame.FIXED) { - return convertToFixed(time, result); - } - if (referenceFrame === ReferenceFrame.INERTIAL) { - var fixedToIcrf = Transforms.computeFixedToIcrfMatrix(time, scratchMatrix3); - if (!defined(fixedToIcrf)) { - return undefined; - } - return fixedToIcrf.multiplyByVector(result, result); - } - } - return result; - }; - - DynamicPositionProperty.prototype._getValueRangeInReferenceFrame = function(start, stop, currentTime, referenceFrame, maximumStep, result) { - if (!defined(start)) { - throw new DeveloperError('start is required'); - } - - if (!defined(stop)) { - throw new DeveloperError('stop is required'); - } - - if (!defined(result)) { - result = []; - } - - var propertyIntervals = this._propertyIntervals; - - var startIndex = defined(start) ? propertyIntervals.indexOf(start) : 0; - var stopIndex = defined(stop) ? propertyIntervals.indexOf(stop) : propertyIntervals.length - 1; - if (startIndex < 0) { - startIndex = ~startIndex; - } - - if (startIndex === propertyIntervals.getLength()) { - result.length = 0; - return result; - } - - if (stopIndex < 0) { - stopIndex = ~stopIndex; - if (stopIndex !== propertyIntervals.getLength()) { - result.length = 0; - return result; - } - stopIndex -= 1; - } - - var r = 0; - //Always step exactly on start (but only use it if it exists.) - var tmp; - tmp = this._getValueInReferenceFrame(start, referenceFrame, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - - var steppedOnNow = !defined(currentTime) || currentTime.lessThan(start) || currentTime.greaterThan(stop); - for ( var i = startIndex; i < stopIndex + 1; i++) { - var current; - var interval = propertyIntervals.get(i); - var nextInterval = propertyIntervals.get(i + 1); - var loopStop = stop; - if (defined(nextInterval) && stop.greaterThan(nextInterval.start)) { - loopStop = nextInterval.start; - } - - var sampling = false; - var sampleStepsToTake; - var sampleStepsTaken; - var sampleStepSize; - - var property = interval.data; - var currentInterval = property._intervals.get(0); - var times = currentInterval.data.times; - if (defined(times)) { - //Iterate over all interval times and add the ones that fall in our - //time range. Note that times can contain data outside of - //the intervals range. This is by design for use with interpolation. - var t = 0; - var len = times.length; - current = times[t]; - while(t < len) { - if (!steppedOnNow && current.greaterThanOrEquals(currentTime)) { - tmp = this._getValueInReferenceFrame(currentTime, referenceFrame, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - steppedOnNow = true; - } - if (current.greaterThan(start) && current.lessThan(loopStop)) { - tmp = this._getValueInReferenceFrame(current, referenceFrame, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - } - - if (t < (len - 1)) { - if (!sampling) { - var next = times[t + 1]; - var secondsUntilNext = current.getSecondsDifference(next); - sampling = secondsUntilNext > maximumStep; - - if (sampling) { - sampleStepsToTake = Math.floor(secondsUntilNext / maximumStep); - sampleStepsTaken = 0; - sampleStepSize = secondsUntilNext / Math.max(sampleStepsToTake, 2); - sampleStepsToTake = Math.max(sampleStepsToTake - 2, 1); - } - } - - if (sampling && sampleStepsTaken < sampleStepsToTake) { - current = current.addSeconds(sampleStepSize); - sampleStepsTaken++; - continue; - } - } - sampling = false; - t++; - current = times[t]; - } - } else { - //If times is undefined, it's because the interval contains a single position - //at which it stays for the duration of the interval. - current = interval.start; - - //We don't need to actually step on now in this case, since the next value - //will be the same; but we do still need to check for it. - steppedOnNow = steppedOnNow || current.greaterThanOrEquals(currentTime); - - //Finally, get the value at this non-sampled interval. - if (current.lessThan(loopStop)) { - tmp = this._getValueInReferenceFrame(current, referenceFrame, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - } - } - } - - //Always step exactly on stop (but only use it if it exists.) - tmp = this._getValueInReferenceFrame(stop, referenceFrame, result[r]); - if (defined(tmp)) { - result[r++] = tmp; - } - - result.length = r; - return result; - }; - - return DynamicPositionProperty; -}); \ No newline at end of file diff --git a/Source/DynamicScene/DynamicProperty.js b/Source/DynamicScene/DynamicProperty.js deleted file mode 100644 index 71e9efdb699d..000000000000 --- a/Source/DynamicScene/DynamicProperty.js +++ /dev/null @@ -1,397 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/DeveloperError', - '../Core/Iso8601', - '../Core/JulianDate', - '../Core/TimeInterval', - '../Core/TimeIntervalCollection', - '../Core/binarySearch', - '../Core/HermitePolynomialApproximation', - '../Core/LinearApproximation', - '../Core/LagrangePolynomialApproximation' - ], function( - defined, - DeveloperError, - Iso8601, - JulianDate, - TimeInterval, - TimeIntervalCollection, - binarySearch, - HermitePolynomialApproximation, - LinearApproximation, - LagrangePolynomialApproximation) { - "use strict"; - - - //CZML_TODO This is more of an idea than a to-do, but currently DynamicProperty requires - //you know the type of data being loaded up-front by passing valueType. We could take - //a similar approach to DynamicMaterialProperty and have a list of potential valueTypes - //that we check for when we encounter data. This would make it possible to support - //properties that are defined in a CZML document but not part of the official spec. This - //would be helpful in cases where a CZML document has $ or # links to other properties, - //but that property itself is not part of another to-spec CZML object. We could still - //allow the user to pass a default valueType if they want to make sure the data - //being processed is only the data of the expected type. - - //Map CZML interval types to their implementation. - var interpolators = { - HERMITE : HermitePolynomialApproximation, - LAGRANGE : LagrangePolynomialApproximation, - LINEAR : LinearApproximation - }; - - //The data associated with each DynamicProperty interval. - function IntervalData() { - this.interpolationAlgorithm = LinearApproximation; - this.numberOfPoints = LinearApproximation.getRequiredDataPoints(1); - this.interpolationDegree = 1; - this.times = undefined; - this.values = undefined; - this.isSampled = false; - this.xTable = undefined; - this.yTable = undefined; - } - - //Converts a CZML defined data into a JulianDate, regardless of whether it was - //specified in epoch seconds or as an ISO8601 string. - function czmlDateToJulianDate(date, epoch) { - if (typeof date === 'string') { - return JulianDate.fromIso8601(date); - } - return epoch.addSeconds(date); - } - - //We can't use splice for inserting new elements because function apply can't handle - //a huge number of arguments. See https://code.google.com/p/chromium/issues/detail?id=56588 - function arrayInsert(array, startIndex, items) { - var i; - var arrayLength = array.length; - var itemsLength = items.length; - var newLength = arrayLength + itemsLength; - - array.length = newLength; - if (arrayLength !== startIndex) { - var q = arrayLength - 1; - for (i = newLength - 1; i >= startIndex; i--) { - array[i] = array[q--]; - } - } - - for (i = 0; i < itemsLength; i++) { - array[startIndex++] = items[i]; - } - } - - /** - *

- * DynamicProperty represents a single value that changes over time. - * Rather than creating instances of this object directly, it's typically - * created and managed via loading CZML data into a DynamicObjectCollection. - * Instances of this type are exposed via DynamicObject and it's sub-objects - * and are responsible for interpreting and interpolating the data for visualization. - *

- *

- * The type of value exposed by this property must be provided during construction - * by passing in an object which performs all the necessary operations needed to - * properly store, retrieve, and interpolate the data. For more specialized needs - * other types of dynamic properties exist, such as DynamicMaterialProperty, - * which as the name implies, handles materials. - *

- * - * @alias DynamicProperty - * @constructor - * - * @param {Object} valueType A CZML type object which contains the methods needed to interpret and interpolate CZML data of the same type. - * - * @see CzmlBoolean - * @see CzmlCartesian2 - * @see CzmlCartesian3 - * @see CzmlPosition - * @see CzmlColor - * @see CzmlHorizontalOrigin - * @see CzmlLabelStyle - * @see CzmlNumber - * @see CzmlString - * @see CzmlUnitCartesian3 - * @see CzmlUnitQuaternion - * @see CzmlUnitSpherical - * @see CzmlVerticalOrigin - * @see DynamicObject - * @see ReferenceProperty - * @see DynamicMaterialProperty - * @see DynamicPositionProperty - * @see DynamicDirectionsProperty - * @see DynamicVertexPositionsProperty - */ - var DynamicProperty = function(valueType) { - if (!defined(valueType)) { - throw new DeveloperError('valueType is required.'); - } - this.valueType = valueType; - this._intervals = new TimeIntervalCollection(); - this._cachedTime = undefined; - this._cachedInterval = undefined; - }; - - /** - * Processes the provided CZML interval or intervals into this property. - * - * @memberof DynamicProperty - * - * @param {Object} czmlIntervals The CZML data to process. - * @param {TimeInterval} [constrainedInterval] Constrains the processing so that any times outside of this interval are ignored. - * @param {String} [sourceUri] The originating url of the CZML being processed. - */ - DynamicProperty.prototype.processCzmlIntervals = function(czmlIntervals, constrainedInterval, sourceUri) { - if (Array.isArray(czmlIntervals)) { - for ( var i = 0, len = czmlIntervals.length; i < len; i++) { - this._addCzmlInterval(czmlIntervals[i], constrainedInterval, sourceUri); - } - } else { - this._addCzmlInterval(czmlIntervals, constrainedInterval, sourceUri); - } - }; - - var interpolationScratch; - - /** - * Returns the value of the property at the specified time. - * @memberof DynamicProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. - * @returns The modified result parameter or a new instance if the result parameter was not supplied. - */ - DynamicProperty.prototype.getValue = function(time, result) { - var valueType = this.valueType; - - if (defined(this._staticValue)) { - return valueType.getValue(this._staticValue, result); - } - - var interval = this._cachedInterval; - if (!JulianDate.equals(this._cachedTime, time)) { - this._cachedTime = JulianDate.clone(time, this._cachedTime); - if (!defined(interval) || !interval.contains(time)) { - interval = this._intervals.findIntervalContainingDate(time); - this._cachedInterval = interval; - } - } - - if (!defined(interval)) { - return undefined; - } - - var intervalData = interval.data; - var times = intervalData.times; - var values = intervalData.values; - if (intervalData.isSampled && times.length >= 0 && values.length > 0) { - var doublesPerValue = valueType.doublesPerValue; - var index = binarySearch(times, time, JulianDate.compare); - if (index < 0) { - if (intervalData.numberOfPoints < 2) { - return undefined; - } - index = ~index; - - if (index >= times.length) { - index = times.length - 1; - } - - var firstIndex = 0; - var lastIndex = times.length - 1; - - var degree = intervalData.numberOfPoints - 1; - var pointsInCollection = lastIndex - firstIndex + 1; - - if (pointsInCollection < degree + 1) { - // Use the entire range. - } else { - var computedFirstIndex = index - ((degree / 2) | 0) - 1; - if (computedFirstIndex < firstIndex) { - computedFirstIndex = firstIndex; - } - var computedLastIndex = computedFirstIndex + degree; - if (computedLastIndex > lastIndex) { - computedLastIndex = lastIndex; - computedFirstIndex = computedLastIndex - degree; - if (computedFirstIndex < firstIndex) { - computedFirstIndex = firstIndex; - } - } - - firstIndex = computedFirstIndex; - lastIndex = computedLastIndex; - } - - var length = lastIndex - firstIndex + 1; - - var doublesPerInterpolationValue = valueType.doublesPerInterpolationValue; - var xTable = intervalData.xTable; - var yTable = intervalData.yTable; - - if (!defined(xTable)) { - xTable = intervalData.xTable = new Array(intervalData.numberOfPoints); - yTable = intervalData.yTable = new Array(intervalData.numberOfPoints * doublesPerInterpolationValue); - } - - // Build the tables - for ( var i = 0; i < length; ++i) { - xTable[i] = times[lastIndex].getSecondsDifference(times[firstIndex + i]); - } - var specializedPackFunction = valueType.packValuesForInterpolation; - if (!defined(specializedPackFunction)) { - var destinationIndex = 0; - var sourceIndex = firstIndex * doublesPerValue; - var stop = (lastIndex + 1) * doublesPerValue; - - while (sourceIndex < stop) { - yTable[destinationIndex] = values[sourceIndex]; - sourceIndex++; - destinationIndex++; - } - } else { - specializedPackFunction(values, yTable, firstIndex, lastIndex); - } - - // Interpolate! - var x = times[lastIndex].getSecondsDifference(time); - interpolationScratch = intervalData.interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, doublesPerInterpolationValue, interpolationScratch); - - var specializedGetFunction = valueType.getValueFromInterpolationResult; - if (!defined(specializedGetFunction)) { - return valueType.getValueFromArray(interpolationScratch, 0, result); - } - return specializedGetFunction(interpolationScratch, result, values, firstIndex, lastIndex); - } - return valueType.getValueFromArray(intervalData.values, index * doublesPerValue, result); - } - return valueType.getValue(intervalData.values, result); - }; - - DynamicProperty._mergeNewSamples = function(epoch, times, values, newData, doublesPerValue) { - var newDataIndex = 0; - var i; - var prevItem; - var timesInsertionPoint; - var valuesInsertionPoint; - var timesSpliceArgs; - var valuesSpliceArgs; - var currentTime; - var nextTime; - - while (newDataIndex < newData.length) { - currentTime = czmlDateToJulianDate(newData[newDataIndex], epoch); - timesInsertionPoint = binarySearch(times, currentTime, JulianDate.compare); - - if (timesInsertionPoint < 0) { - //Doesn't exist, insert as many additional values as we can. - timesInsertionPoint = ~timesInsertionPoint; - timesSpliceArgs = []; - - valuesInsertionPoint = timesInsertionPoint * doublesPerValue; - valuesSpliceArgs = []; - prevItem = undefined; - nextTime = times[timesInsertionPoint]; - while (newDataIndex < newData.length) { - currentTime = czmlDateToJulianDate(newData[newDataIndex], epoch); - if ((defined(prevItem) && JulianDate.compare(prevItem, currentTime) >= 0) || - (defined(nextTime) && JulianDate.compare(currentTime, nextTime) >= 0)) { - break; - } - timesSpliceArgs.push(currentTime); - newDataIndex = newDataIndex + 1; - for (i = 0; i < doublesPerValue; i++) { - valuesSpliceArgs.push(newData[newDataIndex]); - newDataIndex = newDataIndex + 1; - } - prevItem = currentTime; - } - - arrayInsert(values, valuesInsertionPoint, valuesSpliceArgs); - arrayInsert(times, timesInsertionPoint, timesSpliceArgs); - } else { - //Found an exact match - for (i = 0; i < doublesPerValue; i++) { - newDataIndex++; - values[(timesInsertionPoint * doublesPerValue) + i] = newData[newDataIndex]; - } - newDataIndex++; - } - } - }; - - DynamicProperty.prototype._addCzmlInterval = function(czmlInterval, constrainedInterval, sourceUri) { - var iso8601Interval = czmlInterval.interval; - if (!defined(iso8601Interval)) { - iso8601Interval = Iso8601.MAXIMUM_INTERVAL; - } else { - iso8601Interval = TimeInterval.fromIso8601(iso8601Interval); - } - - if (defined(constrainedInterval)) { - iso8601Interval = iso8601Interval.intersect(constrainedInterval); - } - - var unwrappedInterval = this.valueType.unwrapInterval(czmlInterval, sourceUri); - if (defined(unwrappedInterval)) { - this._addCzmlIntervalUnwrapped(iso8601Interval.start, iso8601Interval.stop, unwrappedInterval, czmlInterval.epoch, czmlInterval.interpolationAlgorithm, czmlInterval.interpolationDegree); - } - }; - - DynamicProperty.prototype._addCzmlIntervalUnwrapped = function(start, stop, unwrappedInterval, epoch, interpolationAlgorithmType, interpolationDegree) { - var thisIntervals = this._intervals; - var existingInterval = thisIntervals.findInterval(start, stop); - this._cachedTime = undefined; - this._cachedInterval = undefined; - - var intervalData; - if (!defined(existingInterval)) { - intervalData = new IntervalData(); - existingInterval = new TimeInterval(start, stop, true, true, intervalData); - thisIntervals.addInterval(existingInterval); - } else { - intervalData = existingInterval.data; - } - - var valueType = this.valueType; - if (valueType.isSampled(unwrappedInterval)) { - var interpolationAlgorithm; - if (defined(interpolationAlgorithmType)) { - interpolationAlgorithm = interpolators[interpolationAlgorithmType]; - intervalData.interpolationAlgorithm = interpolationAlgorithm; - } - if (defined(interpolationAlgorithm) && defined(interpolationDegree)) { - intervalData.interpolationDegree = interpolationDegree; - intervalData.xTable = undefined; - intervalData.yTable = undefined; - } - - if (!intervalData.isSampled) { - intervalData.times = []; - intervalData.values = []; - intervalData.isSampled = true; - } - if (defined(epoch)) { - epoch = JulianDate.fromIso8601(epoch); - } - DynamicProperty._mergeNewSamples(epoch, intervalData.times, intervalData.values, unwrappedInterval, valueType.doublesPerValue, valueType); - intervalData.numberOfPoints = Math.min(intervalData.interpolationAlgorithm.getRequiredDataPoints(intervalData.interpolationDegree), intervalData.times.length); - this._staticValue = undefined; - } else { - //Packet itself is a constant value - intervalData.times = undefined; - intervalData.values = unwrappedInterval; - intervalData.isSampled = false; - - if (existingInterval.equals(Iso8601.MAXIMUM_INTERVAL)) { - this._staticValue = unwrappedInterval; - } else { - this._staticValue = undefined; - } - } - }; - - return DynamicProperty; -}); \ No newline at end of file diff --git a/Source/DynamicScene/DynamicPyramid.js b/Source/DynamicScene/DynamicPyramid.js index 55c0db5a2fa6..cac9d288a810 100644 --- a/Source/DynamicScene/DynamicPyramid.js +++ b/Source/DynamicScene/DynamicPyramid.js @@ -1,196 +1,63 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlNumber', - './CzmlColor', - './DynamicProperty', - './DynamicDirectionsProperty', - './DynamicMaterialProperty' + '../Core/defined' ], function( - TimeInterval, defaultValue, - defined, - CzmlBoolean, - CzmlNumber, - CzmlColor, - DynamicProperty, - DynamicDirectionsProperty, - DynamicMaterialProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic pyramid, typically used in conjunction with DynamicPyramidVisualizer and - * DynamicObjectCollection to visualize CZML. + * An optionally time-dynamic pyramid. * * @alias DynamicPyramid * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicPyramidVisualizer - * @see VisualizerCollection - * @see CustomSensor - * @see CzmlDefaults */ var DynamicPyramid = function() { /** - * A DynamicProperty of type CzmlBoolean which determines the pyramid's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the visibility of the pyramid. + * @type {Property} */ this.show = undefined; /** - * A DynamicDirectionsProperty which determines the projection of the pyramid. - * @type {DynamicDirectionsProperty} + * A {@link Property} which returns an array of {@link Spherical} instances representing the pyramid's projection. + * @type {Property} * @default undefined */ this.directions = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the pyramid's radius. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the radius of the pyramid's projection. + * @type {Property} */ this.radius = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the pyramid's intersection visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the visibility of the line formed by the intersection of the pyramid and other central bodies. + * @type {Property} */ this.showIntersection = undefined; /** - * A DynamicProperty of type CzmlColor which determines the color of the line formed by the intersection of the pyramid and other central bodies. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the color of the line formed by the intersection of the pyramid and other central bodies. + * @type {Property} */ this.intersectionColor = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the approximate pixel width of the line formed by the intersection of the pyramid and other central bodies. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the width of the line formed by the intersection of the pyramid and other central bodies. + * @type {Property} */ this.intersectionWidth = undefined; /** - * A DynamicMaterialProperty which determines the material. - * @type {DynamicMaterialProperty} - * @default undefined + * Gets or sets the {@link MaterialProperty} specifying the the pyramid's appearance. + * @type {MaterialProperty} */ this.material = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's pyramid. - * If the DynamicObject does not have a pyramid, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the pyramid data. - * @param {Object} packet The CZML packet to process. - * @param {DynamicObject} dynamicObjectCollection The DynamicObjectCollection to which the DynamicObject belongs. - * - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicPyramid.processCzmlPacket = function(dynamicObject, packet, dynamicObjectCollection) { - var pyramidData = packet.pyramid; - if (!defined(pyramidData)) { - return false; - } - - var pyramidUpdated = false; - var pyramid = dynamicObject.pyramid; - pyramidUpdated = !defined(pyramid); - if (pyramidUpdated) { - dynamicObject.pyramid = pyramid = new DynamicPyramid(); - } - - var interval = pyramidData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(pyramidData.show)) { - var show = pyramid.show; - if (!defined(show)) { - pyramid.show = show = new DynamicProperty(CzmlBoolean); - pyramidUpdated = true; - } - show.processCzmlIntervals(pyramidData.show, interval); - } - - if (defined(pyramidData.radius)) { - var radius = pyramid.radius; - if (!defined(radius)) { - pyramid.radius = radius = new DynamicProperty(CzmlNumber); - pyramidUpdated = true; - } - radius.processCzmlIntervals(pyramidData.radius, interval); - } - - if (defined(pyramidData.showIntersection)) { - var showIntersection = pyramid.showIntersection; - if (!defined(showIntersection)) { - pyramid.showIntersection = showIntersection = new DynamicProperty(CzmlBoolean); - pyramidUpdated = true; - } - showIntersection.processCzmlIntervals(pyramidData.showIntersection, interval); - } - - if (defined(pyramidData.intersectionColor)) { - var intersectionColor = pyramid.intersectionColor; - if (!defined(intersectionColor)) { - pyramid.intersectionColor = intersectionColor = new DynamicProperty(CzmlColor); - pyramidUpdated = true; - } - intersectionColor.processCzmlIntervals(pyramidData.intersectionColor, interval); - } - - if (defined(pyramidData.intersectionWidth)) { - var intersectionWidth = pyramid.intersectionWidth; - if (!defined(intersectionWidth)) { - pyramid.intersectionWidth = intersectionWidth = new DynamicProperty(CzmlNumber); - pyramidUpdated = true; - } - intersectionWidth.processCzmlIntervals(pyramidData.intersectionWidth, interval); - } - - if (defined(pyramidData.material)) { - var material = pyramid.material; - if (!defined(material)) { - pyramid.material = material = new DynamicMaterialProperty(); - pyramidUpdated = true; - } - material.processCzmlIntervals(pyramidData.material, interval); - } - - if (defined(pyramidData.directions)) { - var directions = pyramid.directions; - if (!defined(directions)) { - pyramid.directions = directions = new DynamicDirectionsProperty(); - pyramidUpdated = true; - } - directions.processCzmlIntervals(pyramidData.directions, interval); - } - return pyramidUpdated; - }; - /** * Given two DynamicObjects, takes the pyramid properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicPyramid.mergeProperties = function(targetObject, objectToMerge) { var pyramidToMerge = objectToMerge.pyramid; @@ -213,12 +80,8 @@ define([ /** * Given a DynamicObject, undefines the pyramid associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the pyramid from. - * - * @see CzmlDefaults */ DynamicPyramid.undefineProperties = function(dynamicObject) { dynamicObject.pyramid = undefined; diff --git a/Source/DynamicScene/DynamicPyramidVisualizer.js b/Source/DynamicScene/DynamicPyramidVisualizer.js index 8a48c53bd0d8..5c15824c6d40 100644 --- a/Source/DynamicScene/DynamicPyramidVisualizer.js +++ b/Source/DynamicScene/DynamicPyramidVisualizer.js @@ -8,7 +8,8 @@ define([ '../Core/Matrix3', '../Core/Matrix4', '../Scene/CustomSensorVolume', - '../Scene/Material' + '../Scene/Material', + './MaterialProperty' ], function( defaultValue, defined, @@ -18,7 +19,8 @@ define([ Matrix3, Matrix4, CustomSensorVolume, - Material) { + Material, + MaterialProperty) { "use strict"; var matrix3Scratch = new Matrix3(); @@ -246,13 +248,13 @@ define([ pyramid.show = true; - var directions = directionsProperty.getValueSpherical(time); + var directions = directionsProperty.getValue(time); if (defined(directions) && pyramid._visualizerDirections !== directions) { pyramid.setDirections(directions); pyramid._visualizerDirections = directions; } - position = defaultValue(positionProperty.getValueCartesian(time, position), pyramid._visualizerPosition); + position = defaultValue(positionProperty.getValue(time, position), pyramid._visualizerPosition); orientation = defaultValue(orientationProperty.getValue(time, orientation), pyramid._visualizerOrientation); if (defined(position) && @@ -264,10 +266,7 @@ define([ orientation.clone(pyramid._visualizerOrientation); } - var material = dynamicPyramid.material; - if (defined(material)) { - pyramid.material = material.getValue(time, context, pyramid.material); - } + pyramid.material = MaterialProperty.getValue(time, context, dynamicPyramid.material, pyramid.material); var property = dynamicPyramid.intersectionColor; if (defined(property)) { @@ -310,4 +309,4 @@ define([ }; return DynamicPyramidVisualizer; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/DynamicVector.js b/Source/DynamicScene/DynamicVector.js index eb511a1b4409..4ea710a85355 100644 --- a/Source/DynamicScene/DynamicVector.js +++ b/Source/DynamicScene/DynamicVector.js @@ -1,161 +1,51 @@ /*global define*/ define([ - '../Core/TimeInterval', '../Core/defaultValue', - '../Core/defined', - './CzmlBoolean', - './CzmlDirection', - './CzmlNumber', - './CzmlColor', - './DynamicProperty'], -function( - TimeInterval, + '../Core/defined' + ], function( defaultValue, - defined, - CzmlBoolean, - CzmlDirection, - CzmlNumber, - CzmlColor, - DynamicProperty) { + defined) { "use strict"; /** - * Represents a time-dynamic vector, typically used in conjunction with DynamicVectorVisualizer and - * DynamicObjectCollection to visualize CZML. - * + * An optionally time-dynamic vector. * @alias DynamicVector * @constructor - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see DynamicVectorVisualizer - * @see VisualizerCollection - * @see CzmlDefaults */ var DynamicVector = function() { /** - * A DynamicProperty of type CzmlColor which determines the vector's color. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Color} {@link Property} specifying the the vector's color. + * @type {Property} */ this.color = undefined; /** - * A DynamicProperty of type CzmlBoolean which determines the vector's visibility. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the boolean {@link Property} specifying the vector's visibility. + * @type {Property} */ this.show = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the vector's width. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the vector's width. + * @type {Property} */ this.width = undefined; /** - * A DynamicProperty of type CzmlDirection which determines the vector's direction. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the {@link Cartesian3} {@link Property} specifying the the vector's direction. + * @type {Property} */ this.direction = undefined; /** - * A DynamicProperty of type CzmlNumber which determines the vector's graphical length. - * @type {DynamicProperty} - * @default undefined + * Gets or sets the numeric {@link Property} specifying the the vector's graphical length in meters. + * @type {Property} */ this.length = undefined; }; - /** - * Processes a single CZML packet and merges its data into the provided DynamicObject's vector. - * If the DynamicObject does not have a vector, one is created. This method is not - * normally called directly, but is part of the array of CZML processing functions that is - * passed into the DynamicObjectCollection constructor. - * - * @param {DynamicObject} dynamicObject The DynamicObject which will contain the vector data. - * @param {Object} packet The CZML packet to process. - * @returns {Boolean} true if any new properties were created while processing the packet, false otherwise. - * - * @see DynamicObject - * @see DynamicProperty - * @see DynamicObjectCollection - * @see CzmlDefaults#updaters - */ - DynamicVector.processCzmlPacket = function(dynamicObject, packet) { - var vectorData = packet.vector; - if (!defined(vectorData)) { - return false; - } - - var vectorUpdated = false; - var vector = dynamicObject.vector; - vectorUpdated = !defined(vector); - if (vectorUpdated) { - dynamicObject.vector = vector = new DynamicVector(); - } - - var interval = vectorData.interval; - if (defined(interval)) { - interval = TimeInterval.fromIso8601(interval); - } - - if (defined(vectorData.color)) { - var color = vector.color; - if (!defined(color)) { - vector.color = color = new DynamicProperty(CzmlColor); - vectorUpdated = true; - } - color.processCzmlIntervals(vectorData.color, interval); - } - - if (defined(vectorData.width)) { - var width = vector.width; - if (!defined(width)) { - vector.width = width = new DynamicProperty(CzmlNumber); - vectorUpdated = true; - } - width.processCzmlIntervals(vectorData.width, interval); - } - - if (defined(vectorData.direction)) { - var direction = vector.direction; - if (!defined(direction)) { - vector.direction = direction = new DynamicProperty(CzmlDirection); - vectorUpdated = true; - } - direction.processCzmlIntervals(vectorData.direction, interval); - } - - if (defined(vectorData.length)) { - var length = vector.length; - if (!defined(length)) { - vector.length = length = new DynamicProperty(CzmlNumber); - vectorUpdated = true; - } - length.processCzmlIntervals(vectorData.length, interval); - } - - if (defined(vectorData.show)) { - var show = vector.show; - if (!defined(show)) { - vector.show = show = new DynamicProperty(CzmlBoolean); - vectorUpdated = true; - } - show.processCzmlIntervals(vectorData.show, interval); - } - return vectorUpdated; - }; - /** * Given two DynamicObjects, takes the vector properties from the second * and assigns them to the first, assuming such a property did not already exist. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it. * @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged. - * - * @see CzmlDefaults */ DynamicVector.mergeProperties = function(targetObject, objectToMerge) { var vectorToMerge = objectToMerge.vector; @@ -176,12 +66,8 @@ function( /** * Given a DynamicObject, undefines the vector associated with it. - * This method is not normally called directly, but is part of the array of CZML processing - * functions that is passed into the CompositeDynamicObjectCollection constructor. * * @param {DynamicObject} dynamicObject The DynamicObject to remove the vector from. - * - * @see CzmlDefaults */ DynamicVector.undefineProperties = function(dynamicObject) { dynamicObject.vector = undefined; diff --git a/Source/DynamicScene/DynamicVectorVisualizer.js b/Source/DynamicScene/DynamicVectorVisualizer.js index 954e8d80fb87..a0322ccff2e4 100644 --- a/Source/DynamicScene/DynamicVectorVisualizer.js +++ b/Source/DynamicScene/DynamicVectorVisualizer.js @@ -227,7 +227,7 @@ define([ polyline.setShow(true); var positions = polyline._visualizerPositions; - var position = positionProperty.getValueCartesian(time, positions[0]); + var position = positionProperty.getValue(time, positions[0]); var direction = directionProperty.getValue(time, positions[1]); var length = lengthProperty.getValue(time); if (defined(position) && defined(direction) && defined(length)) { diff --git a/Source/DynamicScene/DynamicVertexPositionsProperty.js b/Source/DynamicScene/DynamicVertexPositionsProperty.js index ba23a4cf70dc..aa00b6be88ee 100644 --- a/Source/DynamicScene/DynamicVertexPositionsProperty.js +++ b/Source/DynamicScene/DynamicVertexPositionsProperty.js @@ -49,14 +49,7 @@ define([ } } - ValueHolder.prototype.getValueCartographic = function() { - if (!defined(this.cartographic)) { - this.cartographic = wgs84.cartesianArrayToCartographicArray(this.cartesian); - } - return this.cartographic; - }; - - ValueHolder.prototype.getValueCartesian = function() { + ValueHolder.prototype.getValue = function() { if (!defined(this.cartesian)) { this.cartesian = wgs84.cartographicArrayToCartesianArray(this.cartographic); } @@ -64,36 +57,12 @@ define([ }; /** - * A dynamic property which maintains an array of positions that can change over time. - * The positions can be represented as both Cartesian and Cartographic coordinates. - * Rather than creating instances of this object directly, it's typically - * created and managed via loading CZML data into a DynamicObjectCollection. - * Instances of this type are exposed via DynamicObject and it's sub-objects - * and are responsible for interpreting and interpolating the data for visualization. - * - * @alias DynamicVertexPositionsProperty - * @internalconstructor - * - * @see DynamicObject - * @see DynamicProperty - * @see ReferenceProperty - * @see DynamicMaterialProperty - * @see DynamicPositionProperty - * @see DynamicDirectionsProperty + * @private */ var DynamicVertexPositionsProperty = function() { this._propertyIntervals = new TimeIntervalCollection(); }; - /** - * Processes the provided CZML interval or intervals into this property. - * - * @memberof DynamicVertexPositionsProperty - * - * @param {Object} czmlIntervals The CZML data to process. - * @param {TimeInterval} [constrainedInterval] Constrains the processing so that any times outside of this interval are ignored. - * @param {DynamicObjectCollection} dynamicObjectCollection The DynamicObjectCollection to be used as a target for resolving links within this property. - */ DynamicVertexPositionsProperty.prototype.processCzmlIntervals = function(czmlIntervals, constrainedInterval, dynamicObjectCollection) { if (Array.isArray(czmlIntervals)) { for ( var i = 0, len = czmlIntervals.length; i < len; i++) { @@ -104,42 +73,7 @@ define([ } }; - /** - * Retrieves the values at the supplied time as Cartographic coordinates. - * @memberof DynamicVertexPositionsProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @returns An array of Cartographic coordinates for the provided time. - */ - DynamicVertexPositionsProperty.prototype.getValueCartographic = function(time) { - var interval = this._propertyIntervals.findIntervalContainingDate(time); - if (!defined(interval)) { - return undefined; - } - var interval_data = interval.data; - if (Array.isArray(interval_data)) { - var result = []; - for ( var i = 0, len = interval_data.length; i < len; i++) { - var value = interval_data[i].getValueCartographic(time); - if (defined(value)) { - result.push(value); - } - } - return result; - } - - return interval_data.getValueCartographic(); - - }; - - /** - * Retrieves the values at the supplied time as Cartesian coordinates. - * @memberof DynamicVertexPositionsProperty - * - * @param {JulianDate} time The time for which to retrieve the value. - * @returns An array of Cartesian coordinates for the provided time. - */ - DynamicVertexPositionsProperty.prototype.getValueCartesian = function(time) { + DynamicVertexPositionsProperty.prototype.getValue = function(time) { var interval = this._propertyIntervals.findIntervalContainingDate(time); if (!defined(interval)) { return undefined; @@ -148,7 +82,7 @@ define([ if (Array.isArray(interval_data)) { var result = []; for ( var i = 0, len = interval_data.length; i < len; i++) { - var value = interval_data[i].getValueCartesian(time); + var value = interval_data[i].getValue(time); if (defined(value)) { result.push(value); } @@ -156,7 +90,7 @@ define([ return result; } - return interval_data.getValueCartesian(); + return interval_data.getValue(); }; DynamicVertexPositionsProperty.prototype._addCzmlInterval = function(czmlInterval, constrainedInterval, dynamicObjectCollection) { @@ -194,4 +128,4 @@ define([ }; return DynamicVertexPositionsProperty; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/GeoJsonDataSource.js b/Source/DynamicScene/GeoJsonDataSource.js index 63b5e2c512ca..8330ad0873c5 100644 --- a/Source/DynamicScene/GeoJsonDataSource.js +++ b/Source/DynamicScene/GeoJsonDataSource.js @@ -4,7 +4,6 @@ define([ '../Core/Cartographic', '../Core/Color', '../Core/defined', - '../Core/defineProperties', '../Core/DeveloperError', '../Core/RuntimeError', '../Core/Ellipsoid', @@ -15,7 +14,7 @@ define([ './DynamicPoint', './DynamicPolyline', './DynamicPolygon', - './DynamicMaterialProperty', + './ColorMaterialProperty', './DynamicObjectCollection', '../ThirdParty/when', '../ThirdParty/topojson' @@ -24,7 +23,6 @@ define([ Cartographic, Color, defined, - defineProperties, DeveloperError, RuntimeError, Ellipsoid, @@ -35,27 +33,12 @@ define([ DynamicPoint, DynamicPolyline, DynamicPolygon, - DynamicMaterialProperty, + ColorMaterialProperty, DynamicObjectCollection, when, topojson) { "use strict"; - //DynamicPositionProperty is pretty hard to use with non-CZML based data - //For now we create two of our own properties for exposing GeoJSON - //data. - var ConstantPositionProperty = function(value) { - this._value = value; - }; - - ConstantPositionProperty.prototype.getValueCartesian = function(time, result) { - var value = this._value; - if (typeof value.clone === 'function') { - return value.clone(result); - } - return value; - }; - //GeoJSON specifies only the Feature object has a usable id property //But since "multi" geometries create multiple dynamicObject, //we can't use it for them either. @@ -127,7 +110,7 @@ define([ function processPoint(dataSource, geoJson, geometry, crsFunction, source) { var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultPoint); - dynamicObject.position = new ConstantPositionProperty(crsFunction(geometry.coordinates)); + dynamicObject.position = new ConstantProperty(crsFunction(geometry.coordinates)); } function processMultiPoint(dataSource, geoJson, geometry, crsFunction, source) { @@ -135,14 +118,14 @@ define([ for ( var i = 0; i < coordinates.length; i++) { var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultPoint); - dynamicObject.position = new ConstantPositionProperty(crsFunction(coordinates[i])); + dynamicObject.position = new ConstantProperty(crsFunction(coordinates[i])); } } function processLineString(dataSource, geoJson, geometry, crsFunction, source) { var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultLine); - dynamicObject.vertexPositions = new ConstantPositionProperty(coordinatesArrayToCartesianArray(geometry.coordinates, crsFunction)); + dynamicObject.vertexPositions = new ConstantProperty(coordinatesArrayToCartesianArray(geometry.coordinates, crsFunction)); } function processMultiLineString(dataSource, geoJson, geometry, crsFunction, source) { @@ -150,7 +133,7 @@ define([ for ( var i = 0; i < lineStrings.length; i++) { var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultLine); - dynamicObject.vertexPositions = new ConstantPositionProperty(coordinatesArrayToCartesianArray(lineStrings[i], crsFunction)); + dynamicObject.vertexPositions = new ConstantProperty(coordinatesArrayToCartesianArray(lineStrings[i], crsFunction)); } } @@ -158,7 +141,7 @@ define([ //TODO Holes var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultPolygon); - dynamicObject.vertexPositions = new ConstantPositionProperty(coordinatesArrayToCartesianArray(geometry.coordinates[0], crsFunction)); + dynamicObject.vertexPositions = new ConstantProperty(coordinatesArrayToCartesianArray(geometry.coordinates[0], crsFunction)); } function processTopology(dataSource, geoJson, geometry, crsFunction, source) { @@ -178,7 +161,7 @@ define([ var polygon = polygons[i]; var dynamicObject = createObject(geoJson, dataSource._dynamicObjectCollection); dynamicObject.merge(dataSource.defaultPolygon); - dynamicObject.vertexPositions = new ConstantPositionProperty(coordinatesArrayToCartesianArray(polygon[0], crsFunction)); + dynamicObject.vertexPositions = new ConstantProperty(coordinatesArrayToCartesianArray(polygon[0], crsFunction)); } } @@ -247,24 +230,21 @@ define([ //default polygon var defaultPolygon = new DynamicObject('GeoJsonDataSource.defaultPolygon'); - var polygonMaterial = new DynamicMaterialProperty(); + polyline = new DynamicPolyline(); polyline.color = new ConstantProperty(Color.YELLOW); polyline.width = new ConstantProperty(1); polyline.outlineColor = new ConstantProperty(Color.BLACK); polyline.outlineWidth = new ConstantProperty(0); defaultPolygon.polyline = polyline; + var polygon = new DynamicPolygon(); - polygon.material = polygonMaterial; - polygonMaterial.processCzmlIntervals({ - solidColor : { - color : { - rgba : [255, 255, 0, 25] - } - } - }, undefined, undefined); defaultPolygon.polygon = polygon; + var material = new ColorMaterialProperty(); + material.color = new ConstantProperty(new Color(1.0, 1.0, 0.0, 0.1)); + polygon.material = material; + this._changed = new Event(); this._error = new Event(); this._dynamicObjectCollection = new DynamicObjectCollection(); diff --git a/Source/DynamicScene/GridMaterialProperty.js b/Source/DynamicScene/GridMaterialProperty.js new file mode 100644 index 000000000000..6ff25de7bcf8 --- /dev/null +++ b/Source/DynamicScene/GridMaterialProperty.js @@ -0,0 +1,82 @@ +/*global define*/ +define([ + '../Core/Cartesian2', + '../Core/Color', + '../Core/defined', + './ConstantProperty' + ], function( + Cartesian2, + Color, + defined, + ConstantProperty) { + "use strict"; + + /** + * A {@link MaterialProperty} that maps to grid {@link Material} uniforms. + * @alias GridMaterialProperty + * @constructor + */ + var GridMaterialProperty = function() { + /** + * A {@link Color} {@link Property} which determines the grid's color. + * @type {Property} + * @default new ConstantProperty(Color.WHITE) + */ + this.color = new ConstantProperty(Color.WHITE); + + /** + * A numeric {@link Property} which determines the grid cells alpha value, when combined with the color alpha. + * @type {Property} + * @default new ConstantProperty(0.1) + */ + this.cellAlpha = new ConstantProperty(0.1); + + /** + * A {@link Cartesian2} {@link Property} which determines the number of rows and columns in the grid. + * @type {Property} + * @default new ConstantProperty(new Cartesian2(8, 8)) + */ + this.lineCount = new ConstantProperty(new Cartesian2(8, 8)); + + /** + * A {@link Cartesian2} {@link Property} which determines the thickness of rows and columns in the grid. + * @type {Property} + * @default new ConstantProperty(new Cartesian2(1.0, 1.0)) + */ + this.lineThickness = new ConstantProperty(new Cartesian2(1.0, 1.0)); + }; + + /** + * Gets the {@link Material} type at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the type. + * @type {String} The type of material. + */ + GridMaterialProperty.prototype.getType = function(time) { + return 'Grid'; + }; + + /** + * Gets the value of the property at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + GridMaterialProperty.prototype.getValue = function(time, result) { + if (!defined(result)) { + result = {}; + } + result.color = defined(this.color) ? this.color.getValue(time, result.color) : undefined; + result.cellAlpha = defined(this.cellAlpha) ? this.cellAlpha.getValue(time) : undefined; + result.lineCount = defined(this.lineCount) ? this.lineCount.getValue(time, result.lineCount) : undefined; + result.lineThickness = defined(this.lineThickness) ? this.lineThickness.getValue(time, result.lineThickness) : undefined; + return result; + }; + + return GridMaterialProperty; +}); diff --git a/Source/DynamicScene/ImageMaterialProperty.js b/Source/DynamicScene/ImageMaterialProperty.js new file mode 100644 index 000000000000..4f38d40fdd28 --- /dev/null +++ b/Source/DynamicScene/ImageMaterialProperty.js @@ -0,0 +1,63 @@ +/*global define*/ +define([ + '../Core/Cartesian2', + '../Core/defined', + './ConstantProperty' + ], function( + Cartesian2, + defined, + ConstantProperty) { + "use strict"; + + /** + * A {@link MaterialProperty} that maps to image {@link Material} uniforms. + * @alias ImageMaterialProperty + * @constructor + */ + var ImageMaterialProperty = function() { + /** + * A string {@link Property} which is the url of the desired image. + * @type {Property} + */ + this.image = undefined; + /** + * A {@link Cartesian2} {@link Property} which determines the number of times the image repeats in each direction. + * @type {Property} + * @default new ConstantProperty(new Cartesian2(1, 1)) + */ + this.repeat = new ConstantProperty(new Cartesian2(1, 1)); + }; + + /** + * Gets the {@link Material} type at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the type. + * @type {String} The type of material. + */ + ImageMaterialProperty.prototype.getType = function(time) { + return 'Image'; + }; + + /** + * Gets the value of the property at the provided time. + * @memberof MaterialProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + ImageMaterialProperty.prototype.getValue = function(time, result) { + if (!defined(result)) { + result = {}; + } + + result.image = defined(this.image) ? this.image.getValue(time) : undefined; + result.repeat = defined(this.repeat) ? this.repeat.getValue(time, result.repeat) : undefined; + return result; + }; + + return ImageMaterialProperty; +}); diff --git a/Source/DynamicScene/MaterialProperty.js b/Source/DynamicScene/MaterialProperty.js new file mode 100644 index 000000000000..5868ec014fd4 --- /dev/null +++ b/Source/DynamicScene/MaterialProperty.js @@ -0,0 +1,68 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/DeveloperError', + '../Scene/Material' + ], function( + defined, + DeveloperError, + Material) { + "use strict"; + + function throwInstantiationError() { + throw new DeveloperError('This type should not be instantiated directly.'); + } + + /** + * The interface for all {@link Property} objects that represent {@link Material} uniforms. + * This type defines an interface and cannot be instantiated directly. + * + * @alias MaterialProperty + * @constructor + * + * @see ColorMaterialProperty + * @see CompositeMaterialProperty + * @see GridMaterialProperty + * @see ImageMaterialProperty + */ + var MaterialProperty = throwInstantiationError; + + /** + * Gets the {@link Material} type at the provided time. + * @memberof MaterialProperty + * @function + * + * @param {JulianDate} time The time for which to retrieve the type. + * @type {String} The type of material. + */ + MaterialProperty.prototype.getType = throwInstantiationError; + + /** + * Gets the value of the property at the provided time. + * @memberof MaterialProperty + * @function + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + MaterialProperty.prototype.getValue = throwInstantiationError; + + /** + * @private + */ + MaterialProperty.getValue = function(time, context, materialProperty, material) { + if (defined(materialProperty)) { + var type = materialProperty.getType(time); + if (!defined(material) || (material.type !== type)) { + material = Material.fromType(context, type); + } + materialProperty.getValue(time, material.uniforms); + } + return material; + }; + + return MaterialProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/PositionProperty.js b/Source/DynamicScene/PositionProperty.js new file mode 100644 index 000000000000..e0a48c14feb5 --- /dev/null +++ b/Source/DynamicScene/PositionProperty.js @@ -0,0 +1,102 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/Matrix3', + '../Core/ReferenceFrame', + '../Core/Transforms' + ], function( + Cartesian3, + defined, + defineProperties, + DeveloperError, + Matrix3, + ReferenceFrame, + Transforms) { + "use strict"; + + function throwInstantiationError() { + throw new DeveloperError('This type should not be instantiated directly.'); + } + + /** + * The interface for all position {@link Property} objects. Position properties + * represent a world location as a {@link Cartesian3} with an associated + * {@link ReferenceFrame}. + * This type defines an interface and cannot be instantiated directly. + * + * @alias PositionProperty + * @constructor + * + * @see CompositePositionProperty + * @see ConstantPositionProperty + * @see SampledPositionProperty + * @see TimeIntervalCollectionPositionProperty + */ + var PositionProperty = throwInstantiationError; + + defineProperties(PositionProperty.prototype, { + /** + * Gets the reference frame that the position is defined in. + * @memberof PositionProperty.prototype + * @Type {ReferenceFrame} + */ + referenceFrame : { + get : throwInstantiationError + } + }); + + /** + * Gets the value of the property at the provided time. + * @memberof PositionProperty + * @function + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + PositionProperty.prototype.getValue = throwInstantiationError; + + /** + * Gets the value of the property at the provided time and in the provided reference frame. + * @memberof PositionProperty + * @function + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} referenceFrame is required. + */ + PositionProperty.prototype.getValueInReferenceFrame = throwInstantiationError; + + var scratchMatrix3 = new Matrix3(); + + /** + * @private + */ + PositionProperty.convertToReferenceFrame = function(time, value, inputFrame, outputFrame, result) { + if (inputFrame === outputFrame) { + return Cartesian3.clone(value, result); + } + + var icrfToFixed = Transforms.computeIcrfToFixedMatrix(time, scratchMatrix3); + if (!defined(icrfToFixed)) { + icrfToFixed = Transforms.computeTemeToPseudoFixedMatrix(time, scratchMatrix3); + } + if (inputFrame === ReferenceFrame.INERTIAL) { + return icrfToFixed.multiplyByVector(value, result); + } + if (inputFrame === ReferenceFrame.FIXED) { + return icrfToFixed.transpose(scratchMatrix3).multiplyByVector(value, result); + } + }; + + return PositionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/Property.js b/Source/DynamicScene/Property.js new file mode 100644 index 000000000000..468aee688659 --- /dev/null +++ b/Source/DynamicScene/Property.js @@ -0,0 +1,44 @@ +/*global define*/ +define([ + '../Core/DeveloperError' + ], function( + DeveloperError) { + "use strict"; + + function throwInstantiationError() { + throw new DeveloperError('This type should not be instantiated directly.'); + } + + /** + * The interface for all properties, which represent a value that can + * optionally vary over time. + * This type defines an interface and cannot be instantiated directly. + * + * @alias Property + * @constructor + * + * @see CompositeProperty + * @see ConstantProperty + * @see SampledProperty + * @see TimeIntervalCollectionProperty + * @see MaterialProperty + * @see PositionProperty + * @see RefereenceProperty + */ + var Property = throwInstantiationError; + + /** + * Gets the value of the property at the provided time. + * @memberof Property + * @function + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + Property.prototype.getValue = throwInstantiationError; + + return Property; +}); \ No newline at end of file diff --git a/Source/DynamicScene/ReferenceProperty.js b/Source/DynamicScene/ReferenceProperty.js index 4c8abf241b2c..3acd040cf363 100644 --- a/Source/DynamicScene/ReferenceProperty.js +++ b/Source/DynamicScene/ReferenceProperty.js @@ -24,9 +24,7 @@ define([ } /** - * A dynamic property which transparently links to another property, which may - * or may not exist yet. It is up to the caller to know which kind of property - * is being linked to. + * A {@link Property} which transparently links to another property on a provided object. * * @alias ReferenceProperty * @constructor @@ -38,14 +36,6 @@ define([ * @exception {DeveloperError} dynamicObjectCollection is required. * @exception {DeveloperError} targetObjectId is required. * @exception {DeveloperError} targetPropertyName is required. - * - * @see ReferenceProperty#fromString - * @see DynamicProperty - * @see DynamicPositionProperty - * @see DynamicDirectionsProperty - * @see DynamicVertexPositionsProperty - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection */ var ReferenceProperty = function(dynamicObjectCollection, targetObjectId, targetPropertyName) { if (!defined(dynamicObjectCollection)) { @@ -73,19 +63,11 @@ define([ * @param {DynamicObject} dynamicObjectCollection * @param referenceString * + * @returns A new instance of ReferenceProperty. + * * @exception {DeveloperError} dynamicObjectCollection is required. * @exception {DeveloperError} referenceString is required. - * @exception {DeveloperError} referenceString must contain a single . delineating the target object ID and property name. - * - * @see ReferenceProperty#fromString - * @see DynamicProperty - * @see DynamicPositionProperty - * @see DynamicDirectionsProperty - * @see DynamicVertexPositionsProperty - * @see DynamicObjectCollection - * @see CompositeDynamicObjectCollection - * - * @returns A new instance of ReferenceProperty. + * @exception {DeveloperError} referenceString must contain a single period delineating the target object ID and property name. */ ReferenceProperty.fromString = function(dynamicObjectCollection, referenceString) { if (!defined(dynamicObjectCollection)) { @@ -105,55 +87,24 @@ define([ }; /** - * Retrieves the value of the property at the specified time. + * Gets the value of the property at the provided time. + * @memberof ReferenceProperty * - * @param time The time to evaluate the property. - * @param [result] The object to store the result in, if undefined a new instance will be created. - * @returns The result parameter or a new instance if the parameter was omitted. - */ - ReferenceProperty.prototype.getValue = function(time, result) { - var targetProperty = resolve(this); - return defined(targetProperty) && this._targetObject.isAvailable(time) ? targetProperty.getValue(time, result) : undefined; - }; - - /** - * Retrieves the Cartographic value or values of the property at the specified time if the linked property - * is a DynamicPositionProperty or DynamicVertexPositionsProperty. + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. * - * @param time The time to evaluate the property. - * @param [result] The object to store the result in, if undefined a new instance will be created. - * @returns The result parameter or a new instance if the parameter was omitted. - */ - ReferenceProperty.prototype.getValueCartographic = function(time, result) { - var targetProperty = resolve(this); - return defined(targetProperty) && this._targetObject.isAvailable(time) ? targetProperty.getValueCartographic(time, result) : undefined; - }; - - /** - * Retrieves the Cartesian value or values of the property at the specified time if the linked property - * is a DynamicPositionProperty, DynamicVertexPositionsProperty, or DynamicDirectionsProperty. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. * - * @param time The time to evaluate the property. - * @param [result] The object to store the result in, if undefined a new instance will be created. - * @returns The result parameter or a new instance if the parameter was omitted. + * @exception {DeveloperError} time is required. */ - ReferenceProperty.prototype.getValueCartesian = function(time, result) { - var targetProperty = resolve(this); - return defined(targetProperty) && this._targetObject.isAvailable(time) ? targetProperty.getValueCartesian(time, result) : undefined; - }; + ReferenceProperty.prototype.getValue = function(time, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } - /** - * Retrieves the Spherical value or values of the property at the specified time if the linked property - * is a DynamicDirectionsProperty. - * - * @param time The time to evaluate the property. - * @param [result] The object to store the result in, if undefined a new instance will be created. - * @returns The result parameter or a new instance if the parameter was omitted. - */ - ReferenceProperty.prototype.getValueSpherical = function(time, result) { var targetProperty = resolve(this); - return defined(targetProperty) && this._targetObject.isAvailable(time) ? targetProperty.getValueSpherical(time, result) : undefined; + return defined(targetProperty) && this._targetObject.isAvailable(time) ? targetProperty.getValue(time, result) : undefined; }; return ReferenceProperty; -}); \ No newline at end of file +}); diff --git a/Source/DynamicScene/SampledPositionProperty.js b/Source/DynamicScene/SampledPositionProperty.js new file mode 100644 index 000000000000..048ab08fac44 --- /dev/null +++ b/Source/DynamicScene/SampledPositionProperty.js @@ -0,0 +1,163 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/ReferenceFrame', + './PositionProperty', + './SampledProperty' + ], function( + Cartesian3, + defaultValue, + defined, + defineProperties, + DeveloperError, + ReferenceFrame, + PositionProperty, + SampledProperty) { + "use strict"; + + /** + * A {@link SampledProperty} which is also a {@link PositionProperty}. + * + * @alias SampledPositionProperty + * @constructor + * + * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined. + */ + var SampledPositionProperty = function(referenceFrame) { + this._property = new SampledProperty(Cartesian3); + this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + }; + + defineProperties(SampledPositionProperty.prototype, { + /** + * Gets the reference frame in which the position is defined. + * @memberof SampledPositionProperty.prototype + * @Type {ReferenceFrame} + * @default ReferenceFrame.FIXED; + */ + referenceFrame : { + get : function() { + return this._referenceFrame; + } + }, + /** + * Gets or sets the degree of interpolation to perform when retrieving a value. + * @memberof SampledPositionProperty.prototype + * + * @type {Object} + * @default 1 + */ + interpolationDegree : { + get : function() { + return this._property.interpolationDegree; + }, + set : function(value) { + this._property.interpolationDegree = value; + } + }, + /** + * Gets or sets the interpolation algorithm to use when retrieving a value. + * @memberof SampledPositionProperty.prototype + * + * @type {InterpolationAlgorithm} + * @default LinearApproximation + */ + interpolationAlgorithm : { + get : function() { + return this._property.interpolationAlgorithm; + }, + set : function(value) { + this._property.interpolationAlgorithm = value; + } + } + }); + + /** + * Gets the value of the property at the provided time. + * @memberof SampledPositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + SampledPositionProperty.prototype.getValue = function(time, result) { + return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result); + }; + + /** + * Gets the value of the property at the provided time and in the provided reference frame. + * @memberof SampledPositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} referenceFrame is required. + */ + SampledPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + if (!defined(referenceFrame)) { + throw new DeveloperError('referenceFrame is required.'); + } + + result = this._property.getValue(time, result); + if (defined(result)) { + return PositionProperty.convertToReferenceFrame(time, result, this._referenceFrame, referenceFrame, result); + } + return result; + }; + + /** + * Adds a new sample + * @memberof SampledPositionProperty + * + * @param {JulianDate} time The sample time. + * @param {Cartesian3} value The value at the provided time. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} value is required. + */ + SampledPositionProperty.prototype.addSample = function(time, value) { + this._property.addSample(time, value); + }; + + /** + * Adds an array of samples + * @memberof SampledPositionProperty + * + * @param {Array} times An array of JulianDate instances where each index is a sample time. + * @param {Array} values The array of Cartesian3 instances, where each value corresponds to the provided times index. + * + * @exception {DeveloperError} times is required. + * @exception {DeveloperError} values is required. + * @exception {DeveloperError} times and values must be the same length.. + */ + SampledPositionProperty.prototype.addSamples = function(times, values) { + this._property.addSamples(times, values); + }; + + /** + * Adds samples as a single packed array where each new sample is represented as a date, followed by the packed representation of the corresponding value. + * @memberof SampledPositionProperty + * + * @param {Array} packedSamples The array of packed samples. + * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds. + * + * @exception {DeveloperError} packedSamples is required. + */ + SampledPositionProperty.prototype.addSamplesPackedArray = function(data, epoch) { + this._property.addSamplesPackedArray(data, epoch); + }; + + return SampledPositionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/SampledProperty.js b/Source/DynamicScene/SampledProperty.js new file mode 100644 index 000000000000..9119173f9251 --- /dev/null +++ b/Source/DynamicScene/SampledProperty.js @@ -0,0 +1,408 @@ +/*global define*/ +define([ + '../Core/binarySearch', + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/JulianDate', + '../Core/LinearApproximation' + ], function( + binarySearch, + defaultValue, + defined, + defineProperties, + DeveloperError, + JulianDate, + LinearApproximation) { + "use strict"; + + var PackableNumber = { + packedLength : 1, + pack : function(value, array, startingIndex) { + startingIndex = defaultValue(startingIndex, 0); + array[startingIndex] = value; + }, + unpack : function(array, startingIndex, result) { + startingIndex = defaultValue(startingIndex, 0); + return array[startingIndex]; + } + }; + + //We can't use splice for inserting new elements because function apply can't handle + //a huge number of arguments. See https://code.google.com/p/chromium/issues/detail?id=56588 + function arrayInsert(array, startIndex, items) { + var i; + var arrayLength = array.length; + var itemsLength = items.length; + var newLength = arrayLength + itemsLength; + + array.length = newLength; + if (arrayLength !== startIndex) { + var q = arrayLength - 1; + for (i = newLength - 1; i >= startIndex; i--) { + array[i] = array[q--]; + } + } + + for (i = 0; i < itemsLength; i++) { + array[startIndex++] = items[i]; + } + } + + function convertDate(date, epoch) { + if (date instanceof JulianDate) { + return date; + } + if (typeof date === 'string') { + return JulianDate.fromIso8601(date); + } + return epoch.addSeconds(date); + } + + var mergeNewSamples = function(epoch, times, values, newData, packedLength) { + var newDataIndex = 0; + var i; + var prevItem; + var timesInsertionPoint; + var valuesInsertionPoint; + var timesSpliceArgs; + var valuesSpliceArgs; + var currentTime; + var nextTime; + + while (newDataIndex < newData.length) { + currentTime = convertDate(newData[newDataIndex], epoch); + timesInsertionPoint = binarySearch(times, currentTime, JulianDate.compare); + + if (timesInsertionPoint < 0) { + //Doesn't exist, insert as many additional values as we can. + timesInsertionPoint = ~timesInsertionPoint; + timesSpliceArgs = []; + + valuesInsertionPoint = timesInsertionPoint * packedLength; + valuesSpliceArgs = []; + prevItem = undefined; + nextTime = times[timesInsertionPoint]; + while (newDataIndex < newData.length) { + currentTime = convertDate(newData[newDataIndex], epoch); + if ((defined(prevItem) && JulianDate.compare(prevItem, currentTime) >= 0) || (defined(nextTime) && JulianDate.compare(currentTime, nextTime) >= 0)) { + break; + } + timesSpliceArgs.push(currentTime); + newDataIndex = newDataIndex + 1; + for (i = 0; i < packedLength; i++) { + valuesSpliceArgs.push(newData[newDataIndex]); + newDataIndex = newDataIndex + 1; + } + prevItem = currentTime; + } + + arrayInsert(values, valuesInsertionPoint, valuesSpliceArgs); + arrayInsert(times, timesInsertionPoint, timesSpliceArgs); + } else { + //Found an exact match + for (i = 0; i < packedLength; i++) { + newDataIndex++; + values[(timesInsertionPoint * packedLength) + i] = newData[newDataIndex]; + } + newDataIndex++; + } + } + }; + + /** + * A {@link Property} whose value is interpolated for a given time from the + * provided set of samples and specified interpolation algorithm and degree. + * @alias SampledProperty + * @constructor + * + * @param {Object} type The type of property, which must be Number, String or implement {@link Packable}. + * + * @exception {DeveloperError} type is required. + * + * @see SampledPositionProperty + * + * @example + * //Create a linearly interpolated Cartesian2 + * var property = new SampledProperty(Cartesian2); + * property.interpolationDegree = 1; + * property.interpolationAlgorithm = LinearApproximation; + * + * //Populate it with data + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:00:00.00Z`), new Cartesian2(0, 0)); + * property.addSample(JulianDate.fromIso8601(`2012-08-02T00:00:00.00Z`), new Cartesian2(4, 7)); + * + * //Retrieve an interpolated value + * var result = property.getValue(JulianDate.fromIso8601(`2012-08-01T12:00:00.00Z`)); + * + * @example + * //Create a simple numeric SampledProperty that uses third degree Hermite Polynomial Approximation + * var property = new SampledProperty(Number); + * property.interpolationDegree = 3; + * property.interpolationAlgorithm = HermitePolynomialApproximation; + * + * //Populate it with data + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:00:00.00Z`), 1.0); + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:01:00.00Z`), 6.0); + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:02:00.00Z`), 12.0); + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:03:30.00Z`), 5.0); + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:06:30.00Z`), 2.0); + * + * //Samples can be added in any order. + * property.addSample(JulianDate.fromIso8601(`2012-08-01T00:00:30.00Z`), 6.2); + * + * //Retrieve an interpolated value + * var result = property.getValue(JulianDate.fromIso8601(`2012-08-01T00:02:34.00Z`)); + */ + var SampledProperty = function(type) { + if (!defined(type)) { + throw new DeveloperError('type is required.'); + } + + var innerType = type; + if (innerType === Number) { + innerType = PackableNumber; + } + + var packedInterpolationLength = defaultValue(innerType.packedInterpolationLength, innerType.packedLength); + + this._type = type; + this._innerType = innerType; + this._interpolationDegree = 1; + this._interpolationAlgorithm = LinearApproximation; + this._numberOfPoints = 0; + this._times = []; + this._values = []; + this._xTable = []; + this._yTable = []; + this._packedInterpolationLength = packedInterpolationLength; + this._updateTableLength = true; + this._interpolationResult = new Array(packedInterpolationLength); + }; + + defineProperties(SampledProperty.prototype, { + /** + * Gets the type of property. + * @memberof SampledProperty.prototype + * @type {Object} + */ + type : { + get : function() { + return this._type; + } + }, + /** + * Gets or sets the degree of interpolation to perform when retrieving a value. + * @memberof SampledProperty.prototype + * @type {Object} + * @default 1 + */ + interpolationDegree : { + get : function() { + return this._interpolationDegree; + }, + set : function(value) { + this._interpolationDegree = value; + this._updateTableLength = true; + } + }, + /** + * Gets or sets the interpolation algorithm to use when retrieving a value. + * @memberof SampledProperty.prototype + * @type {InterpolationAlgorithm} + * @default LinearApproximation + */ + interpolationAlgorithm : { + get : function() { + return this._interpolationAlgorithm; + }, + set : function(value) { + this._interpolationAlgorithm = value; + this._updateTableLength = true; + } + } + }); + + /** + * Gets the value of the property at the provided time. + * @memberof SampledProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + SampledProperty.prototype.getValue = function(time, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + + var innerType = this._innerType; + var times = this._times; + var values = this._values; + var index = binarySearch(times, time, JulianDate.compare); + if (index < 0) { + var xTable = this._xTable; + var yTable = this._yTable; + var interpolationAlgorithm = this._interpolationAlgorithm; + var packedInterpolationLength = this._packedInterpolationLength; + + if (this._updateTableLength) { + this._updateTableLength = false; + var numberOfPoints = Math.min(interpolationAlgorithm.getRequiredDataPoints(this._interpolationDegree), times.length); + if (numberOfPoints !== this._numberOfPoints) { + this._numberOfPoints = numberOfPoints; + xTable.length = numberOfPoints; + yTable.length = numberOfPoints * packedInterpolationLength; + } + } + + var degree = this._numberOfPoints - 1; + if (degree < 1) { + return undefined; + } + index = ~index; + + if (index >= times.length) { + index = times.length - 1; + } + + var firstIndex = 0; + var lastIndex = times.length - 1; + var pointsInCollection = lastIndex - firstIndex + 1; + + if (pointsInCollection < degree + 1) { + // Use the entire range. + } else { + var computedFirstIndex = index - ((degree / 2) | 0) - 1; + if (computedFirstIndex < firstIndex) { + computedFirstIndex = firstIndex; + } + var computedLastIndex = computedFirstIndex + degree; + if (computedLastIndex > lastIndex) { + computedLastIndex = lastIndex; + computedFirstIndex = computedLastIndex - degree; + if (computedFirstIndex < firstIndex) { + computedFirstIndex = firstIndex; + } + } + + firstIndex = computedFirstIndex; + lastIndex = computedLastIndex; + } + var length = lastIndex - firstIndex + 1; + + // Build the tables + for ( var i = 0; i < length; ++i) { + xTable[i] = times[lastIndex].getSecondsDifference(times[firstIndex + i]); + } + + if (!defined(innerType.convertPackedArrayForInterpolation)) { + var destinationIndex = 0; + var packedLength = innerType.packedLength; + var sourceIndex = firstIndex * packedLength; + var stop = (lastIndex + 1) * packedLength; + + while (sourceIndex < stop) { + yTable[destinationIndex] = values[sourceIndex]; + sourceIndex++; + destinationIndex++; + } + } else { + innerType.convertPackedArrayForInterpolation(values, firstIndex, lastIndex, yTable); + } + + // Interpolate! + var x = times[lastIndex].getSecondsDifference(time); + var interpolationResult = interpolationAlgorithm.interpolateOrderZero(x, xTable, yTable, packedInterpolationLength, this._interpolationResult); + + if (!defined(innerType.unpackInterpolationResult)) { + return innerType.unpack(interpolationResult, 0, result); + } + return innerType.unpackInterpolationResult(interpolationResult, values, firstIndex, lastIndex, result); + } + return innerType.unpack(this._values, index * innerType.packedLength, result); + }; + + /** + * Adds a new sample + * @memberof SampledProperty + * + * @param {JulianDate} time The sample time. + * @param {Object} value The value at the provided time. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} value is required. + */ + SampledProperty.prototype.addSample = function(time, value) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + if (!defined(value)) { + throw new DeveloperError('value is required.'); + } + + var innerType = this._innerType; + var data = [time]; + innerType.pack(value, data, 1); + mergeNewSamples(undefined, this._times, this._values, data, innerType.packedLength); + this._updateTableLength = true; + }; + + /** + * Adds an array of samples + * @memberof SampledProperty + * + * @param {Array} times An array of JulianDate instances where each index is a sample time. + * @param {Array} values The array of values, where each value corresponds to the provided times index. + * + * @exception {DeveloperError} times is required. + * @exception {DeveloperError} values is required. + * @exception {DeveloperError} times and values must be the same length.. + */ + SampledProperty.prototype.addSamples = function(times, values) { + if (!defined(times)) { + throw new DeveloperError('times is required.'); + } + if (!defined(values)) { + throw new DeveloperError('values is required.'); + } + if (times.length !== values.length) { + throw new DeveloperError('times and values must be the same length.'); + } + + var innerType = this._innerType; + var length = times.length; + var data = []; + for ( var i = 0; i < length; i++) { + data.push(times[i]); + innerType.pack(values[i], data, data.length); + } + mergeNewSamples(undefined, this._times, this._values, data, innerType.packedLength); + this._updateTableLength = true; + }; + + /** + * Adds samples as a single packed array where each new sample is represented as a date, followed by the packed representation of the corresponding value. + * @memberof SampledProperty + * + * @param {Array} packedSamples The array of packed samples. + * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds. + * + * @exception {DeveloperError} packedSamples is required. + */ + SampledProperty.prototype.addSamplesPackedArray = function(packedSamples, epoch) { + if (!defined(packedSamples)) { + throw new DeveloperError('packedSamples is required.'); + } + mergeNewSamples(epoch, this._times, this._values, packedSamples, this._innerType.packedLength); + this._updateTableLength = true; + }; + + //Exposed for testing. + SampledProperty._mergeNewSamples = mergeNewSamples; + + return SampledProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/TimeIntervalCollectionPositionProperty.js b/Source/DynamicScene/TimeIntervalCollectionPositionProperty.js new file mode 100644 index 000000000000..6ce5ea72d8dc --- /dev/null +++ b/Source/DynamicScene/TimeIntervalCollectionPositionProperty.js @@ -0,0 +1,99 @@ +/*global define*/ +define([ + '../Core/defaultValue', + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/ReferenceFrame', + '../Core/TimeIntervalCollection', + './PositionProperty' + ], function( + defaultValue, + defined, + defineProperties, + DeveloperError, + ReferenceFrame, + TimeIntervalCollection, + PositionProperty) { + "use strict"; + + /** + * A {@link TimeIntervalCollectionProperty} which is also a {@link PositionProperty}. + * + * @alias TimeIntervalCollectionPositionProperty + * @constructor + * + * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined. + */ + var TimeIntervalCollectionPositionProperty = function(referenceFrame) { + this._intervals = new TimeIntervalCollection(); + this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + }; + + defineProperties(TimeIntervalCollectionPositionProperty.prototype, { + /** + * Gets the interval collection. + * @memberof TimeIntervalCollectionPositionProperty.prototype + * @type {TimeIntervalCollection} + */ + intervals : { + get : function() { + return this._intervals; + } + }, + /** + * Gets the reference frame in which the position is defined. + * @memberof TimeIntervalCollectionPositionProperty.prototype + * @Type {ReferenceFrame} + * @default ReferenceFrame.FIXED; + */ + referenceFrame : { + get : function() { + return this._referenceFrame; + } + } + }); + + /** + * Gets the value of the property at the provided time in the fixed frame. + * @memberof CompositePositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + */ + TimeIntervalCollectionPositionProperty.prototype.getValue = function(time, result) { + return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result); + }; + + /** + * Gets the value of the property at the provided time and in the provided reference frame. + * @memberof CompositePositionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result. + * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} referenceFrame is required. + */ + TimeIntervalCollectionPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) { + if (!defined(time)) { + throw new DeveloperError('time is required.'); + } + if (!defined(referenceFrame)) { + throw new DeveloperError('referenceFrame is required.'); + } + + var position = this._intervals.findDataForIntervalContainingDate(time); + if (defined(position)) { + return PositionProperty.convertToReferenceFrame(time, position, this._referenceFrame, referenceFrame, result); + } + return undefined; + }; + + return TimeIntervalCollectionPositionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/TimeIntervalCollectionProperty.js b/Source/DynamicScene/TimeIntervalCollectionProperty.js new file mode 100644 index 000000000000..cc535e363d47 --- /dev/null +++ b/Source/DynamicScene/TimeIntervalCollectionProperty.js @@ -0,0 +1,103 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/defineProperties', + '../Core/DeveloperError', + '../Core/Enumeration', + '../Core/TimeIntervalCollection' + ], function( + defined, + defineProperties, + DeveloperError, + Enumeration, + TimeIntervalCollection) { + "use strict"; + + /** + * A {@link Property} which is defined by a TimeIntervalCollection, where the + * data property of each {@link TimeInterval} represents the value at time. + * + * @alias TimeIntervalCollectionProperty + * @constructor + * + * @param {Function} [clone=value.clone] A function which takes the value and a result parameter and clones it. + * This parameter is only required if the value is not a number or string and does not have a clone function. + * + * @exception {DeveloperError} value is required. + * @exception {DeveloperError} clone is a required function. + * + * @example + * //Create a Cartesian2 interval property which contains data on August 1st, 2012 + * //and uses a different value every 6 hours. + * var composite = new TimeIntervalCollectionProperty(); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T00:00:00.00Z/2012-08-01T06:00:00.00Z', true, false, new Cartesian2(2.0, 3.4))); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T06:00:00.00Z/2012-08-01T12:00:00.00Z', true, false, new Cartesian2(12.0, 2.7))); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T12:00:00.00Z/2012-08-01T18:00:00.00Z', true, false, new Cartesian2(5.0, 12.4))); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T18:00:00.00Z/2012-08-02T00:00:00.00Z', true, true, new Cartesian2(85.0, 4.1))); + * + * @example + * //Create a TimeIntervalCollectionProperty that contains user-defined objects. + * var myObject = { + * value : 6 + * }; + * var myObject2 = { + * value : 12 + * }; + * function cloneMyObject(value, result) { + * return { + * value : value.value + * }; + * } + * var composite = new TimeIntervalCollectionProperty(cloneMyObject); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T00:00:00.00Z/2012-08-01T06:00:00.00Z', true, false, myObject)); + * composite.intervals.addInterval(TimeInterval.fromIso8601('2012-08-01T06:00:00.00Z/2012-08-01T12:00:00.00Z', true, false, myObject2)); + */ + var TimeIntervalCollectionProperty = function(clone) { + this._intervals = new TimeIntervalCollection(); + this._clone = clone; + }; + + defineProperties(TimeIntervalCollectionProperty.prototype, { + /** + * Gets the interval collection. + * @memberof TimeIntervalCollectionProperty.prototype + * + * @type {TimeIntervalCollection} + */ + intervals : { + get : function() { + return this._intervals; + } + } + }); + + /** + * Gets the value of the property at the provided time. + * @memberof TimeIntervalCollectionProperty + * + * @param {JulianDate} time The time for which to retrieve the value. + * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned. + * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied. + * + * @exception {DeveloperError} time is required. + * @exception {DeveloperError} This value requires a clone function be specified for the TimeIntervalCollectionProperty constructor. + */ + TimeIntervalCollectionProperty.prototype.getValue = function(time, result) { + if (!defined(time)) { + throw new DeveloperError('time is required'); + } + + var value = this._intervals.findDataForIntervalContainingDate(time); + if (defined(value) && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Enumeration)) { + if (typeof value.clone === 'function') { + return value.clone(result); + } else if (!defined(this._clone)) { + throw new DeveloperError('This value requires a clone function be specified for the TimeIntervalCollectionProperty constructor.'); + } + return this._clone(value, result); + } + return value; + }; + + return TimeIntervalCollectionProperty; +}); \ No newline at end of file diff --git a/Source/DynamicScene/VisualizerCollection.js b/Source/DynamicScene/VisualizerCollection.js index bcee8440b4d9..e6a9b3ae261d 100644 --- a/Source/DynamicScene/VisualizerCollection.js +++ b/Source/DynamicScene/VisualizerCollection.js @@ -2,15 +2,11 @@ define([ '../Core/defaultValue', '../Core/defined', - '../Core/destroyObject', - '../Core/DeveloperError', - './CzmlDefaults' + '../Core/destroyObject' ], function( defaultValue, defined, - destroyObject, - DeveloperError, - CzmlDefaults) { + destroyObject) { "use strict"; /** @@ -21,8 +17,6 @@ define([ * * @param {Object} The array of visualizers to use. * @param {DynamicObjectCollection} The objects to be visualized. - * - * @see CzmlDefaults#createVisualizers */ var VisualizerCollection = function(visualizers, dynamicObjectCollection) { this._visualizers = defined(visualizers) ? visualizers : []; @@ -30,25 +24,6 @@ define([ this.setDynamicObjectCollection(dynamicObjectCollection); }; - /** - * Creates a new VisualizerCollection which includes all standard visualizers. - * - * @memberof VisualizerCollection - * - * @param {Scene} The scene where visualization will take place. - * @param {DynamicObjectCollection} The objects to be visualized. - * - * @exception {DeveloperError} scene is required. - * - * @see CzmlDefaults#createVisualizers - */ - VisualizerCollection.createCzmlStandardCollection = function(scene, dynamicObjectCollection) { - if (!defined(scene)) { - throw new DeveloperError('scene is required.'); - } - return new VisualizerCollection(CzmlDefaults.createVisualizers(scene), dynamicObjectCollection); - }; - /** * Gets a copy of the array of visualizers in the collection. * @returns {Array} the array of visualizers in the collection. diff --git a/Source/DynamicScene/processCzml.js b/Source/DynamicScene/processCzml.js deleted file mode 100644 index a09956fcc823..000000000000 --- a/Source/DynamicScene/processCzml.js +++ /dev/null @@ -1,83 +0,0 @@ -/*global define*/ -define([ - '../Core/createGuid', - '../Core/defined', - '../Core/DeveloperError', - './CzmlDefaults' - ], function( - createGuid, - defined, - DeveloperError, - CzmlDefaults) { - "use strict"; - - function processCzmlPacket(packet, dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri) { - var objectId = packet.id; - if (!defined(objectId)) { - objectId = createGuid(); - } - - if (packet['delete'] === true) { - dynamicObjectCollection.removeObject(objectId); - } else { - var object = dynamicObjectCollection.getOrCreateObject(objectId); - for ( var i = updaterFunctions.length - 1; i > -1; i--) { - if (updaterFunctions[i](object, packet, dynamicObjectCollection, sourceUri) && !defined(updatedObjectsHash[objectId])) { - updatedObjectsHash[objectId] = true; - updatedObjects.push(object); - } - } - } - } - - /** - * Processes the provided CZML, creating or updating DynamicObject instances for each - * corresponding CZML identifier. - * @exports processCzml - * - * @param {Object} czml The parsed CZML object to be processed. - * @param {DynamicObjectCollection} dynamicObjectCollection The collection to create or updated objects within. - * @param {String} [sourceUri] The uri of the file where the CZML originated from. If provided, relative uri look-ups will use this as their base. - * @param {Array} [updaterFunctions=CzmlDefaults.updaters] The array of updated functions to use for processing. If left undefined, all standard CZML data is processed. - * - * @exception {DeveloperError} czml is required. - * @exception {DeveloperError} dynamicObjectCollection is required. - * - * @returns An array containing all DynamicObject instances that were created or updated. - * - * @example - * var url = 'http://someUrl.com/myCzmlFile.czml'; - * var dynamicObjectCollection = new DynamicObjectCollection(); - * loadJson(url).then(function(czml) { - * processCzml(czml, dynamicObjectCollection, url); - * }); - */ - var processCzml = function(czml, dynamicObjectCollection, sourceUri, updaterFunctions) { - if (!defined(czml)) { - throw new DeveloperError('czml is required.'); - } - if (!defined(dynamicObjectCollection)) { - throw new DeveloperError('dynamicObjectCollection is required.'); - } - - var updatedObjects = []; - var updatedObjectsHash = {}; - updaterFunctions = defined(updaterFunctions) ? updaterFunctions : CzmlDefaults.updaters; - - if (Array.isArray(czml)) { - for ( var i = 0, len = czml.length; i < len; i++) { - processCzmlPacket(czml[i], dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri); - } - } else { - processCzmlPacket(czml, dynamicObjectCollection, updatedObjects, updatedObjectsHash, updaterFunctions, sourceUri); - } - - if (updatedObjects.length > 0) { - dynamicObjectCollection.objectPropertiesChanged.raiseEvent(dynamicObjectCollection, updatedObjects); - } - - return updatedObjects; - }; - - return processCzml; -}); diff --git a/Specs/Core/Cartesian2Spec.js b/Specs/Core/Cartesian2Spec.js index 302c57e27474..019b144580e7 100644 --- a/Specs/Core/Cartesian2Spec.js +++ b/Specs/Core/Cartesian2Spec.js @@ -1,10 +1,12 @@ /*global defineSuite*/ defineSuite([ 'Core/Cartesian2', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( Cartesian2, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -629,4 +631,6 @@ defineSuite([ var expectedResult = new Cartesian2(2, 2); expect(cartesian2).toEqual(expectedResult); }); + + createPackableSpecs(Cartesian2, new Cartesian2(1, 2), [1, 2]); }); diff --git a/Specs/Core/Cartesian3Spec.js b/Specs/Core/Cartesian3Spec.js index baf5b3c74cd9..eeb83d7e3f7e 100644 --- a/Specs/Core/Cartesian3Spec.js +++ b/Specs/Core/Cartesian3Spec.js @@ -1,10 +1,12 @@ /*global defineSuite*/ defineSuite([ 'Core/Cartesian3', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( - Cartesian3, - CesiumMath) { + Cartesian3, + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -713,4 +715,6 @@ defineSuite([ var expectedResult = new Cartesian3(2, 2, 4); expect(cartesian3).toEqual(expectedResult); }); + + createPackableSpecs(Cartesian3, new Cartesian3(1, 2, 3), [1, 2, 3]); }); diff --git a/Specs/Core/Cartesian4Spec.js b/Specs/Core/Cartesian4Spec.js index cabdfc2aa101..2cd4cde011f0 100644 --- a/Specs/Core/Cartesian4Spec.js +++ b/Specs/Core/Cartesian4Spec.js @@ -1,8 +1,10 @@ /*global defineSuite*/ defineSuite([ - 'Core/Cartesian4' + 'Core/Cartesian4', + 'Specs/createPackableSpecs' ], function( - Cartesian4) { + Cartesian4, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -633,4 +635,6 @@ defineSuite([ var expectedResult = new Cartesian4(2, 2, 4, 7); expect(cartesian4).toEqual(expectedResult); }); + + createPackableSpecs(Cartesian4, new Cartesian4(1, 2, 3, 4), [1, 2, 3, 4]); }); diff --git a/Specs/Core/ColorSpec.js b/Specs/Core/ColorSpec.js index 766590051d42..d4d7c71fac75 100644 --- a/Specs/Core/ColorSpec.js +++ b/Specs/Core/ColorSpec.js @@ -1,9 +1,11 @@ /*global defineSuite*/ defineSuite(['Core/Color', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( Color, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -332,4 +334,6 @@ defineSuite(['Core/Color', var newRgba = newColor.toRgba(); expect(rgba).toEqual(newRgba); }); + + createPackableSpecs(Color, new Color(0.1, 0.2, 0.3, 0.4), [0.1, 0.2, 0.3, 0.4]); }); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index fe45b3dc45ff..829ae9cfd13d 100644 --- a/Specs/Core/QuaternionSpec.js +++ b/Specs/Core/QuaternionSpec.js @@ -3,12 +3,14 @@ defineSuite([ 'Core/Quaternion', 'Core/Cartesian3', 'Core/Math', - 'Core/Matrix3' + 'Core/Matrix3', + 'Specs/createPackableSpecs' ], function( Quaternion, Cartesian3, CesiumMath, - Matrix3) { + Matrix3, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -758,5 +760,6 @@ defineSuite([ Quaternion.equalsEpsilon(new Quaternion(), new Quaternion(), undefined); }).toThrow(); }); -}); + createPackableSpecs(Quaternion, new Quaternion(1, 2, 3, 4), [1, 2, 3, 4]); +}); diff --git a/Specs/Core/TimeIntervalCollectionSpec.js b/Specs/Core/TimeIntervalCollectionSpec.js index 298c69ca7744..ceb0b39a6068 100644 --- a/Specs/Core/TimeIntervalCollectionSpec.js +++ b/Specs/Core/TimeIntervalCollectionSpec.js @@ -251,6 +251,23 @@ defineSuite([ expect(intervals.findIntervalContainingDate(interval3.stop).data).toEqual(3); }); + it('findDataForIntervalContainingDate works', function() { + var interval1 = new TimeInterval(JulianDate.fromTotalDays(1), JulianDate.fromTotalDays(2.5), true, true, 1); + var interval2 = new TimeInterval(JulianDate.fromTotalDays(2), JulianDate.fromTotalDays(3), false, true, 2); + + var intervals = new TimeIntervalCollection(); + intervals.addInterval(interval1); + expect(intervals.findDataForIntervalContainingDate(interval1.start)).toEqual(1); + expect(intervals.findDataForIntervalContainingDate(interval1.stop)).toEqual(1); + + intervals.addInterval(interval2); + expect(intervals.findDataForIntervalContainingDate(interval1.start)).toEqual(1); + expect(intervals.findDataForIntervalContainingDate(interval1.stop)).toEqual(2); + expect(intervals.findDataForIntervalContainingDate(interval2.stop)).toEqual(2); + + expect(intervals.findDataForIntervalContainingDate(JulianDate.fromTotalDays(5))).toBeUndefined(); + }); + it('addInterval correctly intervals that have the same data when using equalsCallback', function() { var intervals = new TimeIntervalCollection(); @@ -463,6 +480,13 @@ defineSuite([ }).toThrow(); }); + it('findDataForIntervalContainingDate throws with undefined date', function() { + var intervals = new TimeIntervalCollection(); + expect(function() { + intervals.findDataForIntervalContainingDate(undefined); + }).toThrow(); + }); + it('contains throws with undefined date', function() { var intervals = new TimeIntervalCollection(); expect(function() { diff --git a/Specs/DynamicScene/ColorMaterialPropertySpec.js b/Specs/DynamicScene/ColorMaterialPropertySpec.js new file mode 100644 index 000000000000..b8e7053cecde --- /dev/null +++ b/Specs/DynamicScene/ColorMaterialPropertySpec.js @@ -0,0 +1,70 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/ColorMaterialProperty', + 'DynamicScene/ConstantProperty', + 'DynamicScene/TimeIntervalCollectionProperty', + 'Core/Color', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Specs/UndefinedProperty' + ], function( + ColorMaterialProperty, + ConstantProperty, + TimeIntervalCollectionProperty, + Color, + JulianDate, + TimeInterval, + UndefinedProperty) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('works with basic types', function() { + var property = new ColorMaterialProperty(); + expect(property.color).toBeDefined(); + expect(property.getType()).toEqual('Color'); + + var result = property.getValue(); + expect(result.color).toEqual(Color.WHITE); + }); + + it('works with constant values', function() { + var property = new ColorMaterialProperty(); + property.color = new ConstantProperty(Color.RED); + + var result = property.getValue(new JulianDate()); + expect(result.color).toEqual(Color.RED); + }); + + it('works with undefined values', function() { + var property = new ColorMaterialProperty(); + property.color = new UndefinedProperty(); + + var result = property.getValue(); + expect(result.hasOwnProperty('color')).toEqual(true); + expect(result.color).toBeUndefined(); + }); + + it('works with dynamic values', function() { + var property = new ColorMaterialProperty(); + property.color = new TimeIntervalCollectionProperty(); + + var start = new JulianDate(1, 0); + var stop = new JulianDate(2, 0); + property.color.intervals.addInterval(new TimeInterval(start, stop, true, true, Color.BLUE)); + + var result = property.getValue(start); + expect(result.color).toEqual(Color.BLUE); + }); + + it('works with a result parameter', function() { + var property = new ColorMaterialProperty(); + property.color = new ConstantProperty(Color.RED); + + var result = { + color : Color.BLUE.clone() + }; + var returnedResult = property.getValue(new JulianDate(), result); + expect(returnedResult).toBe(result); + expect(result.color).toEqual(Color.RED); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js b/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js index bd605a9d1de3..0b384b5b50db 100644 --- a/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js +++ b/Specs/DynamicScene/CompositeDynamicObjectCollectionSpec.js @@ -5,8 +5,7 @@ defineSuite([ 'Core/JulianDate', 'Core/Iso8601', 'Core/TimeInterval', - 'DynamicScene/processCzml', - 'DynamicScene/CzmlDefaults', + 'DynamicScene/CzmlDataSource', 'Scene/HorizontalOrigin' ], function( CompositeDynamicObjectCollection, @@ -14,8 +13,7 @@ defineSuite([ JulianDate, Iso8601, TimeInterval, - processCzml, - CzmlDefaults, + CzmlDataSource, HorizontalOrigin) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -38,8 +36,8 @@ defineSuite([ it('default constructor sets expected properties.', function() { var compositeDynamicObjectCollection = new CompositeDynamicObjectCollection(); - expect(compositeDynamicObjectCollection.mergeFunctions).toEqual(CzmlDefaults.mergers); - expect(compositeDynamicObjectCollection.cleanFunctions).toEqual(CzmlDefaults.cleaners); + expect(compositeDynamicObjectCollection.mergeFunctions).toEqual(CompositeDynamicObjectCollection.mergers); + expect(compositeDynamicObjectCollection.cleanFunctions).toEqual(CompositeDynamicObjectCollection.cleaners); expect(compositeDynamicObjectCollection.getCollections().length).toEqual(0); var objects = compositeDynamicObjectCollection.getObjects(); expect(objects.length).toEqual(0); @@ -120,10 +118,10 @@ defineSuite([ it('setCollections works with existing dynamicObjectCollections', function() { var dynamicObjectCollection1 = new DynamicObjectCollection(); - processCzml(czml1, dynamicObjectCollection1); + CzmlDataSource._processCzml(czml1, dynamicObjectCollection1); var dynamicObjectCollection2 = new DynamicObjectCollection(); - processCzml(czml2, dynamicObjectCollection2); + CzmlDataSource._processCzml(czml2, dynamicObjectCollection2); var compositeDynamicObjectCollection = new CompositeDynamicObjectCollection(); compositeDynamicObjectCollection.setCollections([dynamicObjectCollection1, dynamicObjectCollection2]); @@ -142,10 +140,10 @@ defineSuite([ it('Constructing with existing dynamicObjectCollections merges expected objects', function() { var dynamicObjectCollection1 = new DynamicObjectCollection(); - processCzml(czml1, dynamicObjectCollection1); + CzmlDataSource._processCzml(czml1, dynamicObjectCollection1); var dynamicObjectCollection2 = new DynamicObjectCollection(); - processCzml(czml2, dynamicObjectCollection2); + CzmlDataSource._processCzml(czml2, dynamicObjectCollection2); var compositeDynamicObjectCollection = new CompositeDynamicObjectCollection([dynamicObjectCollection1, dynamicObjectCollection2]); @@ -175,7 +173,7 @@ defineSuite([ 'horizontalOrigin' : 'CENTER' } }; - processCzml(czml3, dynamicObjectCollection1); + CzmlDataSource._processCzml(czml3, dynamicObjectCollection1); var objects = compositeDynamicObjectCollection.getObjects(); expect(objects.length).toEqual(1); @@ -191,11 +189,11 @@ defineSuite([ var czml4 = { 'id' : 'testBillboard', 'billboard' : { - 'horizontalOrigin' : 'TOP', + 'horizontalOrigin' : 'LEFT', 'scale' : 3.0 } }; - processCzml(czml4, dynamicObjectCollection2); + CzmlDataSource._processCzml(czml4, dynamicObjectCollection2); objects = compositeDynamicObjectCollection.getObjects(); expect(objects.length).toEqual(1); @@ -206,6 +204,6 @@ defineSuite([ expect(object.billboard.show.getValue(new JulianDate())).toEqual(true); expect(object.billboard.scale.getValue(new JulianDate())).toEqual(3.0); - expect(object.billboard.horizontalOrigin.getValue(new JulianDate())).toEqual(HorizontalOrigin.TOP); + expect(object.billboard.horizontalOrigin.getValue(new JulianDate())).toEqual(HorizontalOrigin.LEFT); }); }); diff --git a/Specs/DynamicScene/CompositeMaterialPropertySpec.js b/Specs/DynamicScene/CompositeMaterialPropertySpec.js new file mode 100644 index 000000000000..87b94e2e7f46 --- /dev/null +++ b/Specs/DynamicScene/CompositeMaterialPropertySpec.js @@ -0,0 +1,78 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/CompositeMaterialProperty', + 'DynamicScene/ConstantProperty', + 'DynamicScene/ColorMaterialProperty', + 'DynamicScene/GridMaterialProperty', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Core/TimeIntervalCollection' + ], function( + CompositeMaterialProperty, + ConstantProperty, + ColorMaterialProperty, + GridMaterialProperty, + JulianDate, + TimeInterval, + TimeIntervalCollection) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('default constructor has expected values', function() { + var property = new CompositeMaterialProperty(); + expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); + expect(property.getType(new JulianDate())).toBeUndefined(); + expect(property.getValue(new JulianDate())).toBeUndefined(); + }); + + it('works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ColorMaterialProperty()); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new GridMaterialProperty()); + + var property = new CompositeMaterialProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(property.getType(interval1.start)).toEqual('Color'); + expect(result1).not.toBe(interval1.data.getValue(interval1.start)); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop); + expect(property.getType(interval2.stop)).toEqual('Grid'); + expect(result2).not.toBe(interval2.data.getValue(interval2.stop)); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ColorMaterialProperty()); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new GridMaterialProperty()); + + var property = new CompositeMaterialProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = {}; + var result1 = property.getValue(interval1.start, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValue throws with no time parameter', function() { + var property = new CompositeMaterialProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); + + it('getType throws with no time parameter', function() { + var property = new CompositeMaterialProperty(); + expect(function() { + property.getType(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/CompositePositionPropertySpec.js b/Specs/DynamicScene/CompositePositionPropertySpec.js new file mode 100644 index 000000000000..18d96daa3161 --- /dev/null +++ b/Specs/DynamicScene/CompositePositionPropertySpec.js @@ -0,0 +1,149 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/CompositePositionProperty', + 'DynamicScene/ConstantPositionProperty', + 'DynamicScene/PositionProperty', + 'Core/Cartesian3', + 'Core/JulianDate', + 'Core/ReferenceFrame', + 'Core/TimeInterval', + 'Core/TimeIntervalCollection' + ], function( + CompositePositionProperty, + ConstantPositionProperty, + PositionProperty, + Cartesian3, + JulianDate, + ReferenceFrame, + TimeInterval, + TimeIntervalCollection) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('default constructor has expected values', function() { + var property = new CompositePositionProperty(); + expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); + expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); + }); + + it('constructor sets expected values', function() { + var property = new CompositePositionProperty(ReferenceFrame.INERTIAL); + expect(property.referenceFrame).toBe(ReferenceFrame.INERTIAL); + }); + + it('can modify reference frame', function() { + var property = new CompositePositionProperty(); + expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); + property.referenceFrame = ReferenceFrame.INERTIAL; + expect(property.referenceFrame).toBe(ReferenceFrame.INERTIAL); + }); + + it('works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3))); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6))); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(result1).not.toBe(interval1.data.getValue(interval1.start)); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop); + expect(result2).not.toBe(interval2.data.getValue(interval2.stop)); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValue works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3))); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6))); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = new Cartesian3(); + var result1 = property.getValue(interval1.start, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValue works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3))); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6))); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValue returns in fixed frame', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3), ReferenceFrame.INERTIAL)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6), ReferenceFrame.FIXED)); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var valueInertial = new Cartesian3(1, 2, 3); + var valueFixed = PositionProperty.convertToReferenceFrame(interval1.start, valueInertial, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED); + + var result1 = property.getValue(interval1.start); + expect(result1).toEqual(valueFixed); + + var result2 = property.getValue(interval2.stop); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValueInReferenceFrame works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3), ReferenceFrame.INERTIAL)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6), ReferenceFrame.FIXED)); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = new Cartesian3(); + var result1 = property.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL)); + + var result2 = property.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED)); + }); + + it('getValueInReferenceFrame works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantPositionProperty(new Cartesian3(1, 2, 3), ReferenceFrame.INERTIAL)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantPositionProperty(new Cartesian3(4, 5, 6), ReferenceFrame.FIXED)); + + var property = new CompositePositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL); + expect(result1).toEqual(interval1.data.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL)); + + var result2 = property.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED); + expect(result2).toEqual(interval2.data.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED)); + }); + + it('throws with no time parameter', function() { + var property = new CompositePositionProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/CompositePropertySpec.js b/Specs/DynamicScene/CompositePropertySpec.js new file mode 100644 index 000000000000..86d0815f3d0d --- /dev/null +++ b/Specs/DynamicScene/CompositePropertySpec.js @@ -0,0 +1,66 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/CompositeProperty', + 'DynamicScene/ConstantProperty', + 'Core/Cartesian3', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Core/TimeIntervalCollection' + ], function( + CompositeProperty, + ConstantProperty, + Cartesian3, + JulianDate, + TimeInterval, + TimeIntervalCollection) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('default constructor has expected values', function() { + var property = new CompositeProperty(); + expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); + expect(property.getValue(new JulianDate())).toBeUndefined(); + }); + + it('works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantProperty(new Cartesian3(1, 2, 3))); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantProperty(new Cartesian3(4, 5, 6))); + + var property = new CompositeProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(result1).not.toBe(interval1.data.getValue(interval1.start)); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop); + expect(result2).not.toBe(interval2.data.getValue(interval2.stop)); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new ConstantProperty(new Cartesian3(1, 2, 3))); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new ConstantProperty(new Cartesian3(4, 5, 6))); + + var property = new CompositeProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = new Cartesian3(); + var result1 = property.getValue(interval1.start, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data.getValue(interval1.start)); + + var result2 = property.getValue(interval2.stop, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data.getValue(interval2.stop)); + }); + + it('getValue throws with no time parameter', function() { + var property = new CompositeProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/ConstantPositionPropertySpec.js b/Specs/DynamicScene/ConstantPositionPropertySpec.js new file mode 100644 index 000000000000..27431bf5eda9 --- /dev/null +++ b/Specs/DynamicScene/ConstantPositionPropertySpec.js @@ -0,0 +1,86 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/ConstantPositionProperty', + 'DynamicScene/PositionProperty', + 'Core/Cartesian3', + 'Core/JulianDate', + 'Core/ReferenceFrame' + ], function( + ConstantPositionProperty, + PositionProperty, + Cartesian3, + JulianDate, + ReferenceFrame) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + var time = new JulianDate(); + + it('Constructor sets expected defaults', function() { + var property = new ConstantPositionProperty(new Cartesian3(1, 2, 3)); + expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); + + property = new ConstantPositionProperty(new Cartesian3(1, 2, 3), ReferenceFrame.INERTIAL); + expect(property.referenceFrame).toBe(ReferenceFrame.INERTIAL); + }); + + it('getValue works without a result parameter', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantPositionProperty(value); + + var result = property.getValue(time); + expect(result).not.toBe(value); + expect(result).toEqual(value); + }); + + it('getValue works with a result parameter', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantPositionProperty(value); + + var expected = new Cartesian3(); + var result = property.getValue(time, expected); + expect(result).toBe(expected); + expect(expected).toEqual(value); + }); + + it('getValue returns in fixed frame', function() { + var valueInertial = new Cartesian3(1, 2, 3); + var valueFixed = PositionProperty.convertToReferenceFrame(time, valueInertial, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED); + var property = new ConstantPositionProperty(valueInertial, ReferenceFrame.INERTIAL); + + var result = property.getValue(time); + expect(result).toEqual(valueFixed); + }); + + it('getValueInReferenceFrame works without a result parameter', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantPositionProperty(value); + + var result = property.getValueInReferenceFrame(time, ReferenceFrame.INERTIAL); + expect(result).not.toBe(value); + expect(result).toEqual(PositionProperty.convertToReferenceFrame(time, value, ReferenceFrame.FIXED, ReferenceFrame.INERTIAL)); + }); + + it('getValueInReferenceFrame works with a result parameter', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantPositionProperty(value, ReferenceFrame.INERTIAL); + + var expected = new Cartesian3(); + var result = property.getValueInReferenceFrame(time, ReferenceFrame.FIXED, expected); + expect(result).toBe(expected); + expect(expected).toEqual(PositionProperty.convertToReferenceFrame(time, value, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED)); + }); + + it('constructor throws with undefined value', function() { + expect(function() { + return new ConstantPositionProperty(undefined); + }).toThrow(); + }); + + it('getValue throws without time parameter', function() { + var property = new ConstantPositionProperty(new Cartesian3(1, 2, 3)); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/ConstantPropertySpec.js b/Specs/DynamicScene/ConstantPropertySpec.js new file mode 100644 index 000000000000..78beba73343a --- /dev/null +++ b/Specs/DynamicScene/ConstantPropertySpec.js @@ -0,0 +1,64 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/ConstantProperty', + 'Core/Cartesian3', + 'Core/JulianDate' + ], function( + ConstantProperty, + Cartesian3, + JulianDate) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + var time = new JulianDate(); + + it('works with basic types', function() { + var expected = 5; + var property = new ConstantProperty(expected); + expect(property.getValue(time)).toBe(expected); + }); + + it('works with clone function', function() { + var expected = {}; + var cloneCalled = false; + var cloneFunction = function() { + cloneCalled = true; + return expected; + }; + var property = new ConstantProperty(expected, cloneFunction); + expect(property.getValue(time)).toBe(expected); + expect(cloneCalled).toEqual(true); + }); + + it('works with clonable objects', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantProperty(value); + + var result = property.getValue(time); + expect(result).not.toBe(value); + expect(result).toEqual(value); + }); + + it('works with clonable objects with result parameter', function() { + var value = new Cartesian3(1, 2, 3); + var property = new ConstantProperty(value); + + var expected = new Cartesian3(); + var result = property.getValue(time, expected); + expect(result).toBe(expected); + expect(expected).toEqual(value); + }); + + it('constructor throws with undefined value', function() { + expect(function() { + return new ConstantProperty(undefined, function() { + }); + }).toThrow(); + }); + + it('constructor throws with undefined clone function on non-basic type', function() { + expect(function() { + return new ConstantProperty({}, undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlBooleanSpec.js b/Specs/DynamicScene/CzmlBooleanSpec.js deleted file mode 100644 index 12b50f07315c..000000000000 --- a/Specs/DynamicScene/CzmlBooleanSpec.js +++ /dev/null @@ -1,28 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlBoolean' - ], function( - CzmlBoolean) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleBoolean = true; - - var constantBooleanInterval = { - boolean : false - }; - - it('unwrapInterval', function() { - expect(CzmlBoolean.unwrapInterval(simpleBoolean)).toEqual(simpleBoolean); - expect(CzmlBoolean.unwrapInterval(constantBooleanInterval)).toEqual(constantBooleanInterval.boolean); - }); - - it('isSampled', function() { - expect(CzmlBoolean.isSampled()).toEqual(false); - }); - - it('getValue', function() { - expect(CzmlBoolean.getValue(simpleBoolean)).toEqual(simpleBoolean); - expect(CzmlBoolean.getValue(constantBooleanInterval.boolean)).toEqual(constantBooleanInterval.boolean); - }); -}); diff --git a/Specs/DynamicScene/CzmlCartesian2Spec.js b/Specs/DynamicScene/CzmlCartesian2Spec.js deleted file mode 100644 index 4b6d1bd1eabd..000000000000 --- a/Specs/DynamicScene/CzmlCartesian2Spec.js +++ /dev/null @@ -1,39 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlCartesian2', - 'Core/Cartesian2' - ], function( - CzmlCartesian2, - Cartesian2) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var cartesian1 = new Cartesian2(123.456, 789.101112); - var cartesian2 = new Cartesian2(789.101112, 123.456); - - var constantCartesianInterval = { - cartesian2 : [cartesian1.x, cartesian1.y] - }; - - var sampledCartesianInterval = { - cartesian2 : [0, cartesian1.x, cartesian1.y, 1, cartesian2.x, cartesian2.y] - }; - - it('unwrapInterval', function() { - expect(CzmlCartesian2.unwrapInterval(constantCartesianInterval)).toEqual(constantCartesianInterval.cartesian2); - expect(CzmlCartesian2.unwrapInterval(sampledCartesianInterval)).toEqual(sampledCartesianInterval.cartesian2); - }); - - it('isSampled', function() { - expect(CzmlCartesian2.isSampled(constantCartesianInterval.cartesian2)).toEqual(false); - expect(CzmlCartesian2.isSampled(sampledCartesianInterval.cartesian2)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlCartesian2.getValue(constantCartesianInterval.cartesian2)).toEqual(cartesian1); - }); - - it('getValueFromArray', function() { - expect(CzmlCartesian2.getValueFromArray(sampledCartesianInterval.cartesian2, 4)).toEqual(cartesian2); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlCartesian3Spec.js b/Specs/DynamicScene/CzmlCartesian3Spec.js deleted file mode 100644 index 19e6922ebea6..000000000000 --- a/Specs/DynamicScene/CzmlCartesian3Spec.js +++ /dev/null @@ -1,39 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlCartesian3', - 'Core/Cartesian3' - ], function( - CzmlCartesian3, - Cartesian3) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var cartesian1 = new Cartesian3(123.456, 789.101112, 321.312); - var cartesian2 = new Cartesian3(789.101112, 123.456, 521.312); - - var constantCartesianInterval = { - cartesian : [cartesian1.x, cartesian1.y, cartesian1.z] - }; - - var sampledCartesianInterval = { - cartesian : [0, cartesian1.x, cartesian1.y, cartesian1.z, 1, cartesian2.x, cartesian2.y, cartesian2.z] - }; - - it('unwrapInterval', function() { - expect(CzmlCartesian3.unwrapInterval(constantCartesianInterval)).toEqual(constantCartesianInterval.cartesian); - expect(CzmlCartesian3.unwrapInterval(sampledCartesianInterval)).toEqual(sampledCartesianInterval.cartesian); - }); - - it('isSampled', function() { - expect(CzmlCartesian3.isSampled(constantCartesianInterval.cartesian)).toEqual(false); - expect(CzmlCartesian3.isSampled(sampledCartesianInterval.cartesian)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlCartesian3.getValue(constantCartesianInterval.cartesian)).toEqual(cartesian1); - }); - - it('getValueFromArray', function() { - expect(CzmlCartesian3.getValueFromArray(sampledCartesianInterval.cartesian, 5)).toEqual(cartesian2); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlColorSpec.js b/Specs/DynamicScene/CzmlColorSpec.js deleted file mode 100644 index 6201353e2ab8..000000000000 --- a/Specs/DynamicScene/CzmlColorSpec.js +++ /dev/null @@ -1,49 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlColor', - 'Core/Color' - ], function( - CzmlColor, - Color) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var constantRgbaInterval = { - rgba : [1, 2, 3, 4] - }; - - var constantRgbafInterval = { - rgbaf : [Color.byteToFloat(1), Color.byteToFloat(2), Color.byteToFloat(3), Color.byteToFloat(4)] - }; - - var sampledRgbaInterval = { - rgba : [0, 1, 2, 3, 4, 1, 5, 6, 7, 8] - }; - - var sampledRgbafInterval = { - rgbaf : [0, Color.byteToFloat(1), Color.byteToFloat(2), Color.byteToFloat(3), Color.byteToFloat(4), 1, Color.byteToFloat(5), Color.byteToFloat(6), Color.byteToFloat(7), Color.byteToFloat(8)] - }; - - var color1 = new Color(sampledRgbafInterval.rgbaf[1], sampledRgbafInterval.rgbaf[2], sampledRgbafInterval.rgbaf[3], sampledRgbafInterval.rgbaf[4]); - var color2 = new Color(sampledRgbafInterval.rgbaf[6], sampledRgbafInterval.rgbaf[7], sampledRgbafInterval.rgbaf[8], sampledRgbafInterval.rgbaf[9]); - - it('unwrapInterval', function() { - expect(CzmlColor.unwrapInterval(constantRgbaInterval)).toEqual(constantRgbafInterval.rgbaf); - expect(CzmlColor.unwrapInterval(constantRgbafInterval)).toEqual(constantRgbafInterval.rgbaf); - expect(CzmlColor.unwrapInterval(sampledRgbaInterval)).toEqual(sampledRgbafInterval.rgbaf); - expect(CzmlColor.unwrapInterval(sampledRgbafInterval)).toEqual(sampledRgbafInterval.rgbaf); - }); - - it('isSampled', function() { - expect(CzmlColor.isSampled(sampledRgbaInterval.rgba)).toEqual(true); - expect(CzmlColor.isSampled(sampledRgbafInterval.rgbaf)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlColor.getValue(constantRgbafInterval.rgbaf)).toEqual(color1); - }); - - it('getValueFromArray', function() { - expect(CzmlColor.getValueFromArray(sampledRgbafInterval.rgbaf, 6)).toEqual(color2); - }); -}); diff --git a/Specs/DynamicScene/CzmlDataSourceSpec.js b/Specs/DynamicScene/CzmlDataSourceSpec.js index 6198ec74c637..36499d7b6090 100644 --- a/Specs/DynamicScene/CzmlDataSourceSpec.js +++ b/Specs/DynamicScene/CzmlDataSourceSpec.js @@ -2,9 +2,20 @@ defineSuite([ 'DynamicScene/CzmlDataSource', 'DynamicScene/DynamicObjectCollection', + 'Core/Cartesian2', + 'Core/Cartesian3', 'Core/ClockRange', 'Core/ClockStep', + 'Core/Color', 'Core/defined', + 'Core/Quaternion', + 'Core/Spherical', + 'DynamicScene/DynamicBillboard', + 'DynamicScene/DynamicObject', + 'Scene/HorizontalOrigin', + 'Core/Iso8601', + 'Scene/LabelStyle', + 'Scene/VerticalOrigin', 'Core/Event', 'Core/loadJson', 'Core/JulianDate', @@ -13,9 +24,20 @@ defineSuite([ ], function( CzmlDataSource, DynamicObjectCollection, + Cartesian2, + Cartesian3, ClockRange, ClockStep, + Color, defined, + Quaternion, + Spherical, + DynamicBillboard, + DynamicObject, + HorizontalOrigin, + Iso8601, + LabelStyle, + VerticalOrigin, Event, loadJson, JulianDate, @@ -271,4 +293,987 @@ defineSuite([ expect(resolveSpy).not.toHaveBeenCalled(); }); }); + + it('CZML adds data for infinite billboard.', function() { + var sourceUri = 'http://someImage.invalid/'; + var billboardPacket = { + billboard : { + image : 'image.png', + scale : 1.0, + horizontalOrigin : 'CENTER', + verticalOrigin : 'CENTER', + color : { + rgbaf : [1.0, 1.0, 1.0, 1.0] + }, + eyeOffset : { + cartesian : [3.0, 4.0, 5.0] + }, + pixelOffset : { + cartesian2 : [1.0, 2.0] + }, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(billboardPacket, sourceUri); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.billboard).toBeDefined(); + expect(dynamicObject.billboard.image.getValue(Iso8601.MINIMUM_VALUE)).toEqual(sourceUri + 'image.png'); + expect(dynamicObject.billboard.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(billboardPacket.billboard.scale); + expect(dynamicObject.billboard.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.CENTER); + expect(dynamicObject.billboard.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); + expect(dynamicObject.billboard.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); + expect(dynamicObject.billboard.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); + expect(dynamicObject.billboard.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(1.0, 2.0)); + expect(dynamicObject.billboard.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained billboard.', function() { + var billboardPacket = { + billboard : { + interval : '2000-01-01/2001-01-01', + image : 'http://someImage.invalid/image', + scale : 1.0, + horizontalOrigin : 'CENTER', + verticalOrigin : 'CENTER', + color : { + rgbaf : [1.0, 1.0, 1.0, 1.0] + }, + eyeOffset : { + cartesian : [3.0, 4.0, 5.0] + }, + pixelOffset : { + cartesian2 : [1.0, 2.0] + }, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(billboardPacket.billboard.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(billboardPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.billboard).toBeDefined(); + expect(dynamicObject.billboard.image.getValue(validTime)).toEqual(billboardPacket.billboard.image); + expect(dynamicObject.billboard.scale.getValue(validTime)).toEqual(billboardPacket.billboard.scale); + expect(dynamicObject.billboard.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.CENTER); + expect(dynamicObject.billboard.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); + expect(dynamicObject.billboard.color.getValue(validTime)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); + expect(dynamicObject.billboard.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); + expect(dynamicObject.billboard.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(1.0, 2.0)); + expect(dynamicObject.billboard.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.billboard).toBeDefined(); + expect(dynamicObject.billboard.image.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.scale.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.horizontalOrigin.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.verticalOrigin.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.eyeOffset.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.pixelOffset.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.billboard.show.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds clock data.', function() { + var clockPacket = { + id : 'document', + clock : { + interval : '2012-03-15T10:00:00Z/2012-03-16T10:00:00Z', + currentTime : '2012-03-15T10:00:00Z', + multiplier : 60.0, + range : 'LOOP_STOP', + step : 'SYSTEM_CLOCK_MULTIPLIER' + } + }; + + var interval = TimeInterval.fromIso8601(clockPacket.clock.interval); + var currentTime = JulianDate.fromIso8601(clockPacket.clock.currentTime); + var multiplier = clockPacket.clock.multiplier; + var range = ClockRange[clockPacket.clock.range]; + var step = ClockStep[clockPacket.clock.step]; + + var dataSource = new CzmlDataSource(); + dataSource.load(clockPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.clock).toBeDefined(); + expect(dynamicObject.clock.startTime).toEqual(interval.start); + expect(dynamicObject.clock.stopTime).toEqual(interval.stop); + expect(dynamicObject.clock.currentTime).toEqual(currentTime); + expect(dynamicObject.clock.clockRange).toEqual(range); + expect(dynamicObject.clock.clockStep).toEqual(step); + expect(dynamicObject.clock.multiplier).toEqual(multiplier); + }); + + it('CZML only adds clock data on the document object.', function() { + var clockPacket = { + id : 'notTheDocument', + clock : { + interval : "2012-03-15T10:00:00Z/2012-03-16T10:00:00Z", + currentTime : "2012-03-15T10:00:00Z", + multiplier : 60.0, + range : "LOOP_STOP", + step : "SYSTEM_CLOCK_MULTIPLIER" + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(clockPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + expect(dynamicObject.clock).toBeUndefined(); + }); + + + it('CZML adds data for infinite cone.', function() { + var conePacket = { + cone : { + innerHalfAngle : 1.0, + outerHalfAngle : 1.1, + minimumClockAngle : 1.2, + maximumClockAngle : 1.3, + radius : 2.0, + show : true, + showIntersection : false, + intersectionWidth : 6.0, + capMaterial : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + innerMaterial : { + solidColor : { + color : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + } + } + }, + outerMaterial : { + solidColor : { + color : { + rgbaf : [0.3, 0.3, 0.3, 0.3] + } + } + }, + silhouetteMaterial : { + solidColor : { + color : { + rgbaf : [0.4, 0.4, 0.4, 0.4] + } + } + }, + intersectionColor : { + rgbaf : [0.5, 0.5, 0.5, 0.5] + } + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(conePacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.cone).toBeDefined(); + expect(dynamicObject.cone.innerHalfAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.innerHalfAngle); + expect(dynamicObject.cone.outerHalfAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.outerHalfAngle); + expect(dynamicObject.cone.minimumClockAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.minimumClockAngle); + expect(dynamicObject.cone.maximumClockAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.maximumClockAngle); + expect(dynamicObject.cone.radius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.radius); + expect(dynamicObject.cone.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.show); + expect(dynamicObject.cone.showIntersection.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.showIntersection); + expect(dynamicObject.cone.capMaterial.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.cone.innerMaterial.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.cone.outerMaterial.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.3, 0.3, 0.3, 0.3)); + expect(dynamicObject.cone.silhouetteMaterial.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.4, 0.4, 0.4, 0.4)); + expect(dynamicObject.cone.intersectionColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); + expect(dynamicObject.cone.intersectionWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.intersectionWidth); + }); + + it('CZML adds data for constrained cone.', function() { + var conePacket = { + cone : { + interval : '2000-01-01/2001-01-01', + innerHalfAngle : 1.0, + outerHalfAngle : 1.1, + minimumClockAngle : 1.2, + maximumClockAngle : 1.3, + radius : 2.0, + show : true, + showIntersection : false, + intersectionWidth : 4.0, + capMaterial : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + innerMaterial : { + solidColor : { + color : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + } + } + }, + outerMaterial : { + solidColor : { + color : { + rgbaf : [0.3, 0.3, 0.3, 0.3] + } + } + }, + silhouetteMaterial : { + solidColor : { + color : { + rgbaf : [0.4, 0.4, 0.4, 0.4] + } + } + }, + intersectionColor : { + rgbaf : [0.5, 0.5, 0.5, 0.5] + } + } + }; + + var validTime = TimeInterval.fromIso8601(conePacket.cone.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(conePacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.cone).toBeDefined(); + expect(dynamicObject.cone.innerHalfAngle.getValue(validTime)).toEqual(conePacket.cone.innerHalfAngle); + expect(dynamicObject.cone.outerHalfAngle.getValue(validTime)).toEqual(conePacket.cone.outerHalfAngle); + expect(dynamicObject.cone.minimumClockAngle.getValue(validTime)).toEqual(conePacket.cone.minimumClockAngle); + expect(dynamicObject.cone.maximumClockAngle.getValue(validTime)).toEqual(conePacket.cone.maximumClockAngle); + expect(dynamicObject.cone.radius.getValue(validTime)).toEqual(conePacket.cone.radius); + expect(dynamicObject.cone.show.getValue(validTime)).toEqual(conePacket.cone.show); + expect(dynamicObject.cone.showIntersection.getValue(validTime)).toEqual(conePacket.cone.showIntersection); + expect(dynamicObject.cone.capMaterial.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.cone.innerMaterial.getValue(validTime).color).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.cone.outerMaterial.getValue(validTime).color).toEqual(new Color(0.3, 0.3, 0.3, 0.3)); + expect(dynamicObject.cone.silhouetteMaterial.getValue(validTime).color).toEqual(new Color(0.4, 0.4, 0.4, 0.4)); + expect(dynamicObject.cone.intersectionColor.getValue(validTime)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); + expect(dynamicObject.cone.intersectionWidth.getValue(validTime)).toEqual(conePacket.cone.intersectionWidth); + + expect(dynamicObject.cone.innerHalfAngle.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.outerHalfAngle.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.minimumClockAngle.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.maximumClockAngle.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.radius.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.show.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.showIntersection.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.capMaterial.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.innerMaterial.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.outerMaterial.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.silhouetteMaterial.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.intersectionColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.cone.intersectionWidth.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite ellipse.', function() { + var ellipsePacket = { + ellipse : { + semiMajorAxis : 10, + semiMinorAxis : 20, + bearing : 1.0 + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(ellipsePacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.ellipse).toBeDefined(); + expect(dynamicObject.ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMajorAxis); + expect(dynamicObject.ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMinorAxis); + expect(dynamicObject.ellipse.bearing.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.bearing); + }); + + it('CZML adds data for constrained ellipse.', function() { + var ellipsePacketInterval = { + ellipse : { + interval : '2000-01-01/2001-01-01', + semiMajorAxis : 10, + semiMinorAxis : 20, + bearing : 1.0 + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(ellipsePacketInterval); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + var validTime = TimeInterval.fromIso8601(ellipsePacketInterval.ellipse.interval).start; + var invalidTime = validTime.addSeconds(-1); + + expect(dynamicObject.ellipse).toBeDefined(); + expect(dynamicObject.ellipse.semiMajorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMajorAxis); + expect(dynamicObject.ellipse.semiMinorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMinorAxis); + expect(dynamicObject.ellipse.bearing.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.bearing); + + expect(dynamicObject.ellipse.semiMajorAxis.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.ellipse.semiMinorAxis.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.ellipse.bearing.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite ellipsoid.', function() { + var expectedRadii = new Cartesian3(1.0, 2.0, 3.0); + + var ellipsoidPacket = { + ellipsoid : { + radii : { + cartesian : [1.0, 2.0, 3.0] + }, + show : true, + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + } + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(ellipsoidPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.ellipsoid).toBeDefined(); + expect(dynamicObject.ellipsoid.radii.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedRadii); + expect(dynamicObject.ellipsoid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsoidPacket.ellipsoid.show); + expect(dynamicObject.ellipsoid.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + }); + + it('CZML adds data for constrained ellipsoid.', function() { + var expectedRadii = new Cartesian3(1.0, 2.0, 3.0); + + var ellipsoidPacketInterval = { + ellipsoid : { + interval : '2000-01-01/2001-01-01', + radii : { + cartesian : [1.0, 2.0, 3.0] + }, + show : true, + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + } + } + }; + + var validTime = TimeInterval.fromIso8601(ellipsoidPacketInterval.ellipsoid.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(ellipsoidPacketInterval); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.ellipsoid).toBeDefined(); + expect(dynamicObject.ellipsoid.radii.getValue(validTime)).toEqual(expectedRadii); + expect(dynamicObject.ellipsoid.show.getValue(validTime)).toEqual(ellipsoidPacketInterval.ellipsoid.show); + expect(dynamicObject.ellipsoid.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + + expect(dynamicObject.ellipsoid.radii.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.ellipsoid.show.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.ellipsoid.material.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite label.', function() { + var labelPacket = { + label : { + text : 'TestFacility', + font : '10pt "Open Sans"', + style : 'FILL', + fillColor : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 3.14, + horizontalOrigin : 'LEFT', + verticalOrigin : 'CENTER', + eyeOffset : { + cartesian : [1.0, 2.0, 3.0] + }, + pixelOffset : { + cartesian2 : [4.0, 5.0] + }, + scale : 1.0, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(labelPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.label).toBeDefined(); + expect(dynamicObject.label.text.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.text); + expect(dynamicObject.label.font.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.font); + expect(dynamicObject.label.style.getValue(Iso8601.MINIMUM_VALUE)).toEqual(LabelStyle.FILL); + expect(dynamicObject.label.fillColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.label.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.label.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.outlineWidth); + expect(dynamicObject.label.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.LEFT); + expect(dynamicObject.label.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); + expect(dynamicObject.label.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + expect(dynamicObject.label.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(4.0, 5.0)); + expect(dynamicObject.label.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.scale); + expect(dynamicObject.label.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.show); + }); + + it('CZML adds data for constrained label.', function() { + var labelPacket = { + label : { + interval : '2000-01-01/2001-01-01', + text : 'TestFacility', + font : '10pt "Open Sans"', + style : 'FILL', + fillColor : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 2.78, + horizontalOrigin : 'LEFT', + verticalOrigin : 'CENTER', + eyeOffset : { + cartesian : [1.0, 2.0, 3.0] + }, + pixelOffset : { + cartesian2 : [4.0, 5.0] + }, + scale : 1.0, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(labelPacket.label.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(labelPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.label).toBeDefined(); + expect(dynamicObject.label.text.getValue(validTime)).toEqual(labelPacket.label.text); + expect(dynamicObject.label.font.getValue(validTime)).toEqual(labelPacket.label.font); + expect(dynamicObject.label.style.getValue(validTime)).toEqual(LabelStyle.FILL); + expect(dynamicObject.label.fillColor.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.label.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.label.outlineWidth.getValue(validTime)).toEqual(labelPacket.label.outlineWidth); + expect(dynamicObject.label.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.LEFT); + expect(dynamicObject.label.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); + expect(dynamicObject.label.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + expect(dynamicObject.label.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(4.0, 5.0)); + expect(dynamicObject.label.scale.getValue(validTime)).toEqual(labelPacket.label.scale); + expect(dynamicObject.label.show.getValue(validTime)).toEqual(labelPacket.label.show); + + expect(dynamicObject.label.text.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.font.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.style.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.fillColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.outlineColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.outlineWidth.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.horizontalOrigin.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.verticalOrigin.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.eyeOffset.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.pixelOffset.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.scale.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.label.show.getValue(invalidTime)).toBeUndefined(); + }); + + + it('CZML Position works.', function() { + var packet = { + position : { + cartesian : [1.0, 2.0, 3.0] + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(packet); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + expect(dynamicObject.position.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + }); + + it('CZML Orientation works.', function() { + var packet = { + orientation : { + unitQuaternion : [0.0, 0.0, 0.0, 1.0] + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(packet); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + expect(dynamicObject.orientation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Quaternion(0.0, 0.0, 0.0, 1.0)); + }); + + it('CZML VertexPositions works.', function() { + var packet = { + vertexPositions : { + cartesian : [1.0, 2.0, 3.0, 5.0, 6.0, 7.0] + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(packet); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + expect(dynamicObject.vertexPositions.getValue(Iso8601.MINIMUM_VALUE)).toEqual([new Cartesian3(1.0, 2.0, 3.0), new Cartesian3(5.0, 6.0, 7.0)]); + }); + + it('CZML ViewFrom works.', function() { + var packet = { + viewFrom : { + cartesian : [1.0, 2.0, 3.0] + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(packet); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + expect(dynamicObject.viewFrom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); + }); + + it('CZML Availability works.', function() { + var packet = { + availability : '2000-01-01/2001-01-01' + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(packet); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + var interval = TimeInterval.fromIso8601(packet.availability); + expect(dynamicObject.availability).toEqual(interval); + }); + + it('CZML adds data for infinite path.', function() { + var pathPacket = { + path : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + resolution : 23.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + leadTime : 2.0, + trailTime : 3.0, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(pathPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.path).toBeDefined(); + expect(dynamicObject.path.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.width); + expect(dynamicObject.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.resolution); + expect(dynamicObject.path.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.path.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.outlineWidth); + expect(dynamicObject.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.leadTime); + expect(dynamicObject.path.trailTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.trailTime); + expect(dynamicObject.path.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained path.', function() { + var pathPacket = { + path : { + interval : '2000-01-01/2001-01-01', + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + resolution : 23.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + leadTime : 2.0, + trailTime : 3.0, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(pathPacket.path.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(pathPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.path).toBeDefined(); + expect(dynamicObject.path.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.path.width.getValue(validTime)).toEqual(pathPacket.path.width); + expect(dynamicObject.path.resolution.getValue(validTime)).toEqual(pathPacket.path.resolution); + expect(dynamicObject.path.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.path.outlineWidth.getValue(validTime)).toEqual(pathPacket.path.outlineWidth); + expect(dynamicObject.path.leadTime.getValue(validTime)).toEqual(pathPacket.path.leadTime); + expect(dynamicObject.path.trailTime.getValue(validTime)).toEqual(pathPacket.path.trailTime); + expect(dynamicObject.path.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.path.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.width.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.outlineColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.outlineWidth.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.leadTime.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.trailTime.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.show.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite point.', function() { + var pointPacket = { + point : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + pixelSize : 1.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(pointPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.point).toBeDefined(); + expect(dynamicObject.point.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.point.pixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.pixelSize); + expect(dynamicObject.point.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.point.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.outlineWidth); + expect(dynamicObject.point.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained point.', function() { + var pointPacket = { + point : { + interval : '2000-01-01/2001-01-01', + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + pixelSize : 1.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(pointPacket.point.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(pointPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.point).toBeDefined(); + expect(dynamicObject.point.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.point.pixelSize.getValue(validTime)).toEqual(pointPacket.point.pixelSize); + expect(dynamicObject.point.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.point.outlineWidth.getValue(validTime)).toEqual(pointPacket.point.outlineWidth); + expect(dynamicObject.point.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.point.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.point.pixelSize.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.point.outlineColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.point.outlineWidth.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.point.show.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite polygon.', function() { + var polygonPacket = { + polygon : { + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(polygonPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.polygon).toBeDefined(); + expect(dynamicObject.polygon.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.polygon.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained polygon.', function() { + var polygonPacket = { + polygon : { + interval : '2000-01-01/2001-01-01', + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(polygonPacket.polygon.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(polygonPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.polygon).toBeDefined(); + expect(dynamicObject.polygon.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.polygon.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.polygon.material.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.polygon.show.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite polyline.', function() { + var polylinePacket = { + polyline : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(polylinePacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.polyline).toBeDefined(); + expect(dynamicObject.polyline.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.width); + expect(dynamicObject.polyline.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.polyline.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.outlineWidth); + expect(dynamicObject.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained polyline.', function() { + var polylinePacket = { + polyline : { + interval : '2000-01-01/2001-01-01', + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + outlineColor : { + rgbaf : [0.2, 0.2, 0.2, 0.2] + }, + outlineWidth : 1.0, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(polylinePacket.polyline.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(polylinePacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.polyline).toBeDefined(); + expect(dynamicObject.polyline.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.polyline.width.getValue(validTime)).toEqual(polylinePacket.polyline.width); + expect(dynamicObject.polyline.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.polyline.outlineWidth.getValue(validTime)).toEqual(polylinePacket.polyline.outlineWidth); + expect(dynamicObject.polyline.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.polyline.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.polyline.width.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.polyline.outlineColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.polyline.outlineWidth.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.polyline.show.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite pyramid.', function() { + var pyramidPacket = { + pyramid : { + directions : { + unitSpherical : [1.0, 2.0, 3.0, 4.0] + }, + radius : 2.0, + show : true, + showIntersection : false, + intersectionWidth : 7.0, + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + intersectionColor : { + rgbaf : [0.5, 0.5, 0.5, 0.5] + } + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(pyramidPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.pyramid).toBeDefined(); + expect(dynamicObject.pyramid.directions.getValue(Iso8601.MINIMUM_VALUE)).toEqual( + [new Spherical(pyramidPacket.pyramid.directions.unitSpherical[0], pyramidPacket.pyramid.directions.unitSpherical[1]), + new Spherical(pyramidPacket.pyramid.directions.unitSpherical[2], pyramidPacket.pyramid.directions.unitSpherical[3])]); + expect(dynamicObject.pyramid.radius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.radius); + expect(dynamicObject.pyramid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.show); + expect(dynamicObject.pyramid.showIntersection.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.showIntersection); + expect(dynamicObject.pyramid.material.getValue(Iso8601.MINIMUM_VALUE).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.pyramid.intersectionColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); + expect(dynamicObject.pyramid.intersectionWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(7.0); + }); + + it('CZML adds data for constrained pyramid.', function() { + var pyramidPacket = { + pyramid : { + interval : '2000-01-01/2001-01-01', + directions : { + unitSpherical : [1.0, 2.0, 3.0, 4.0] + }, + radius : 2.0, + show : true, + showIntersection : false, + intersectionWidth : 8.0, + material : { + solidColor : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + } + } + }, + intersectionColor : { + rgbaf : [0.5, 0.5, 0.5, 0.5] + } + } + }; + + var validTime = TimeInterval.fromIso8601(pyramidPacket.pyramid.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(pyramidPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.pyramid).toBeDefined(); + expect(dynamicObject.pyramid.directions.getValue(validTime)).toEqual( + [new Spherical(pyramidPacket.pyramid.directions.unitSpherical[0], pyramidPacket.pyramid.directions.unitSpherical[1]), + new Spherical(pyramidPacket.pyramid.directions.unitSpherical[2], pyramidPacket.pyramid.directions.unitSpherical[3])]); + expect(dynamicObject.pyramid.radius.getValue(validTime)).toEqual(pyramidPacket.pyramid.radius); + expect(dynamicObject.pyramid.show.getValue(validTime)).toEqual(pyramidPacket.pyramid.show); + expect(dynamicObject.pyramid.showIntersection.getValue(validTime)).toEqual(pyramidPacket.pyramid.showIntersection); + expect(dynamicObject.pyramid.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.pyramid.intersectionColor.getValue(validTime)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); + expect(dynamicObject.pyramid.intersectionWidth.getValue(validTime)).toEqual(8.0); + + expect(dynamicObject.pyramid.directions.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.radius.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.show.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.showIntersection.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.material.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.intersectionColor.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.pyramid.intersectionWidth.getValue(invalidTime)).toBeUndefined(); + }); + + it('CZML adds data for infinite vector.', function() { + var direction = new Cartesian3(1, 2, 3).normalize(); + var vectorPacket = { + vector : { + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + length : 10.0, + direction : { + unitCartesian : [direction.x, direction.y, direction.z] + }, + show : true + } + }; + + var dataSource = new CzmlDataSource(); + dataSource.load(vectorPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.vector).toBeDefined(); + expect(dynamicObject.vector.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.vector.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(vectorPacket.vector.width); + expect(dynamicObject.vector.direction.getValue(Iso8601.MINIMUM_VALUE)).toEqual(direction); + expect(dynamicObject.vector.length.getValue(Iso8601.MINIMUM_VALUE)).toEqual(vectorPacket.vector.length); + expect(dynamicObject.vector.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); + }); + + it('CZML adds data for constrained vector.', function() { + var direction = new Cartesian3(1, 2, 3).normalize(); + var vectorPacket = { + vector : { + interval : '2000-01-01/2001-01-01', + color : { + rgbaf : [0.1, 0.1, 0.1, 0.1] + }, + width : 1.0, + length : 10.0, + direction : { + unitCartesian : [direction.x, direction.y, direction.z] + }, + show : true + } + }; + + var validTime = TimeInterval.fromIso8601(vectorPacket.vector.interval).start; + var invalidTime = validTime.addSeconds(-1); + + var dataSource = new CzmlDataSource(); + dataSource.load(vectorPacket); + var dynamicObject = dataSource.getDynamicObjectCollection().getObjects()[0]; + + expect(dynamicObject.vector).toBeDefined(); + expect(dynamicObject.vector.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.vector.width.getValue(validTime)).toEqual(vectorPacket.vector.width); + expect(dynamicObject.vector.direction.getValue(validTime)).toEqual(direction); + expect(dynamicObject.vector.length.getValue(validTime)).toEqual(vectorPacket.vector.length); + expect(dynamicObject.vector.show.getValue(validTime)).toEqual(true); + + expect(dynamicObject.vector.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.vector.width.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.vector.direction.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.vector.length.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.vector.show.getValue(invalidTime)).toBeUndefined(); + }); }); diff --git a/Specs/DynamicScene/CzmlDirectionSpec.js b/Specs/DynamicScene/CzmlDirectionSpec.js deleted file mode 100644 index f5a7b958adbd..000000000000 --- a/Specs/DynamicScene/CzmlDirectionSpec.js +++ /dev/null @@ -1,64 +0,0 @@ -/*global defineSuite*/ -defineSuite(['DynamicScene/CzmlDirection', - 'Core/Cartesian3', - 'Core/Spherical', - 'Core/Math', - 'Core/Ellipsoid' - ], function( - CzmlDirection, - Cartesian3, - Spherical, - CesiumMath, - Ellipsoid) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var spherical1 = new Spherical(0, 1.0); - var spherical2 = new Spherical(1.0, 0.0); - var cartesian1 = Cartesian3.fromSpherical(spherical1); - var cartesian2 = Cartesian3.fromSpherical(spherical2); - - var constantCartesianInterval = { - unitCartesian : [cartesian1.x, cartesian1.y, cartesian1.z] - }; - - var sampledCartesianInterval = { - unitCartesian : [0, cartesian1.x, cartesian1.y, cartesian1.z, 1, cartesian2.x, cartesian2.y, cartesian2.z] - }; - - var constantSphericalInterval = { - unitSpherical : [spherical1.clock, spherical1.cone] - }; - - var sampledSphericalInterval = { - unitSpherical : [0, spherical1.clock, spherical1.cone, 1, spherical2.clock, spherical2.cone] - }; - - it('unwrapInterval', function() { - expect(CzmlDirection.unwrapInterval(constantCartesianInterval)).toEqual(constantCartesianInterval.unitCartesian); - expect(CzmlDirection.unwrapInterval(sampledCartesianInterval)).toEqual(sampledCartesianInterval.unitCartesian); - }); - - it('isSampled', function() { - expect(CzmlDirection.isSampled(constantCartesianInterval.unitCartesian)).toEqual(false); - expect(CzmlDirection.isSampled(sampledCartesianInterval.unitCartesian)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlDirection.getValue(constantCartesianInterval.unitCartesian)).toEqual(cartesian1); - }); - - it('getValueFromArray', function() { - expect(CzmlDirection.getValueFromArray(sampledCartesianInterval.unitCartesian, 5)).toEqual(cartesian2); - }); - - it('Spherical unwrapInterval', function() { - expect(CzmlDirection.unwrapInterval(constantSphericalInterval)).toEqual(constantCartesianInterval.unitCartesian); - expect(CzmlDirection.unwrapInterval(sampledSphericalInterval)).toEqual(sampledCartesianInterval.unitCartesian); - }); - - it('Spherical isSampled', function() { - expect(CzmlDirection.isSampled(constantSphericalInterval.unitSpherical)).toEqual(false); - expect(CzmlDirection.isSampled(sampledSphericalInterval.unitSpherical)).toEqual(true); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlHorizontalOriginSpec.js b/Specs/DynamicScene/CzmlHorizontalOriginSpec.js deleted file mode 100644 index a49c1e4d7ef2..000000000000 --- a/Specs/DynamicScene/CzmlHorizontalOriginSpec.js +++ /dev/null @@ -1,30 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlHorizontalOrigin', - 'Scene/HorizontalOrigin' - ], function( - CzmlHorizontalOrigin, - HorizontalOrigin) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleHorizontalOrigin = 'CENTER'; - - var constantHorizontalOriginInterval = { - horizontalOrigin : 'LEFT' - }; - - it('unwrapInterval', function() { - expect(CzmlHorizontalOrigin.unwrapInterval(simpleHorizontalOrigin)).toEqual(simpleHorizontalOrigin); - expect(CzmlHorizontalOrigin.unwrapInterval(constantHorizontalOriginInterval)).toEqual(constantHorizontalOriginInterval.horizontalOrigin); - }); - - it('isSampled', function() { - expect(CzmlHorizontalOrigin.isSampled()).toEqual(false); - }); - - it('getValue', function() { - expect(CzmlHorizontalOrigin.getValue(simpleHorizontalOrigin)).toEqual(HorizontalOrigin.CENTER); - expect(CzmlHorizontalOrigin.getValue(constantHorizontalOriginInterval.horizontalOrigin)).toEqual(HorizontalOrigin.LEFT); - }); -}); diff --git a/Specs/DynamicScene/CzmlImageSpec.js b/Specs/DynamicScene/CzmlImageSpec.js deleted file mode 100644 index 2afb764f5791..000000000000 --- a/Specs/DynamicScene/CzmlImageSpec.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlImage' - ], function( - CzmlImage) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleImage = 'foo.png'; - - var constantImageInterval = { - image : 'foo.png' - }; - - it('unwrapInterval works without a source uri', function() { - expect(CzmlImage.unwrapInterval(simpleImage)).toEqual(simpleImage); - expect(CzmlImage.unwrapInterval(constantImageInterval)).toEqual(constantImageInterval.image); - }); - - it('unwrapInterval resolves link with sourceUri', function() { - expect(CzmlImage.unwrapInterval(simpleImage, "http://www.agi.com")).toEqual("http://www.agi.com/foo.png"); - expect(CzmlImage.unwrapInterval(simpleImage, "http://www.agi.com/data.czml")).toEqual("http://www.agi.com/foo.png"); - expect(CzmlImage.unwrapInterval(simpleImage, "http://www.agi.com/subdir/data.czml")).toEqual("http://www.agi.com/subdir/foo.png"); - expect(CzmlImage.unwrapInterval(constantImageInterval, "http://www.agi.com/someQuery?a=1&b=3")).toEqual("http://www.agi.com/foo.png"); - }); - - it('unwrapInterval works with absolute urls', function() { - var url = 'http://example.invalid/someDir/some.png'; - expect(CzmlImage.unwrapInterval(url, "http://www.agi.com")).toEqual(url); - expect(CzmlImage.unwrapInterval(url, "http://www.agi.com/data.czml")).toEqual(url); - expect(CzmlImage.unwrapInterval(url, "http://www.agi.com/subdir/data.czml")).toEqual(url); - - var interval = { - image : url - }; - expect(CzmlImage.unwrapInterval(interval, "http://www.agi.com/someQuery?a=1&b=3")).toEqual(url); - }); - - it('unwrapInterval works with data urls', function() { - var dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; - - expect(CzmlImage.unwrapInterval(dataUrl, "http://www.agi.com")).toEqual(dataUrl); - expect(CzmlImage.unwrapInterval(dataUrl, "http://www.agi.com/data.czml")).toEqual(dataUrl); - expect(CzmlImage.unwrapInterval(dataUrl, "http://www.agi.com/data.czml")).toEqual(dataUrl); - - var interval = { - image : dataUrl - }; - expect(CzmlImage.unwrapInterval(interval, "http://www.agi.com/someQuery?a=1&b=3")).toEqual(dataUrl); - }); - - it('isSampled always returns false', function() { - expect(CzmlImage.isSampled()).toEqual(false); - }); - - it('getValue always returns the passed in parameter.', function() { - expect(CzmlImage.getValue(simpleImage)).toBe(simpleImage); - expect(CzmlImage.getValue(constantImageInterval.image)).toBe(constantImageInterval.image); - }); -}); diff --git a/Specs/DynamicScene/CzmlLabelStyleSpec.js b/Specs/DynamicScene/CzmlLabelStyleSpec.js deleted file mode 100644 index eb908cdad48f..000000000000 --- a/Specs/DynamicScene/CzmlLabelStyleSpec.js +++ /dev/null @@ -1,30 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlLabelStyle', - 'Scene/LabelStyle' - ], function( - CzmlLabelStyle, - LabelStyle) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleLabelStyle = 'FILL'; - - var constantLabelStyleInterval = { - labelStyle : 'OUTLINE' - }; - - it('unwrapInterval', function() { - expect(CzmlLabelStyle.unwrapInterval(simpleLabelStyle)).toEqual(simpleLabelStyle); - expect(CzmlLabelStyle.unwrapInterval(constantLabelStyleInterval)).toEqual(constantLabelStyleInterval.labelStyle); - }); - - it('isSampled', function() { - expect(CzmlLabelStyle.isSampled()).toEqual(false); - }); - - it('getValue', function() { - expect(CzmlLabelStyle.getValue(simpleLabelStyle)).toEqual(LabelStyle.FILL); - expect(CzmlLabelStyle.getValue(constantLabelStyleInterval.labelStyle)).toEqual(LabelStyle.OUTLINE); - }); -}); diff --git a/Specs/DynamicScene/CzmlNumberSpec.js b/Specs/DynamicScene/CzmlNumberSpec.js deleted file mode 100644 index 5c143857c377..000000000000 --- a/Specs/DynamicScene/CzmlNumberSpec.js +++ /dev/null @@ -1,32 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlNumber' - ], function( - CzmlNumber) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleNumber = 0.5; - - var sampledNumberInterval = { - number : [1, 2, 3, 4] - }; - - it('unwrapInterval', function() { - expect(CzmlNumber.unwrapInterval(simpleNumber)).toEqual(simpleNumber); - expect(CzmlNumber.unwrapInterval(sampledNumberInterval)).toEqual(sampledNumberInterval.number); - }); - - it('isSampled', function() { - expect(CzmlNumber.isSampled(simpleNumber)).toEqual(false); - expect(CzmlNumber.isSampled(sampledNumberInterval.number)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlNumber.getValue(simpleNumber)).toEqual(simpleNumber); - }); - - it('getValueFromArray', function() { - expect(CzmlNumber.getValueFromArray(sampledNumberInterval.number, 2)).toEqual(sampledNumberInterval.number[2]); - }); -}); diff --git a/Specs/DynamicScene/CzmlPositionSpec.js b/Specs/DynamicScene/CzmlPositionSpec.js deleted file mode 100644 index ddf35d7885bc..000000000000 --- a/Specs/DynamicScene/CzmlPositionSpec.js +++ /dev/null @@ -1,75 +0,0 @@ -/*global defineSuite*/ -defineSuite(['DynamicScene/CzmlPosition', - 'Core/Cartesian3', - 'Core/Cartographic', - 'Core/Math', - 'Core/Ellipsoid' - ], function( - CzmlPosition, - Cartesian3, - Cartographic, - CesiumMath, - Ellipsoid) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var cartographic1 = new Cartographic(0, 1.0, 100); - var cartographic2 = new Cartographic(1.0, 0.0, 1500); - var cartesian1 = Ellipsoid.WGS84.cartographicToCartesian(cartographic1); - var cartesian2 = Ellipsoid.WGS84.cartographicToCartesian(cartographic2); - - var constantCartesianInterval = { - cartesian : [cartesian1.x, cartesian1.y, cartesian1.z] - }; - - var sampledCartesianInterval = { - cartesian : [0, cartesian1.x, cartesian1.y, cartesian1.z, 1, cartesian2.x, cartesian2.y, cartesian2.z] - }; - - var constantCartographicInterval = { - cartographicRadians : [cartographic1.longitude, cartographic1.latitude, cartographic1.height] - }; - - var constantCartographicDegreesInterval = { - cartographicDegrees : [CesiumMath.toDegrees(cartographic1.longitude), CesiumMath.toDegrees(cartographic1.latitude), cartographic1.height] - }; - - var sampledCartographicInterval = { - cartographicRadians : [0, cartographic1.longitude, cartographic1.latitude, cartographic1.height, 1, cartographic2.longitude, cartographic2.latitude, cartographic2.height] - }; - - var sampledCartographicDegreesInterval = { - cartographicDegrees : [0, CesiumMath.toDegrees(cartographic1.longitude), CesiumMath.toDegrees(cartographic1.latitude), cartographic1.height, 1, CesiumMath.toDegrees(cartographic2.longitude), - CesiumMath.toDegrees(cartographic2.latitude), cartographic2.height] - }; - - it('unwrapInterval', function() { - expect(CzmlPosition.unwrapInterval(constantCartesianInterval)).toEqual(constantCartesianInterval.cartesian); - expect(CzmlPosition.unwrapInterval(sampledCartesianInterval)).toEqual(sampledCartesianInterval.cartesian); - }); - - it('isSampled', function() { - expect(CzmlPosition.isSampled(constantCartesianInterval.cartesian)).toEqual(false); - expect(CzmlPosition.isSampled(sampledCartesianInterval.cartesian)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlPosition.getValue(constantCartesianInterval.cartesian)).toEqual(cartesian1); - }); - - it('getValueFromArray', function() { - expect(CzmlPosition.getValueFromArray(sampledCartesianInterval.cartesian, 5)).toEqual(cartesian2); - }); - - it('Cartographic unwrapInterval', function() { - expect(CzmlPosition.unwrapInterval(constantCartographicInterval)).toEqual(constantCartesianInterval.cartesian); - expect(CzmlPosition.unwrapInterval(constantCartographicDegreesInterval)).toEqual(constantCartesianInterval.cartesian); - expect(CzmlPosition.unwrapInterval(sampledCartographicInterval)).toEqual(sampledCartesianInterval.cartesian); - expect(CzmlPosition.unwrapInterval(sampledCartographicDegreesInterval)).toEqual(sampledCartesianInterval.cartesian); - }); - - it('Cartographic isSampled', function() { - expect(CzmlPosition.isSampled(constantCartographicInterval.cartographicRadians)).toEqual(false); - expect(CzmlPosition.isSampled(sampledCartographicInterval.cartographicRadians)).toEqual(true); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlStringSpec.js b/Specs/DynamicScene/CzmlStringSpec.js deleted file mode 100644 index 849ab726d130..000000000000 --- a/Specs/DynamicScene/CzmlStringSpec.js +++ /dev/null @@ -1,28 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlString' - ], function( - CzmlString) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleString = 'some Value'; - - var constantStringInterval = { - string : 'some other value' - }; - - it('unwrapInterval', function() { - expect(CzmlString.unwrapInterval(simpleString)).toEqual(simpleString); - expect(CzmlString.unwrapInterval(constantStringInterval)).toEqual(constantStringInterval.string); - }); - - it('isSampled', function() { - expect(CzmlString.isSampled()).toEqual(false); - }); - - it('getValue', function() { - expect(CzmlString.getValue(simpleString)).toEqual(simpleString); - expect(CzmlString.getValue(constantStringInterval.string)).toEqual(constantStringInterval.string); - }); -}); diff --git a/Specs/DynamicScene/CzmlUnitCartesian3Spec.js b/Specs/DynamicScene/CzmlUnitCartesian3Spec.js deleted file mode 100644 index 871e2088ad38..000000000000 --- a/Specs/DynamicScene/CzmlUnitCartesian3Spec.js +++ /dev/null @@ -1,41 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlUnitCartesian3', - 'Core/Cartesian3', - 'Core/Math' - ], function( - CzmlUnitCartesian3, - Cartesian3, - CesiumMath) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var cartesian1 = new Cartesian3(1, 2, 3).normalize(); - var cartesian2 = new Cartesian3(4, 5, 6).normalize(); - - var constantCartesianInterval = { - unitCartesian : [cartesian1.x, cartesian1.y, cartesian1.z] - }; - - var sampledCartesianInterval = { - unitCartesian : [0, cartesian1.x, cartesian1.y, cartesian1.z, 1, cartesian2.x, cartesian2.y, cartesian2.z] - }; - - it('unwrapInterval', function() { - expect(CzmlUnitCartesian3.unwrapInterval(constantCartesianInterval)).toEqual(constantCartesianInterval.unitCartesian); - expect(CzmlUnitCartesian3.unwrapInterval(sampledCartesianInterval)).toEqual(sampledCartesianInterval.unitCartesian); - }); - - it('isSampled', function() { - expect(CzmlUnitCartesian3.isSampled(constantCartesianInterval.unitCartesian)).toEqual(false); - expect(CzmlUnitCartesian3.isSampled(sampledCartesianInterval.unitCartesian)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlUnitCartesian3.getValue(constantCartesianInterval.unitCartesian)).toEqual(cartesian1); - }); - - it('getValueFromArray', function() { - expect(CzmlUnitCartesian3.getValueFromArray(sampledCartesianInterval.unitCartesian, 5)).toEqualEpsilon(cartesian2, CesiumMath.EPSILON15); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlUnitQuaternionSpec.js b/Specs/DynamicScene/CzmlUnitQuaternionSpec.js deleted file mode 100644 index f5a883abe2b4..000000000000 --- a/Specs/DynamicScene/CzmlUnitQuaternionSpec.js +++ /dev/null @@ -1,48 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlUnitQuaternion', - 'Core/Quaternion', - 'Core/Math' - ], function( - CzmlUnitQuaternion, - Quaternion, - CesiumMath) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var quaternion1 = new Quaternion(1, 2, 3, 4).normalize(); - var quaternion2 = new Quaternion(4, 5, 6, 7).normalize(); - - var constantQuaternionInterval = { - unitQuaternion : [quaternion1.x, quaternion1.y, quaternion1.z, quaternion1.w] - }; - - var sampledQuaternionInterval = { - unitQuaternion : [0, quaternion1.x, quaternion1.y, quaternion1.z, quaternion1.w, 1, quaternion2.x, quaternion2.y, quaternion2.z, quaternion2.w] - }; - - it('unwrapInterval', function() { - expect(CzmlUnitQuaternion.unwrapInterval(constantQuaternionInterval)).toEqual(constantQuaternionInterval.unitQuaternion); - expect(CzmlUnitQuaternion.unwrapInterval(sampledQuaternionInterval)).toEqual(sampledQuaternionInterval.unitQuaternion); - }); - - it('isSampled', function() { - expect(CzmlUnitQuaternion.isSampled(constantQuaternionInterval.unitQuaternion)).toEqual(false); - expect(CzmlUnitQuaternion.isSampled(sampledQuaternionInterval.unitQuaternion)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlUnitQuaternion.getValue(constantQuaternionInterval.unitQuaternion)).toEqualEpsilon(quaternion1, CesiumMath.EPSILON15); - }); - - it('getValueFromArray', function() { - expect(CzmlUnitQuaternion.getValueFromArray(sampledQuaternionInterval.unitQuaternion, 6)).toEqualEpsilon(quaternion2, CesiumMath.EPSILON15); - }); - - it('packValuesForInterpolation and getValueFromInterpolationResult', function() { - var destination = []; - var source = [quaternion1.x, quaternion1.y, quaternion1.z, quaternion1.w, quaternion2.x, quaternion2.y, quaternion2.z, quaternion2.w]; - CzmlUnitQuaternion.packValuesForInterpolation(source, destination, 0, 1); - expect(CzmlUnitQuaternion.getValueFromInterpolationResult(destination, undefined, source, 0, 1)).toEqualEpsilon(quaternion1, CesiumMath.EPSILON15); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlUnitSphericalSpec.js b/Specs/DynamicScene/CzmlUnitSphericalSpec.js deleted file mode 100644 index d4d14c57762a..000000000000 --- a/Specs/DynamicScene/CzmlUnitSphericalSpec.js +++ /dev/null @@ -1,41 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlUnitSpherical', - 'Core/Spherical', - 'Core/Math' - ], function( - CzmlUnitSpherical, - Spherical, - CesiumMath) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var spherical1 = new Spherical(2, 3, 1.0); - var spherical2 = new Spherical(4, 5, 1.0); - - var constantSphericalInterval = { - unitSpherical : [spherical1.clock, spherical1.cone] - }; - - var sampledSphericalInterval = { - unitSpherical : [0, spherical1.clock, spherical1.cone, 1, spherical2.clock, spherical2.cone] - }; - - it('unwrapInterval', function() { - expect(CzmlUnitSpherical.unwrapInterval(constantSphericalInterval)).toEqual(constantSphericalInterval.unitSpherical); - expect(CzmlUnitSpherical.unwrapInterval(sampledSphericalInterval)).toEqual(sampledSphericalInterval.unitSpherical); - }); - - it('isSampled', function() { - expect(CzmlUnitSpherical.isSampled(constantSphericalInterval.unitSpherical)).toEqual(false); - expect(CzmlUnitSpherical.isSampled(sampledSphericalInterval.unitSpherical)).toEqual(true); - }); - - it('getValue', function() { - expect(CzmlUnitSpherical.getValue(constantSphericalInterval.unitSpherical)).toEqual(spherical1); - }); - - it('getValueFromArray', function() { - expect(CzmlUnitSpherical.getValueFromArray(sampledSphericalInterval.unitSpherical, 4)).toEqual(spherical2); - }); -}); \ No newline at end of file diff --git a/Specs/DynamicScene/CzmlVerticalOriginSpec.js b/Specs/DynamicScene/CzmlVerticalOriginSpec.js deleted file mode 100644 index 2d151110651b..000000000000 --- a/Specs/DynamicScene/CzmlVerticalOriginSpec.js +++ /dev/null @@ -1,30 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/CzmlVerticalOrigin', - 'Scene/VerticalOrigin' - ], function( - CzmlVerticalOrigin, - VerticalOrigin) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var simpleVerticalOrigin = 'CENTER'; - - var constantVerticalOriginInterval = { - verticalOrigin : 'LEFT' - }; - - it('unwrapInterval', function() { - expect(CzmlVerticalOrigin.unwrapInterval(simpleVerticalOrigin)).toEqual(simpleVerticalOrigin); - expect(CzmlVerticalOrigin.unwrapInterval(constantVerticalOriginInterval)).toEqual(constantVerticalOriginInterval.verticalOrigin); - }); - - it('isSampled', function() { - expect(CzmlVerticalOrigin.isSampled()).toEqual(false); - }); - - it('getValue', function() { - expect(CzmlVerticalOrigin.getValue(simpleVerticalOrigin)).toEqual(VerticalOrigin.CENTER); - expect(CzmlVerticalOrigin.getValue(constantVerticalOriginInterval.verticalOrigin)).toEqual(VerticalOrigin.LEFT); - }); -}); diff --git a/Specs/DynamicScene/DynamicBillboardSpec.js b/Specs/DynamicScene/DynamicBillboardSpec.js index b98837750c22..2d7c03ca0156 100644 --- a/Specs/DynamicScene/DynamicBillboardSpec.js +++ b/Specs/DynamicScene/DynamicBillboardSpec.js @@ -22,96 +22,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite billboard.', function() { - var sourceUri = 'http://someImage.invalid/'; - var billboardPacket = { - billboard : { - image : 'image.png', - scale : 1.0, - horizontalOrigin : 'CENTER', - verticalOrigin : 'CENTER', - color : { - rgbaf : [1.0, 1.0, 1.0, 1.0] - }, - eyeOffset : { - cartesian : [3.0, 4.0, 5.0] - }, - pixelOffset : { - cartesian2 : [1.0, 2.0] - }, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicBillboard.processCzmlPacket(dynamicObject, billboardPacket, undefined, sourceUri)).toEqual(true); - - expect(dynamicObject.billboard).toBeDefined(); - expect(dynamicObject.billboard.image.getValue(Iso8601.MINIMUM_VALUE)).toEqual(sourceUri + 'image.png'); - expect(dynamicObject.billboard.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(billboardPacket.billboard.scale); - expect(dynamicObject.billboard.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.CENTER); - expect(dynamicObject.billboard.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); - expect(dynamicObject.billboard.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); - expect(dynamicObject.billboard.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); - expect(dynamicObject.billboard.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(1.0, 2.0)); - expect(dynamicObject.billboard.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained billboard.', function() { - var billboardPacket = { - billboard : { - interval : '2000-01-01/2001-01-01', - image : 'http://someImage.invalid/image', - scale : 1.0, - horizontalOrigin : 'CENTER', - verticalOrigin : 'CENTER', - color : { - rgbaf : [1.0, 1.0, 1.0, 1.0] - }, - eyeOffset : { - cartesian : [3.0, 4.0, 5.0] - }, - pixelOffset : { - cartesian2 : [1.0, 2.0] - }, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(billboardPacket.billboard.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicBillboard.processCzmlPacket(dynamicObject, billboardPacket)).toEqual(true); - - expect(dynamicObject.billboard).toBeDefined(); - expect(dynamicObject.billboard.image.getValue(validTime)).toEqual(billboardPacket.billboard.image); - expect(dynamicObject.billboard.scale.getValue(validTime)).toEqual(billboardPacket.billboard.scale); - expect(dynamicObject.billboard.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.CENTER); - expect(dynamicObject.billboard.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); - expect(dynamicObject.billboard.color.getValue(validTime)).toEqual(new Color(1.0, 1.0, 1.0, 1.0)); - expect(dynamicObject.billboard.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(3.0, 4.0, 5.0)); - expect(dynamicObject.billboard.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(1.0, 2.0)); - expect(dynamicObject.billboard.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.billboard).toBeDefined(); - expect(dynamicObject.billboard.image.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.scale.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.horizontalOrigin.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.verticalOrigin.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.color.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.eyeOffset.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.pixelOffset.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.billboard.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicBillboard.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.billboard).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured billboard', function() { var expectedImage = 'image'; var expectedScale = 'scale'; diff --git a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js index 8480c464b7ae..d07086aeee9f 100644 --- a/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicBillboardVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicBillboardVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicBillboard', 'DynamicScene/DynamicObjectCollection', 'DynamicScene/DynamicObject', @@ -19,7 +19,7 @@ defineSuite([ DynamicBillboardVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, DynamicBillboard, DynamicObjectCollection, DynamicObject, @@ -90,7 +90,7 @@ defineSuite([ visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); visualizer.update(new JulianDate()); var billboardCollection = scene.getPrimitives().get(0); expect(billboardCollection.getLength()).toEqual(0); @@ -102,8 +102,8 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var billboard = testObject.billboard = new DynamicBillboard(); - billboard.show = new MockProperty(true); - billboard.image = new MockProperty('Data/Images/Blue.png'); + billboard.show = new ConstantProperty(true); + billboard.image = new ConstantProperty('Data/Images/Blue.png'); visualizer.update(new JulianDate()); var billboardCollection = scene.getPrimitives().get(0); @@ -115,9 +115,9 @@ defineSuite([ visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var billboard = testObject.billboard = new DynamicBillboard(); - billboard.show = new MockProperty(true); + billboard.show = new ConstantProperty(true); visualizer.update(new JulianDate()); var billboardCollection = scene.getPrimitives().get(0); @@ -138,17 +138,17 @@ defineSuite([ var bb; runs(function() { - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - billboard.show = new MockProperty(true); - billboard.color = new MockProperty(new Color(0.5, 0.5, 0.5, 0.5)); - billboard.image = new MockProperty('Data/Images/Blue.png'); - billboard.eyeOffset = new MockProperty(new Cartesian3(1.0, 2.0, 3.0)); - billboard.scale = new MockProperty(12.5); - billboard.rotation = new MockProperty(1.5); - billboard.alignedAxis = new MockProperty(Cartesian3.UNIT_Z); - billboard.horizontalOrigin = new MockProperty(HorizontalOrigin.RIGHT); - billboard.verticalOrigin = new MockProperty(VerticalOrigin.TOP); - billboard.pixelOffset = new MockProperty(new Cartesian2(3, 2)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + billboard.show = new ConstantProperty(true); + billboard.color = new ConstantProperty(new Color(0.5, 0.5, 0.5, 0.5)); + billboard.image = new ConstantProperty('Data/Images/Blue.png'); + billboard.eyeOffset = new ConstantProperty(new Cartesian3(1.0, 2.0, 3.0)); + billboard.scale = new ConstantProperty(12.5); + billboard.rotation = new ConstantProperty(1.5); + billboard.alignedAxis = new ConstantProperty(Cartesian3.UNIT_Z); + billboard.horizontalOrigin = new ConstantProperty(HorizontalOrigin.RIGHT); + billboard.verticalOrigin = new ConstantProperty(VerticalOrigin.TOP); + billboard.pixelOffset = new ConstantProperty(new Cartesian2(3, 2)); visualizer.update(time); @@ -159,7 +159,7 @@ defineSuite([ waitsFor(function() { visualizer.update(time); if (bb.getShow()) { - expect(bb.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(bb.getPosition()).toEqual(testObject.position.getValue(time)); expect(bb.getColor()).toEqual(testObject.billboard.color.getValue(time)); expect(bb.getEyeOffset()).toEqual(testObject.billboard.eyeOffset.getValue(time)); expect(bb.getScale()).toEqual(testObject.billboard.scale.getValue(time)); @@ -174,23 +174,23 @@ defineSuite([ }); runs(function() { - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1293434)); - billboard.show = new MockProperty(true); - billboard.color = new MockProperty(new Color(0.15, 0.25, 0.35, 0.45)); - billboard.image = new MockProperty('Data/Images/Green.png'); - billboard.eyeOffset = new MockProperty(new Cartesian3(2.0, 3.0, 1.0)); - billboard.scale = new MockProperty(2.5); - billboard.rotation = new MockProperty(2.9); - billboard.alignedAxis = new MockProperty(Cartesian3.UNIT_Y); - billboard.horizontalOrigin = new MockProperty(HorizontalOrigin.LEFT); - billboard.verticalOrigin = new MockProperty(VerticalOrigin.BOTTOM); - billboard.pixelOffset = new MockProperty(new Cartesian2(2, 3)); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1293434)); + billboard.show = new ConstantProperty(true); + billboard.color = new ConstantProperty(new Color(0.15, 0.25, 0.35, 0.45)); + billboard.image = new ConstantProperty('Data/Images/Green.png'); + billboard.eyeOffset = new ConstantProperty(new Cartesian3(2.0, 3.0, 1.0)); + billboard.scale = new ConstantProperty(2.5); + billboard.rotation = new ConstantProperty(2.9); + billboard.alignedAxis = new ConstantProperty(Cartesian3.UNIT_Y); + billboard.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT); + billboard.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM); + billboard.pixelOffset = new ConstantProperty(new Cartesian2(2, 3)); waitsFor(function() { visualizer.update(time); var imageReady = bb.getImageIndex() === 1; //true once the green image is loaded if (imageReady) { - expect(bb.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(bb.getPosition()).toEqual(testObject.position.getValue(time)); expect(bb.getColor()).toEqual(testObject.billboard.color.getValue(time)); expect(bb.getEyeOffset()).toEqual(testObject.billboard.eyeOffset.getValue(time)); expect(bb.getScale()).toEqual(testObject.billboard.scale.getValue(time)); @@ -205,7 +205,7 @@ defineSuite([ }); runs(function() { - billboard.show = new MockProperty(false); + billboard.show = new ConstantProperty(false); waitsFor(function() { visualizer.update(time); @@ -226,9 +226,9 @@ defineSuite([ var time = new JulianDate(); var billboard = testObject.billboard = new DynamicBillboard(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - billboard.show = new MockProperty(true); - billboard.image = new MockProperty('Data/Images/Blue.png'); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + billboard.show = new ConstantProperty(true); + billboard.image = new ConstantProperty('Data/Images/Blue.png'); visualizer.update(time); expect(billboardCollection.getLength()).toEqual(1); var bb = billboardCollection.get(0); @@ -258,9 +258,9 @@ defineSuite([ var time = new JulianDate(); var billboard = testObject.billboard = new DynamicBillboard(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - billboard.show = new MockProperty(true); - billboard.image = new MockProperty('Data/Images/Blue.png'); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + billboard.show = new ConstantProperty(true); + billboard.image = new ConstantProperty('Data/Images/Blue.png'); visualizer.update(time); expect(billboardCollection.getLength()).toEqual(1); var bb = billboardCollection.get(0); @@ -270,17 +270,17 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.billboard = new DynamicBillboard(); - testObject.billboard.show = new MockProperty(true); - testObject.billboard.image = new MockProperty('Data/Images/Blue.png'); + testObject.billboard.show = new ConstantProperty(true); + testObject.billboard.image = new ConstantProperty('Data/Images/Blue.png'); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); testObject2.billboard = new DynamicBillboard(); - testObject2.billboard.show = new MockProperty(true); - testObject2.billboard.image = new MockProperty('Data/Images/Green.png'); + testObject2.billboard.show = new ConstantProperty(true); + testObject2.billboard.image = new ConstantProperty('Data/Images/Green.png'); visualizer = new DynamicBillboardVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicClockSpec.js b/Specs/DynamicScene/DynamicClockSpec.js index 71b57e27ba8c..f4f10bc59fab 100644 --- a/Specs/DynamicScene/DynamicClockSpec.js +++ b/Specs/DynamicScene/DynamicClockSpec.js @@ -16,122 +16,58 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var clockPacket = { - clock : { - interval : '2012-03-15T10:00:00Z/2012-03-16T10:00:00Z', - currentTime : '2012-03-15T10:00:00Z', - multiplier : 60.0, - range : 'LOOP_STOP', - step : 'SYSTEM_CLOCK_MULTIPLIER' - } - }; - - var interval = TimeInterval.fromIso8601(clockPacket.clock.interval); - var currentTime = JulianDate.fromIso8601(clockPacket.clock.currentTime); - var multiplier = clockPacket.clock.multiplier; - var range = ClockRange[clockPacket.clock.range]; - var step = ClockStep[clockPacket.clock.step]; - - it('processCzmlPacket adds clock data.', function() { - var dynamicObject = new DynamicObject('document'); - expect(DynamicClock.processCzmlPacket(dynamicObject, clockPacket)).toEqual(true); - expect(dynamicObject.clock).toBeDefined(); - expect(dynamicObject.clock.startTime).toEqual(interval.start); - expect(dynamicObject.clock.stopTime).toEqual(interval.stop); - expect(dynamicObject.clock.currentTime).toEqual(currentTime); - expect(dynamicObject.clock.clockRange).toEqual(range); - expect(dynamicObject.clock.clockStep).toEqual(step); - expect(dynamicObject.clock.multiplier).toEqual(multiplier); - }); - - it('processCzmlPacket only adds data on the document.', function() { - var clockPacket = { - clock : { - interval : "2012-03-15T10:00:00Z/2012-03-16T10:00:00Z", - currentTime : "2012-03-15T10:00:00Z", - multiplier : 60.0, - range : "LOOP_STOP", - step : "SYSTEM_CLOCK_MULTIPLIER" - } - }; - - var documentObject = new DynamicObject('document'); - var dynamicObject = new DynamicObject('notTheDocument'); - expect(DynamicClock.processCzmlPacket(dynamicObject, clockPacket)).toEqual(false); - expect(dynamicObject.clock).toBeUndefined(); - expect(DynamicClock.processCzmlPacket(documentObject, clockPacket)).toEqual(true); - expect(documentObject.clock).toBeDefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('document'); - expect(DynamicClock.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.clock).toBeUndefined(); - }); - it('mergeProperties creates a clock', function() { - var objectToMerge = new DynamicObject('document'); - DynamicClock.processCzmlPacket(objectToMerge, clockPacket); + var clockToMerge = new DynamicObject('1'); + clockToMerge.startTime = new JulianDate(); + clockToMerge.stopTime = new JulianDate(); + clockToMerge.currentTime = new JulianDate(); + clockToMerge.clockRange = ClockRange.CLAMPED; + clockToMerge.clockStep = ClockStep.TICK_DEPENDENT; + clockToMerge.multiplier = 1; + var objectToMerge = new DynamicObject('objectToMerge'); + objectToMerge.clock = clockToMerge; var targetObject = new DynamicObject('targetObject'); DynamicClock.mergeProperties(targetObject, objectToMerge); - expect(targetObject.clock).toBeDefined(); - expect(targetObject.clock.startTime).toEqual(objectToMerge.clock.startTime); - expect(targetObject.clock.stopTime).toEqual(objectToMerge.clock.stopTime); - expect(targetObject.clock.currentTime).toEqual(objectToMerge.clock.currentTime); - expect(targetObject.clock.clockRange).toEqual(objectToMerge.clock.clockRange); - expect(targetObject.clock.clockStep).toEqual(objectToMerge.clock.clockStep); - expect(targetObject.clock.multiplier).toEqual(objectToMerge.clock.multiplier); - }); - - it('mergeProperties does not overwrite the target clock if the merging object clock is undefined', function() { - var objectToMerge = new DynamicObject('document'); - - var targetObject = new DynamicObject('document'); - DynamicClock.processCzmlPacket(targetObject, clockPacket); - - DynamicClock.mergeProperties(targetObject, objectToMerge); - expect(targetObject.clock).toBeDefined(); - expect(targetObject.clock.startTime).toEqual(interval.start); - expect(targetObject.clock.stopTime).toEqual(interval.stop); - expect(targetObject.clock.currentTime).toEqual(currentTime); - expect(targetObject.clock.clockRange).toEqual(range); - expect(targetObject.clock.clockStep).toEqual(step); - expect(targetObject.clock.multiplier).toEqual(multiplier); + var targetClock = targetObject.clock; + expect(targetClock).toBeInstanceOf(DynamicClock); + expect(targetClock.startTime).toEqual(clockToMerge.startTime); + expect(targetClock.stopTime).toEqual(clockToMerge.stopTime); + expect(targetClock.currentTime).toEqual(clockToMerge.currentTime); + expect(targetClock.clockRange).toEqual(clockToMerge.clockRange); + expect(targetClock.clockStep).toEqual(clockToMerge.clockStep); + expect(targetClock.multiplier).toEqual(clockToMerge.multiplier); }); it('mergeProperties always overwrites the target clock with mergeObject clock if it has one', function() { - var objectToMerge = new DynamicObject('document'); - DynamicClock.processCzmlPacket(objectToMerge, clockPacket); - - var targetObject = new DynamicObject('document'); - var clockPacket2 = { - clock : { - interval : '2013-03-15T10:00:00Z/2014-03-16T10:00:00Z', - currentTime : '2013-03-15T10:00:00Z', - multiplier : 65.0, - range : 'CLAMPED', - step : 'SYSTEM_CLOCK' - } - }; - - DynamicClock.processCzmlPacket(targetObject, clockPacket2); - expect(targetObject.clock.startTime).toNotEqual(objectToMerge.clock.startTime); - expect(targetObject.clock.stopTime).toNotEqual(objectToMerge.clock.stopTime); - expect(targetObject.clock.currentTime).toNotEqual(objectToMerge.clock.currentTime); - expect(targetObject.clock.clockRange).toNotEqual(objectToMerge.clock.clockRange); - expect(targetObject.clock.clockStep).toNotEqual(objectToMerge.clock.clockStep); - expect(targetObject.clock.multiplier).toNotEqual(objectToMerge.clock.multiplier); + var clockToMerge = new DynamicObject('1'); + clockToMerge.startTime = new JulianDate(); + clockToMerge.stopTime = new JulianDate(); + clockToMerge.currentTime = new JulianDate(); + clockToMerge.clockRange = ClockRange.CLAMPED; + clockToMerge.clockStep = ClockStep.TICK_DEPENDENT; + clockToMerge.multiplier = 1; + var objectToMerge = new DynamicObject('objectToMerge'); + objectToMerge.clock = clockToMerge; + + var targetClock = new DynamicClock(); + targetClock.startTime = new JulianDate(); + targetClock.stopTime = new JulianDate(); + targetClock.currentTime = new JulianDate(); + targetClock.clockRange = ClockRange.UNBOUNDED; + targetClock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER; + targetClock.multiplier = 2; + var targetObject = new DynamicObject('targetObject'); + targetObject.clock = targetClock; DynamicClock.mergeProperties(targetObject, objectToMerge); - expect(targetObject.clock.startTime).toEqual(objectToMerge.clock.startTime); - expect(targetObject.clock.stopTime).toEqual(objectToMerge.clock.stopTime); - expect(targetObject.clock.currentTime).toEqual(objectToMerge.clock.currentTime); - expect(targetObject.clock.clockRange).toEqual(objectToMerge.clock.clockRange); - expect(targetObject.clock.clockStep).toEqual(objectToMerge.clock.clockStep); - expect(targetObject.clock.multiplier).toEqual(objectToMerge.clock.multiplier); + expect(targetClock.startTime).toEqual(clockToMerge.startTime); + expect(targetClock.stopTime).toEqual(clockToMerge.stopTime); + expect(targetClock.currentTime).toEqual(clockToMerge.currentTime); + expect(targetClock.clockRange).toEqual(clockToMerge.clockRange); + expect(targetClock.clockStep).toEqual(clockToMerge.clockStep); + expect(targetClock.multiplier).toEqual(clockToMerge.multiplier); }); it('undefineProperties works', function() { diff --git a/Specs/DynamicScene/DynamicConeSpec.js b/Specs/DynamicScene/DynamicConeSpec.js index be18003734ea..911fdccc3105 100644 --- a/Specs/DynamicScene/DynamicConeSpec.js +++ b/Specs/DynamicScene/DynamicConeSpec.js @@ -14,159 +14,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite cone.', function() { - var conePacket = { - cone : { - innerHalfAngle : 1.0, - outerHalfAngle : 1.1, - minimumClockAngle : 1.2, - maximumClockAngle : 1.3, - radius : 2.0, - show : true, - showIntersection : false, - intersectionWidth : 6.0, - capMaterial : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - innerMaterial : { - solidColor : { - color : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - } - } - }, - outerMaterial : { - solidColor : { - color : { - rgbaf : [0.3, 0.3, 0.3, 0.3] - } - } - }, - silhouetteMaterial : { - solidColor : { - color : { - rgbaf : [0.4, 0.4, 0.4, 0.4] - } - } - }, - intersectionColor : { - rgbaf : [0.5, 0.5, 0.5, 0.5] - } - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicCone.processCzmlPacket(dynamicObject, conePacket)).toEqual(true); - - expect(dynamicObject.cone).toBeDefined(); - expect(dynamicObject.cone.innerHalfAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.innerHalfAngle); - expect(dynamicObject.cone.outerHalfAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.outerHalfAngle); - expect(dynamicObject.cone.minimumClockAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.minimumClockAngle); - expect(dynamicObject.cone.maximumClockAngle.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.maximumClockAngle); - expect(dynamicObject.cone.radius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.radius); - expect(dynamicObject.cone.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.show); - expect(dynamicObject.cone.showIntersection.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.showIntersection); - expect(dynamicObject.cone.capMaterial.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.cone.innerMaterial.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.cone.outerMaterial.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.3, 0.3, 0.3, 0.3)); - expect(dynamicObject.cone.silhouetteMaterial.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.4, 0.4, 0.4, 0.4)); - expect(dynamicObject.cone.intersectionColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); - expect(dynamicObject.cone.intersectionWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(conePacket.cone.intersectionWidth); - }); - - it('processCzmlPacket adds data for constrained cone.', function() { - var conePacket = { - cone : { - interval : '2000-01-01/2001-01-01', - innerHalfAngle : 1.0, - outerHalfAngle : 1.1, - minimumClockAngle : 1.2, - maximumClockAngle : 1.3, - radius : 2.0, - show : true, - showIntersection : false, - intersectionWidth : 4.0, - capMaterial : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - innerMaterial : { - solidColor : { - color : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - } - } - }, - outerMaterial : { - solidColor : { - color : { - rgbaf : [0.3, 0.3, 0.3, 0.3] - } - } - }, - silhouetteMaterial : { - solidColor : { - color : { - rgbaf : [0.4, 0.4, 0.4, 0.4] - } - } - }, - intersectionColor : { - rgbaf : [0.5, 0.5, 0.5, 0.5] - } - } - }; - - var validTime = TimeInterval.fromIso8601(conePacket.cone.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicCone.processCzmlPacket(dynamicObject, conePacket)).toEqual(true); - - expect(dynamicObject.cone).toBeDefined(); - expect(dynamicObject.cone.innerHalfAngle.getValue(validTime)).toEqual(conePacket.cone.innerHalfAngle); - expect(dynamicObject.cone.outerHalfAngle.getValue(validTime)).toEqual(conePacket.cone.outerHalfAngle); - expect(dynamicObject.cone.minimumClockAngle.getValue(validTime)).toEqual(conePacket.cone.minimumClockAngle); - expect(dynamicObject.cone.maximumClockAngle.getValue(validTime)).toEqual(conePacket.cone.maximumClockAngle); - expect(dynamicObject.cone.radius.getValue(validTime)).toEqual(conePacket.cone.radius); - expect(dynamicObject.cone.show.getValue(validTime)).toEqual(conePacket.cone.show); - expect(dynamicObject.cone.showIntersection.getValue(validTime)).toEqual(conePacket.cone.showIntersection); - expect(dynamicObject.cone.capMaterial.getValue(validTime).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.cone.innerMaterial.getValue(validTime).uniforms.color).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.cone.outerMaterial.getValue(validTime).uniforms.color).toEqual(new Color(0.3, 0.3, 0.3, 0.3)); - expect(dynamicObject.cone.silhouetteMaterial.getValue(validTime).uniforms.color).toEqual(new Color(0.4, 0.4, 0.4, 0.4)); - expect(dynamicObject.cone.intersectionColor.getValue(validTime)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); - expect(dynamicObject.cone.intersectionWidth.getValue(validTime)).toEqual(conePacket.cone.intersectionWidth); - - expect(dynamicObject.cone.innerHalfAngle.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.outerHalfAngle.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.minimumClockAngle.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.maximumClockAngle.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.radius.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.show.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.showIntersection.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.capMaterial.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.innerMaterial.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.outerMaterial.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.silhouetteMaterial.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.intersectionColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.cone.intersectionWidth.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicCone.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.cone).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured cone', function() { var expectedCapMaterial = 13; var expectedInnerHalfAngle = 14; diff --git a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js index 283d5ae446c1..accb3a6e211f 100644 --- a/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js +++ b/Specs/DynamicScene/DynamicConeVisualizerUsingCustomSensorSpec.js @@ -5,11 +5,11 @@ defineSuite([ 'Core/Matrix4', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicCone', 'DynamicScene/DynamicObjectCollection', 'DynamicScene/DynamicObject', - 'Scene/Material', + 'DynamicScene/ColorMaterialProperty', 'Core/JulianDate', 'Core/Quaternion', 'Core/Cartesian3', @@ -22,11 +22,11 @@ defineSuite([ Matrix4, createScene, destroyScene, - MockProperty, + ConstantProperty, DynamicCone, DynamicObjectCollection, DynamicObject, - Material, + ColorMaterialProperty, JulianDate, Quaternion, Cartesian3, @@ -90,8 +90,8 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -101,10 +101,10 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new MockProperty(1); - cone.outerHalfAngle = new MockProperty(1); + cone.maximumClockAngle = new ConstantProperty(1); + cone.outerHalfAngle = new ConstantProperty(1); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -114,10 +114,10 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new MockProperty(1); - cone.outerHalfAngle = new MockProperty(1); + cone.maximumClockAngle = new ConstantProperty(1); + cone.outerHalfAngle = new ConstantProperty(1); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -128,23 +128,21 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.minimumClockAngle = new MockProperty(0.1); - cone.maximumClockAngle = new MockProperty(0.2); - cone.innerHalfAngle = new MockProperty(0.3); - cone.outerHalfAngle = new MockProperty(0.4); - cone.intersectionColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - cone.intersectionWidth = new MockProperty(0.5); - cone.showIntersection = new MockProperty(true); - cone.radius = new MockProperty(123.5); - cone.show = new MockProperty(true); - - var blueMaterial = Material.fromType(scene.getContext(), Material.ColorType); - blueMaterial.uniforms.color = Color.BLUE; - cone.outerMaterial = new MockProperty(blueMaterial); + cone.minimumClockAngle = new ConstantProperty(0.1); + cone.maximumClockAngle = new ConstantProperty(0.2); + cone.innerHalfAngle = new ConstantProperty(0.3); + cone.outerHalfAngle = new ConstantProperty(0.4); + cone.intersectionColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + cone.intersectionWidth = new ConstantProperty(0.5); + cone.showIntersection = new ConstantProperty(true); + cone.radius = new ConstantProperty(123.5); + cone.show = new ConstantProperty(true); + + cone.outerMaterial = new ColorMaterialProperty(); visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -158,8 +156,8 @@ defineSuite([ expect(c.showIntersection).toEqual(testObject.cone.showIntersection.getValue(time)); expect(c.radius).toEqual(testObject.cone.radius.getValue(time)); expect(c.show).toEqual(testObject.cone.show.getValue(time)); - expect(c.material).toEqual(testObject.cone.outerMaterial.getValue(time)); - expect(c.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValueCartesian(time))); + expect(c.material.uniforms).toEqual(testObject.cone.outerMaterial.getValue(time)); + expect(c.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValue(time))); cone.show.value = false; visualizer.update(time); @@ -172,18 +170,18 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var testObject2 = dynamicObjectCollection.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject2.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject2.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject2.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.intersectionColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); + cone.intersectionColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); var cone2 = testObject2.cone = new DynamicCone(); - cone2.intersectionColor = new MockProperty(new Color(0.4, 0.3, 0.2, 0.1)); + cone2.intersectionColor = new ConstantProperty(new Color(0.4, 0.3, 0.2, 0.1)); visualizer.update(time); @@ -201,8 +199,8 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); testObject.cone = new DynamicCone(); visualizer.update(time); @@ -222,11 +220,11 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new MockProperty(1); - cone.outerHalfAngle = new MockProperty(1); + cone.maximumClockAngle = new ConstantProperty(1); + cone.outerHalfAngle = new ConstantProperty(1); var time = new JulianDate(); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -244,11 +242,11 @@ defineSuite([ visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new MockProperty(1); - cone.outerHalfAngle = new MockProperty(1); + cone.maximumClockAngle = new ConstantProperty(1); + cone.outerHalfAngle = new ConstantProperty(1); var time = new JulianDate(); visualizer.update(time); @@ -258,19 +256,19 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var cone = testObject.cone = new DynamicCone(); - cone.maximumClockAngle = new MockProperty(1); - cone.outerHalfAngle = new MockProperty(1); + cone.maximumClockAngle = new ConstantProperty(1); + cone.outerHalfAngle = new ConstantProperty(1); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.orientation = new MockProperty(new Quaternion(1, 0, 0, 0)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.orientation = new ConstantProperty(new Quaternion(1, 0, 0, 0)); var cone2 = testObject2.cone = new DynamicCone(); - cone2.maximumClockAngle = new MockProperty(0.12); - cone2.outerHalfAngle = new MockProperty(1.1); + cone2.maximumClockAngle = new ConstantProperty(0.12); + cone2.outerHalfAngle = new ConstantProperty(1.1); visualizer = new DynamicConeVisualizerUsingCustomSensor(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicDirectionsPropertySpec.js b/Specs/DynamicScene/DynamicDirectionsPropertySpec.js index 4b1f2256043e..5c8ac4d5a862 100644 --- a/Specs/DynamicScene/DynamicDirectionsPropertySpec.js +++ b/Specs/DynamicScene/DynamicDirectionsPropertySpec.js @@ -12,120 +12,65 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var sphericalInterval = { - unitSpherical : [0.1, 0.2, 0.3, 0.4, 0.5, 0.6] - }; - - var cartesianInterval = { - unitCartesian : [1, 0, 0, 0, 1, 0, 0, 0, 1] - }; + var sphericals; + var cartesians; + var sphericalInterval; + var cartesianInterval; + + beforeAll(function() { + cartesians = [new Cartesian3(1, 0, 0), new Cartesian3(0, 1, 0), new Cartesian3(0, 0, 1)]; + sphericals = [Spherical.fromCartesian3(cartesians[0]), Spherical.fromCartesian3(cartesians[1]), Spherical.fromCartesian3(cartesians[2])]; + + sphericalInterval = { + unitSpherical : [sphericals[0].clock, sphericals[0].cone, sphericals[1].clock, sphericals[1].cone, sphericals[2].clock, sphericals[2].cone] + }; + + cartesianInterval = { + unitCartesian : [cartesians[0].x, cartesians[0].y, cartesians[0].z, cartesians[1].x, cartesians[1].y, cartesians[1].z, cartesians[2].x, cartesians[2].y, cartesians[2].z] + }; + }); - it('getValueCartesian returns undefined if no data exists', function() { + it('getValue returns undefined if no data exists', function() { var property = new DynamicDirectionsProperty(); - expect(property.getValueCartesian(new JulianDate())).toBeUndefined(); + expect(property.getValue(new JulianDate())).toBeUndefined(); }); - it('getValueCartesian throw if no time supplied', function() { + it('getValue throw if no time supplied', function() { var property = new DynamicDirectionsProperty(); expect(function() { - property.getValueCartesian(); + property.getValue(); }).toThrow(); }); - it('getValueCartesian works for cartesian data', function() { + it('getValue works for cartesian data', function() { var property = new DynamicDirectionsProperty(); property.processCzmlIntervals(cartesianInterval); - var result = property.getValueCartesian(new JulianDate()); - expect(result.length).toEqual(3); - expect(result[0].x).toEqual(cartesianInterval.unitCartesian[0]); - expect(result[0].y).toEqual(cartesianInterval.unitCartesian[1]); - expect(result[0].z).toEqual(cartesianInterval.unitCartesian[2]); - - expect(result[1].x).toEqual(cartesianInterval.unitCartesian[3]); - expect(result[1].y).toEqual(cartesianInterval.unitCartesian[4]); - expect(result[1].z).toEqual(cartesianInterval.unitCartesian[5]); - - expect(result[2].x).toEqual(cartesianInterval.unitCartesian[6]); - expect(result[2].y).toEqual(cartesianInterval.unitCartesian[7]); - expect(result[2].z).toEqual(cartesianInterval.unitCartesian[8]); + var result = property.getValue(new JulianDate()); + expect(result.length).toEqual(cartesians.length); + expect(result[0]).toEqual(sphericals[0]); + expect(result[1]).toEqual(sphericals[1]); + expect(result[2]).toEqual(sphericals[2]); }); - it('getValueCartesian works for spherical data', function() { + it('getValue works for spherical data', function() { var property = new DynamicDirectionsProperty(); property.processCzmlIntervals(sphericalInterval); - var result = property.getValueCartesian(new JulianDate()); - - var expected = property.getValueSpherical(new JulianDate()); - for ( var i = expected.length - 1; i > -1; i--) { - expected[i] = Cartesian3.fromSpherical(expected[i]); - } - - expect(result.length).toEqual(3); - expect(result[0].x).toEqual(expected[0].x); - expect(result[0].y).toEqual(expected[0].y); - expect(result[0].z).toEqual(expected[0].z); - - expect(result[1].x).toEqual(expected[1].x); - expect(result[1].y).toEqual(expected[1].y); - expect(result[1].z).toEqual(expected[1].z); - - expect(result[2].x).toEqual(expected[2].x); - expect(result[2].y).toEqual(expected[2].y); - expect(result[2].z).toEqual(expected[2].z); - }); - - it('getValueSpherical works for cartesian data', function() { - var property = new DynamicDirectionsProperty(); - property.processCzmlIntervals(cartesianInterval); - var result = property.getValueSpherical(new JulianDate()); - - var expected = property.getValueCartesian(new JulianDate()); - for ( var i = expected.length - 1; i > -1; i--) { - expected[i] = Spherical.fromCartesian3(expected[i]); - } - - expect(result.length).toEqual(3); - expect(result[0].clock).toEqual(expected[0].clock); - expect(result[0].cone).toEqual(expected[0].cone); - expect(result[0].magnitude).toEqual(expected[0].magnitude); - - expect(result[1].clock).toEqual(expected[1].clock); - expect(result[1].cone).toEqual(expected[1].cone); - expect(result[1].magnitude).toEqual(expected[1].magnitude); - - expect(result[2].clock).toEqual(expected[2].clock); - expect(result[2].cone).toEqual(expected[2].cone); - expect(result[2].magnitude).toEqual(expected[2].magnitude); - }); - - it('getValueSpherical works for spherical data', function() { - var property = new DynamicDirectionsProperty(); - property.processCzmlIntervals(sphericalInterval); - var result = property.getValueSpherical(new JulianDate()); - - expect(result.length).toEqual(3); - expect(result[0].clock).toEqual(sphericalInterval.unitSpherical[0]); - expect(result[0].cone).toEqual(sphericalInterval.unitSpherical[1]); - expect(result[0].magnitude).toEqual(1.0); - - expect(result[1].clock).toEqual(sphericalInterval.unitSpherical[2]); - expect(result[1].cone).toEqual(sphericalInterval.unitSpherical[3]); - expect(result[1].magnitude).toEqual(1.0); - - expect(result[2].clock).toEqual(sphericalInterval.unitSpherical[4]); - expect(result[2].cone).toEqual(sphericalInterval.unitSpherical[5]); - expect(result[2].magnitude).toEqual(1.0); + var result = property.getValue(new JulianDate()); + expect(result.length).toEqual(sphericals.length); + expect(result[0]).toEqual(sphericals[0]); + expect(result[1]).toEqual(sphericals[1]); + expect(result[2]).toEqual(sphericals[2]); }); - it('getValueSpherical returns undefined if no data exists', function() { + it('getValue returns undefined if no data exists', function() { var property = new DynamicDirectionsProperty(); - expect(property.getValueSpherical(new JulianDate())).toBeUndefined(); + expect(property.getValue(new JulianDate())).toBeUndefined(); }); - it('getValueSpherical throws if no time supplied', function() { + it('getValue throws if no time supplied', function() { var property = new DynamicDirectionsProperty(); expect(function() { - property.getValueSpherical(); + property.getValue(); }).toThrow(); }); }); diff --git a/Specs/DynamicScene/DynamicEllipseSpec.js b/Specs/DynamicScene/DynamicEllipseSpec.js index 0a76fcf16817..cc70a662b0a2 100644 --- a/Specs/DynamicScene/DynamicEllipseSpec.js +++ b/Specs/DynamicScene/DynamicEllipseSpec.js @@ -8,7 +8,8 @@ defineSuite([ 'Core/Cartesian3', 'Core/Iso8601', 'Core/TimeInterval', - 'Specs/MockProperty' + 'DynamicScene/ConstantProperty', + 'Specs/UndefinedProperty' ], function( DynamicEllipse, DynamicObject, @@ -18,72 +19,23 @@ defineSuite([ Cartesian3, Iso8601, TimeInterval, - MockProperty) { + ConstantProperty, + UndefinedProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ var position = new Cartesian3(1234, 5678, 9101112); - var ellipsePacket = { - ellipse : { - semiMajorAxis : 10, - semiMinorAxis : 20, - bearing : 1.0 - } - }; - - var ellipsePacketInterval = { - ellipse : { - interval : '2000-01-01/2001-01-01', - semiMajorAxis : 10, - semiMinorAxis : 20, - bearing : 1.0 - } - }; - - it('processCzmlPacket adds data for infinite ellipse.', function() { - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipse.processCzmlPacket(dynamicObject, ellipsePacket)).toEqual(true); - expect(dynamicObject.ellipse).toBeDefined(); - expect(dynamicObject.ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMajorAxis); - expect(dynamicObject.ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.semiMinorAxis); - expect(dynamicObject.ellipse.bearing.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsePacket.ellipse.bearing); - }); - - it('processCzmlPacket adds data for constrained ellipse.', function() { - var validTime = TimeInterval.fromIso8601(ellipsePacketInterval.ellipse.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipse.processCzmlPacket(dynamicObject, ellipsePacketInterval)).toEqual(true); - - expect(dynamicObject.ellipse).toBeDefined(); - expect(dynamicObject.ellipse.semiMajorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMajorAxis); - expect(dynamicObject.ellipse.semiMinorAxis.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.semiMinorAxis); - expect(dynamicObject.ellipse.bearing.getValue(validTime)).toEqual(ellipsePacketInterval.ellipse.bearing); - - expect(dynamicObject.ellipse.semiMajorAxis.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.ellipse.semiMinorAxis.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.ellipse.bearing.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipse.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.ellipse).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured ellipse', function() { - var expectedSemiMajorAxis = new MockProperty(); - var expectedSemiMinorAxis = new MockProperty(); - var expectedBearing = new MockProperty(); + var expectedSemiMajorAxis = new ConstantProperty(1); + var expectedSemiMinorAxis = new ConstantProperty(2); + var expectedBearing = new ConstantProperty(3); var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.ellipse = new DynamicEllipse(); - objectToMerge.semiMajorAxis = new MockProperty(); - objectToMerge.semiMinorAxis = new MockProperty(); - objectToMerge.bearing = new MockProperty(); + objectToMerge.semiMajorAxis = new ConstantProperty(4); + objectToMerge.semiMinorAxis = new ConstantProperty(5); + objectToMerge.bearing = new ConstantProperty(6); var mergedObject = new DynamicObject('mergedObject'); mergedObject.ellipse = new DynamicEllipse(); @@ -93,31 +45,31 @@ defineSuite([ DynamicEllipse.mergeProperties(mergedObject, objectToMerge); - expect(mergedObject.ellipse.semiMajorAxis).toEqual(expectedSemiMajorAxis); - expect(mergedObject.ellipse.semiMinorAxis).toEqual(expectedSemiMinorAxis); - expect(mergedObject.ellipse.bearing).toEqual(expectedBearing); + expect(mergedObject.ellipse.semiMajorAxis).toBe(expectedSemiMajorAxis); + expect(mergedObject.ellipse.semiMinorAxis).toBe(expectedSemiMinorAxis); + expect(mergedObject.ellipse.bearing).toBe(expectedBearing); }); it('mergeProperties creates and configures an undefined ellipse', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.ellipse = new DynamicEllipse(); - objectToMerge.semiMajorAxis = new MockProperty(); - objectToMerge.semiMinorAxis = new MockProperty(); - objectToMerge.bearing = new MockProperty(); + objectToMerge.semiMajorAxis = new ConstantProperty(1); + objectToMerge.semiMinorAxis = new ConstantProperty(2); + objectToMerge.bearing = new ConstantProperty(3); var mergedObject = new DynamicObject('mergedObject'); DynamicEllipse.mergeProperties(mergedObject, objectToMerge); - expect(mergedObject.ellipse.semiMajorAxis).toEqual(objectToMerge.ellipse.semiMajorAxis); - expect(mergedObject.ellipse.semiMinorAxis).toEqual(objectToMerge.ellipse.semiMinorAxis); - expect(mergedObject.ellipse.bearing).toEqual(objectToMerge.ellipse.bearing); + expect(mergedObject.ellipse.semiMajorAxis).toBe(objectToMerge.ellipse.semiMajorAxis); + expect(mergedObject.ellipse.semiMinorAxis).toBe(objectToMerge.ellipse.semiMinorAxis); + expect(mergedObject.ellipse.bearing).toBe(objectToMerge.ellipse.bearing); }); it('mergeProperties does not change when used with an undefined ellipse', function() { - var expectedSemiMajorAxis = new MockProperty(); - var expectedSemiMinorAxis = new MockProperty(); - var expectedBearing = new MockProperty(); + var expectedSemiMajorAxis = new ConstantProperty(1); + var expectedSemiMinorAxis = new ConstantProperty(2); + var expectedBearing = new ConstantProperty(3); var objectToMerge = new DynamicObject('objectToMerge'); var mergedObject = new DynamicObject('mergedObject'); @@ -128,9 +80,9 @@ defineSuite([ DynamicEllipse.mergeProperties(mergedObject, objectToMerge); - expect(mergedObject.ellipse.semiMajorAxis).toEqual(expectedSemiMajorAxis); - expect(mergedObject.ellipse.semiMinorAxis).toEqual(expectedSemiMinorAxis); - expect(mergedObject.ellipse.bearing).toEqual(expectedBearing); + expect(mergedObject.ellipse.semiMajorAxis).toBe(expectedSemiMajorAxis); + expect(mergedObject.ellipse.semiMinorAxis).toBe(expectedSemiMinorAxis); + expect(mergedObject.ellipse.bearing).toBe(expectedBearing); }); it('undefineProperties works', function() { @@ -148,24 +100,24 @@ defineSuite([ it('getValue with no semiMajorAxis returns undefined', function() { var ellipse = new DynamicEllipse(); ellipse = new DynamicEllipse(); - ellipse.bearing = new MockProperty(0); - ellipse.semiMinorAxis = new MockProperty(10); + ellipse.bearing = new ConstantProperty(0); + ellipse.semiMinorAxis = new ConstantProperty(10); ellipse.semiMajorAxis = undefined; expect(ellipse.getValue(new JulianDate(), position)).toBeUndefined(); - ellipse.semiMajorAxis = new MockProperty(undefined); + ellipse.semiMajorAxis = new UndefinedProperty(); expect(ellipse.getValue(new JulianDate(), position)).toBeUndefined(); }); it('getValue with no semiMinorAxis returns undefined', function() { var ellipse = new DynamicEllipse(); ellipse = new DynamicEllipse(); - ellipse.bearing = new MockProperty(0); + ellipse.bearing = new ConstantProperty(0); ellipse.semiMinorAxis = undefined; - ellipse.semiMajorAxis = new MockProperty(10); + ellipse.semiMajorAxis = new ConstantProperty(10); expect(ellipse.getValue(new JulianDate(), position)).toBeUndefined(); - ellipse.semiMinorAxis = new MockProperty(undefined); + ellipse.semiMinorAxis = new UndefinedProperty(); expect(ellipse.getValue(new JulianDate(), position)).toBeUndefined(); }); @@ -176,15 +128,15 @@ defineSuite([ var ellipse = new DynamicEllipse(); ellipse = new DynamicEllipse(); - ellipse.semiMinorAxis = new MockProperty(semiMinor); - ellipse.semiMajorAxis = new MockProperty(semiMajor); + ellipse.semiMinorAxis = new ConstantProperty(semiMinor); + ellipse.semiMajorAxis = new ConstantProperty(semiMajor); ellipse.bearing = undefined; var expected = Shapes.computeEllipseBoundary(Ellipsoid.WGS84, position, semiMajor, semiMinor, bearing); var result = ellipse.getValue(new JulianDate(), position); expect(result).toEqual(expected); - ellipse.bearing = new MockProperty(undefined); + ellipse.bearing = new UndefinedProperty(); result = ellipse.getValue(new JulianDate(), position); expect(result).toEqual(expected); }); @@ -196,9 +148,9 @@ defineSuite([ var ellipse = new DynamicEllipse(); ellipse = new DynamicEllipse(); - ellipse.semiMinorAxis = new MockProperty(semiMinor); - ellipse.semiMajorAxis = new MockProperty(semiMajor); - ellipse.bearing = new MockProperty(bearing); + ellipse.semiMinorAxis = new ConstantProperty(semiMinor); + ellipse.semiMajorAxis = new ConstantProperty(semiMajor); + ellipse.bearing = new ConstantProperty(bearing); var expected = Shapes.computeEllipseBoundary(Ellipsoid.WGS84, position, semiMajor, semiMinor, bearing); var result = ellipse.getValue(new JulianDate(), position); @@ -208,15 +160,15 @@ defineSuite([ it('getValue caches results.', function() { var ellipse = new DynamicEllipse(); ellipse = new DynamicEllipse(); - ellipse.semiMinorAxis = new MockProperty(10); - ellipse.semiMajorAxis = new MockProperty(20); - ellipse.bearing = new MockProperty(50); + ellipse.semiMinorAxis = new ConstantProperty(10); + ellipse.semiMajorAxis = new ConstantProperty(20); + ellipse.bearing = new ConstantProperty(50); var result1 = ellipse.getValue(new JulianDate(), position); var result2 = ellipse.getValue(new JulianDate(), position); expect(result1).toBe(result2); - ellipse.bearing = new MockProperty(75); + ellipse.bearing = new ConstantProperty(75); result2 = ellipse.getValue(new JulianDate(), position); expect(result1).toNotBe(result2); }); diff --git a/Specs/DynamicScene/DynamicEllipsoidSpec.js b/Specs/DynamicScene/DynamicEllipsoidSpec.js index 7ceefcf48083..0f1b3c0da895 100644 --- a/Specs/DynamicScene/DynamicEllipsoidSpec.js +++ b/Specs/DynamicScene/DynamicEllipsoidSpec.js @@ -18,75 +18,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - var expectedRadii = new Cartesian3(1.0, 2.0, 3.0); - - var ellipsoidPacket = { - ellipsoid : { - radii : { - cartesian : [1.0, 2.0, 3.0] - }, - show : true, - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - } - } - }; - - var ellipsoidPacketInterval = { - ellipsoid : { - interval : '2000-01-01/2001-01-01', - radii : { - cartesian : [1.0, 2.0, 3.0] - }, - show : true, - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - } - } - }; - - it('processCzmlPacket adds data for infinite ellipsoid.', function() { - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipsoid.processCzmlPacket(dynamicObject, ellipsoidPacket)).toEqual(true); - - expect(dynamicObject.ellipsoid).toBeDefined(); - expect(dynamicObject.ellipsoid.radii.getValue(Iso8601.MINIMUM_VALUE)).toEqual(expectedRadii); - expect(dynamicObject.ellipsoid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(ellipsoidPacket.ellipsoid.show); - expect(dynamicObject.ellipsoid.material.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - }); - - it('processCzmlPacket adds data for constrained ellipsoid.', function() { - var validTime = TimeInterval.fromIso8601(ellipsoidPacketInterval.ellipsoid.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipsoid.processCzmlPacket(dynamicObject, ellipsoidPacketInterval)).toEqual(true); - - expect(dynamicObject.ellipsoid).toBeDefined(); - expect(dynamicObject.ellipsoid.radii.getValue(validTime)).toEqual(expectedRadii); - expect(dynamicObject.ellipsoid.show.getValue(validTime)).toEqual(ellipsoidPacketInterval.ellipsoid.show); - expect(dynamicObject.ellipsoid.material.getValue(validTime).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - - expect(dynamicObject.ellipsoid.radii.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.ellipsoid.show.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.ellipsoid.material.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicEllipsoid.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.ellipsoid).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured ellipsoid', function() { var expectedMaterial = 4; var expectedRadii = 5; diff --git a/Specs/DynamicScene/DynamicEllipsoidVisualizerSpec.js b/Specs/DynamicScene/DynamicEllipsoidVisualizerSpec.js index 0d2e527828fc..2fd66a0b6d26 100644 --- a/Specs/DynamicScene/DynamicEllipsoidVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicEllipsoidVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicEllipsoidVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'Core/JulianDate', 'Core/Matrix3', 'Core/Matrix4', @@ -13,12 +13,12 @@ defineSuite([ 'Core/Color', 'DynamicScene/DynamicEllipsoid', 'DynamicScene/DynamicObjectCollection', - 'Scene/Material' + 'DynamicScene/ColorMaterialProperty' ], function( DynamicEllipsoidVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, JulianDate, Matrix3, Matrix4, @@ -28,7 +28,7 @@ defineSuite([ Color, DynamicEllipsoid, DynamicObjectCollection, - Material) { + ColorMaterialProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -86,8 +86,8 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -97,9 +97,9 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var ellipsoid = testObject.ellipsoid = new DynamicEllipsoid(); - ellipsoid.radii = new MockProperty(new Cartesian3(1, 2, 3)); + ellipsoid.radii = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -109,8 +109,8 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); testObject.ellipsoid = new DynamicEllipsoid(); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -121,9 +121,9 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.ellipsoid = new DynamicEllipsoid(); - testObject.ellipsoid.radii = new MockProperty(new Cartesian3(1, 2, 3)); + testObject.ellipsoid.radii = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -134,24 +134,22 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var ellipsoid = testObject.ellipsoid = new DynamicEllipsoid(); - ellipsoid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - ellipsoid.radii = new MockProperty(123.5); - ellipsoid.show = new MockProperty(true); - var redMaterial = Material.fromType(scene.getContext(), Material.ColorType); - redMaterial.uniforms.color = Color.RED; - ellipsoid.material = new MockProperty(redMaterial); + ellipsoid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + ellipsoid.radii = new ConstantProperty(123.5); + ellipsoid.show = new ConstantProperty(true); + ellipsoid.material = new ColorMaterialProperty(); visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); var p = scene.getPrimitives().get(0); expect(p.radii).toEqual(testObject.ellipsoid.radii.getValue(time)); expect(p.show).toEqual(testObject.ellipsoid.show.getValue(time)); - expect(p.material).toEqual(testObject.ellipsoid.material.getValue(time)); - expect(p.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValueCartesian(time))); + expect(p.material.uniforms).toEqual(testObject.ellipsoid.material.getValue(time)); + expect(p.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValue(time))); ellipsoid.show.value = false; visualizer.update(time); @@ -163,10 +161,10 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var ellipsoid = testObject.ellipsoid = new DynamicEllipsoid(); - ellipsoid.radii = new MockProperty(new Cartesian3(1, 2, 3)); + ellipsoid.radii = new ConstantProperty(new Cartesian3(1, 2, 3)); var time = new JulianDate(); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -184,10 +182,10 @@ defineSuite([ visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var ellipsoid = testObject.ellipsoid = new DynamicEllipsoid(); - ellipsoid.radii = new MockProperty(new Cartesian3(1, 2, 3)); + ellipsoid.radii = new ConstantProperty(new Cartesian3(1, 2, 3)); var time = new JulianDate(); visualizer.update(time); @@ -197,17 +195,17 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var ellipsoid = testObject.ellipsoid = new DynamicEllipsoid(); - ellipsoid.radii = new MockProperty(new Cartesian3(1, 2, 3)); + ellipsoid.radii = new ConstantProperty(new Cartesian3(1, 2, 3)); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.orientation = new MockProperty(new Quaternion(1, 0, 0, 0)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.orientation = new ConstantProperty(new Quaternion(1, 0, 0, 0)); var ellipsoid2 = testObject2.ellipsoid = new DynamicEllipsoid(); - ellipsoid2.radii = new MockProperty(new Cartesian3(4, 5, 6)); + ellipsoid2.radii = new ConstantProperty(new Cartesian3(4, 5, 6)); visualizer = new DynamicEllipsoidVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicGridMaterialSpec.js b/Specs/DynamicScene/DynamicGridMaterialSpec.js deleted file mode 100644 index ed1f19f8cde8..000000000000 --- a/Specs/DynamicScene/DynamicGridMaterialSpec.js +++ /dev/null @@ -1,78 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/DynamicGridMaterial', - 'Core/Color', - 'Core/JulianDate', - 'Scene/Material', - 'Specs/createContext', - 'Specs/destroyContext' - ], function( - DynamicGridMaterial, - Color, - JulianDate, - Material, - createContext, - destroyContext) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var context; - beforeAll(function() { - context = createContext(); - }); - - afterAll(function() { - destroyContext(context); - }); - - var color = new Color(0.25, 0.5, 0.75, 1); - - var gridCzml = { - grid : { - color : { - rgbaf : [color.red, color.green, color.blue, color.alpha] - }, - cellAlpha : 0.5, - rowCount : 20, - columnCount : 10, - rowThickness : 2, - columnThickness : 5 - } - }; - - it('isMaterial works.', function() { - var grid = new DynamicGridMaterial(); - expect(grid.isMaterial(gridCzml)).toBe(true); - expect(grid.isMaterial({})).toBe(false); - }); - - it('assigns properties from CZML.', function() { - var grid = new DynamicGridMaterial(); - grid.processCzmlIntervals(gridCzml); - - var material = grid.getValue(new JulianDate(), context); - expect(material.uniforms.color).toEqual(color); - expect(material.uniforms.cellAlpha).toEqual(gridCzml.grid.cellAlpha); - expect(material.uniforms.lineCount.x).toEqual(gridCzml.grid.rowCount); - expect(material.uniforms.lineCount.y).toEqual(gridCzml.grid.columnCount); - expect(material.uniforms.lineThickness.x).toEqual(gridCzml.grid.rowThickness); - expect(material.uniforms.lineThickness.y).toEqual(gridCzml.grid.columnThickness); - }); - - it('assigns properties from CZML with result parameter.', function() { - var grid = new DynamicGridMaterial(); - grid.processCzmlIntervals(gridCzml); - - var existingMaterial = Material.fromType(context, Material.GridType); - - var material = grid.getValue(new JulianDate(), context, existingMaterial); - expect(material).toBe(existingMaterial); - expect(material.uniforms.color).toEqual(color); - expect(material.uniforms.cellAlpha).toEqual(gridCzml.grid.cellAlpha); - expect(material.uniforms.lineCount.x).toEqual(gridCzml.grid.rowCount); - expect(material.uniforms.lineCount.y).toEqual(gridCzml.grid.columnCount); - expect(material.uniforms.lineThickness.x).toEqual(gridCzml.grid.rowThickness); - expect(material.uniforms.lineThickness.y).toEqual(gridCzml.grid.columnThickness); - }); - -}, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicLabelSpec.js b/Specs/DynamicScene/DynamicLabelSpec.js index e0ae2cc4a9de..601b93672ee2 100644 --- a/Specs/DynamicScene/DynamicLabelSpec.js +++ b/Specs/DynamicScene/DynamicLabelSpec.js @@ -11,7 +11,7 @@ defineSuite([ 'Scene/HorizontalOrigin', 'Scene/VerticalOrigin', 'Scene/LabelStyle', - 'Specs/MockProperty' + 'DynamicScene/ConstantProperty' ], function( DynamicLabel, DynamicObject, @@ -24,148 +24,38 @@ defineSuite([ HorizontalOrigin, VerticalOrigin, LabelStyle, - MockProperty) { + ConstantProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite label.', function() { - var labelPacket = { - label : { - text : 'TestFacility', - font : '10pt "Open Sans"', - style : 'FILL', - fillColor : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 3.14, - horizontalOrigin : 'LEFT', - verticalOrigin : 'CENTER', - eyeOffset : { - cartesian : [1.0, 2.0, 3.0] - }, - pixelOffset : { - cartesian2 : [4.0, 5.0] - }, - scale : 1.0, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicLabel.processCzmlPacket(dynamicObject, labelPacket)).toEqual(true); - expect(dynamicObject.label).toBeDefined(); - expect(dynamicObject.label.text.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.text); - expect(dynamicObject.label.font.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.font); - expect(dynamicObject.label.style.getValue(Iso8601.MINIMUM_VALUE)).toEqual(LabelStyle.FILL); - expect(dynamicObject.label.fillColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.label.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.label.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.outlineWidth); - expect(dynamicObject.label.horizontalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(HorizontalOrigin.LEFT); - expect(dynamicObject.label.verticalOrigin.getValue(Iso8601.MINIMUM_VALUE)).toEqual(VerticalOrigin.CENTER); - expect(dynamicObject.label.eyeOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(dynamicObject.label.pixelOffset.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian2(4.0, 5.0)); - expect(dynamicObject.label.scale.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.scale); - expect(dynamicObject.label.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(labelPacket.label.show); - }); - - it('processCzmlPacket adds data for constrained label.', function() { - var labelPacket = { - label : { - interval : '2000-01-01/2001-01-01', - text : 'TestFacility', - font : '10pt "Open Sans"', - style : 'FILL', - fillColor : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 2.78, - horizontalOrigin : 'LEFT', - verticalOrigin : 'CENTER', - eyeOffset : { - cartesian : [1.0, 2.0, 3.0] - }, - pixelOffset : { - cartesian2 : [4.0, 5.0] - }, - scale : 1.0, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(labelPacket.label.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicLabel.processCzmlPacket(dynamicObject, labelPacket)).toEqual(true); - expect(dynamicObject.label).toBeDefined(); - expect(dynamicObject.label.text.getValue(validTime)).toEqual(labelPacket.label.text); - expect(dynamicObject.label.font.getValue(validTime)).toEqual(labelPacket.label.font); - expect(dynamicObject.label.style.getValue(validTime)).toEqual(LabelStyle.FILL); - expect(dynamicObject.label.fillColor.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.label.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.label.outlineWidth.getValue(validTime)).toEqual(labelPacket.label.outlineWidth); - expect(dynamicObject.label.horizontalOrigin.getValue(validTime)).toEqual(HorizontalOrigin.LEFT); - expect(dynamicObject.label.verticalOrigin.getValue(validTime)).toEqual(VerticalOrigin.CENTER); - expect(dynamicObject.label.eyeOffset.getValue(validTime)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - expect(dynamicObject.label.pixelOffset.getValue(validTime)).toEqual(new Cartesian2(4.0, 5.0)); - expect(dynamicObject.label.scale.getValue(validTime)).toEqual(labelPacket.label.scale); - expect(dynamicObject.label.show.getValue(validTime)).toEqual(labelPacket.label.show); - - expect(dynamicObject.label.text.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.font.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.style.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.fillColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.outlineColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.outlineWidth.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.horizontalOrigin.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.verticalOrigin.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.eyeOffset.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.pixelOffset.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.scale.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.label.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicLabel.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.label).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured label', function() { - var expectedText = new MockProperty(); - var expectedFont = new MockProperty(); - var expectedStyle = new MockProperty(); - var expectedFillColor = new MockProperty(); - var expectedOutlineColor = new MockProperty(); - var expectedOutlineWidth = new MockProperty(); - var expectedHorizontalOrigin = new MockProperty(); - var expectedVerticalOrigin = new MockProperty(); - var expectedEyeOffset = new MockProperty(); - var expectedPixelOffset = new MockProperty(); - var expectedScale = new MockProperty(); - var expectedShow = new MockProperty(); + var expectedText = new ConstantProperty('my text'); + var expectedFont = new ConstantProperty('10px serif'); + var expectedStyle = new ConstantProperty(LabelStyle.OUTLINE); + var expectedFillColor = new ConstantProperty(Color.RED); + var expectedOutlineColor = new ConstantProperty(Color.WHITE); + var expectedOutlineWidth = new ConstantProperty(4); + var expectedHorizontalOrigin = new ConstantProperty(HorizontalOrigin.RIGHT); + var expectedVerticalOrigin = new ConstantProperty(VerticalOrigin.TOP); + var expectedEyeOffset = new ConstantProperty(Cartesian3.UNIT_Z); + var expectedPixelOffset = new ConstantProperty(Cartesian2.UNIT_Y); + var expectedScale = new ConstantProperty(2); + var expectedShow = new ConstantProperty(true); var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.label = new DynamicLabel(); - objectToMerge.label.text = new MockProperty(); - objectToMerge.label.font = new MockProperty(); - objectToMerge.label.style = new MockProperty(); - objectToMerge.label.fillColor = new MockProperty(); - objectToMerge.label.outlineColor = new MockProperty(); - objectToMerge.label.outlineWidth = new MockProperty(); - objectToMerge.label.horizontalOrigin = new MockProperty(); - objectToMerge.label.verticalOrigin = new MockProperty(); - objectToMerge.label.eyeOffset = new MockProperty(); - objectToMerge.label.pixelOffset = new MockProperty(); - objectToMerge.label.scale = new MockProperty(); - objectToMerge.label.show = new MockProperty(); + objectToMerge.label.text = new ConstantProperty('not it'); + objectToMerge.label.font = new ConstantProperty('arial'); + objectToMerge.label.style = new ConstantProperty(LabelStyle.FILL); + objectToMerge.label.fillColor = new ConstantProperty(Color.BLACK); + objectToMerge.label.outlineColor = new ConstantProperty(Color.BLUE); + objectToMerge.label.outlineWidth = new ConstantProperty(5); + objectToMerge.label.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT); + objectToMerge.label.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM); + objectToMerge.label.eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y); + objectToMerge.label.pixelOffset = new ConstantProperty(Cartesian2.UNIT_X); + objectToMerge.label.scale = new ConstantProperty(1); + objectToMerge.label.show = new ConstantProperty(false); var targetObject = new DynamicObject('targetObject'); targetObject.label = new DynamicLabel(); @@ -201,18 +91,18 @@ defineSuite([ it('mergeProperties creates and configures an undefined label', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.label = new DynamicLabel(); - objectToMerge.label.text = new MockProperty(); - objectToMerge.label.font = new MockProperty(); - objectToMerge.label.style = new MockProperty(); - objectToMerge.label.fillColor = new MockProperty(); - objectToMerge.label.outlineColor = new MockProperty(); - objectToMerge.label.outlineWidth = new MockProperty(); - objectToMerge.label.horizontalOrigin = new MockProperty(); - objectToMerge.label.verticalOrigin = new MockProperty(); - objectToMerge.label.eyeOffset = new MockProperty(); - objectToMerge.label.pixelOffset = new MockProperty(); - objectToMerge.label.scale = new MockProperty(); - objectToMerge.label.show = new MockProperty(); + objectToMerge.label.text = new ConstantProperty('not it'); + objectToMerge.label.font = new ConstantProperty('arial'); + objectToMerge.label.style = new ConstantProperty(LabelStyle.FILL); + objectToMerge.label.fillColor = new ConstantProperty(Color.BLACK); + objectToMerge.label.outlineColor = new ConstantProperty(Color.BLUE); + objectToMerge.label.outlineWidth = new ConstantProperty(5); + objectToMerge.label.horizontalOrigin = new ConstantProperty(HorizontalOrigin.LEFT); + objectToMerge.label.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM); + objectToMerge.label.eyeOffset = new ConstantProperty(Cartesian3.UNIT_Y); + objectToMerge.label.pixelOffset = new ConstantProperty(Cartesian2.UNIT_X); + objectToMerge.label.scale = new ConstantProperty(1); + objectToMerge.label.show = new ConstantProperty(false); var targetObject = new DynamicObject('targetObject'); @@ -233,18 +123,18 @@ defineSuite([ }); it('mergeProperties does not change when used with an undefined label', function() { - var expectedText = new MockProperty(); - var expectedFont = new MockProperty(); - var expectedStyle = new MockProperty(); - var expectedFillColor = new MockProperty(); - var expectedOutlineColor = new MockProperty(); - var expectedOutlineWidth = new MockProperty(); - var expectedHorizontalOrigin = new MockProperty(); - var expectedVerticalOrigin = new MockProperty(); - var expectedEyeOffset = new MockProperty(); - var expectedPixelOffset = new MockProperty(); - var expectedScale = new MockProperty(); - var expectedShow = new MockProperty(); + var expectedText = new ConstantProperty('my text'); + var expectedFont = new ConstantProperty('10px serif'); + var expectedStyle = new ConstantProperty(LabelStyle.OUTLINE); + var expectedFillColor = new ConstantProperty(Color.RED); + var expectedOutlineColor = new ConstantProperty(Color.WHITE); + var expectedOutlineWidth = new ConstantProperty(4); + var expectedHorizontalOrigin = new ConstantProperty(HorizontalOrigin.RIGHT); + var expectedVerticalOrigin = new ConstantProperty(VerticalOrigin.TOP); + var expectedEyeOffset = new ConstantProperty(Cartesian3.UNIT_Z); + var expectedPixelOffset = new ConstantProperty(Cartesian2.UNIT_Y); + var expectedScale = new ConstantProperty(2); + var expectedShow = new ConstantProperty(true); var objectToMerge = new DynamicObject('objectToMerge'); diff --git a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js index e259e25c8112..e189fbd6ee06 100644 --- a/Specs/DynamicScene/DynamicLabelVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicLabelVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicLabelVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicLabel', 'DynamicScene/DynamicObjectCollection', 'Core/JulianDate', @@ -18,7 +18,7 @@ defineSuite([ DynamicLabelVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, DynamicLabel, DynamicObjectCollection, JulianDate, @@ -88,7 +88,7 @@ defineSuite([ visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); visualizer.update(new JulianDate()); var labelCollection = scene.getPrimitives().get(0); expect(labelCollection.getLength()).toEqual(0); @@ -100,8 +100,8 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var label = testObject.label = new DynamicLabel(); - label.show = new MockProperty(true); - label.text = new MockProperty('lorum ipsum'); + label.show = new ConstantProperty(true); + label.text = new ConstantProperty('lorum ipsum'); visualizer.update(new JulianDate()); var labelCollection = scene.getPrimitives().get(0); @@ -113,9 +113,9 @@ defineSuite([ visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var label = testObject.label = new DynamicLabel(); - label.show = new MockProperty(true); + label.show = new ConstantProperty(true); visualizer.update(new JulianDate()); var labelCollection = scene.getPrimitives().get(0); @@ -135,19 +135,19 @@ defineSuite([ var label = testObject.label = new DynamicLabel(); var l; - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - label.text = new MockProperty('a'); - label.font = new MockProperty('sans serif'); - label.style = new MockProperty(LabelStyle.FILL); - label.fillColor = new MockProperty(new Color(0.5, 0.8, 0.6, 0.7)); - label.outlineColor = new MockProperty(new Color(0.4, 0.3, 0.2, 0.1)); - label.outlineWidth = new MockProperty(4.5); - label.horizontalOrigin = new MockProperty(HorizontalOrigin.RIGHT); - label.verticalOrigin = new MockProperty(VerticalOrigin.TOP); - label.eyeOffset = new MockProperty(new Cartesian3(1.0, 2.0, 3.0)); - label.pixelOffset = new MockProperty(new Cartesian2(3, 2)); - label.scale = new MockProperty(12.5); - label.show = new MockProperty(true); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + label.text = new ConstantProperty('a'); + label.font = new ConstantProperty('sans serif'); + label.style = new ConstantProperty(LabelStyle.FILL); + label.fillColor = new ConstantProperty(new Color(0.5, 0.8, 0.6, 0.7)); + label.outlineColor = new ConstantProperty(new Color(0.4, 0.3, 0.2, 0.1)); + label.outlineWidth = new ConstantProperty(4.5); + label.horizontalOrigin = new ConstantProperty(HorizontalOrigin.RIGHT); + label.verticalOrigin = new ConstantProperty(VerticalOrigin.TOP); + label.eyeOffset = new ConstantProperty(new Cartesian3(1.0, 2.0, 3.0)); + label.pixelOffset = new ConstantProperty(new Cartesian2(3, 2)); + label.scale = new ConstantProperty(12.5); + label.show = new ConstantProperty(true); visualizer.update(time); @@ -156,7 +156,7 @@ defineSuite([ l = labelCollection.get(0); visualizer.update(time); - expect(l.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(l.getPosition()).toEqual(testObject.position.getValue(time)); expect(l.getText()).toEqual(testObject.label.text.getValue(time)); expect(l.getFont()).toEqual(testObject.label.font.getValue(time)); expect(l.getStyle()).toEqual(testObject.label.style.getValue(time)); @@ -170,22 +170,22 @@ defineSuite([ expect(l.getScale()).toEqual(testObject.label.scale.getValue(time)); expect(l.getShow()).toEqual(testObject.label.show.getValue(time)); - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1293434)); - label.text = new MockProperty('b'); - label.font = new MockProperty('serif'); - label.style = new MockProperty(LabelStyle.FILL_AND_OUTLINE); - label.fillColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - label.outlineColor = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - label.outlineWidth = new MockProperty(0.5); - label.horizontalOrigin = new MockProperty(HorizontalOrigin.CENTER); - label.verticalOrigin = new MockProperty(VerticalOrigin.BOTTOM); - label.eyeOffset = new MockProperty(new Cartesian3(3.0, 1.0, 2.0)); - label.pixelOffset = new MockProperty(new Cartesian2(2, 3)); - label.scale = new MockProperty(2.5); - label.show = new MockProperty(true); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1293434)); + label.text = new ConstantProperty('b'); + label.font = new ConstantProperty('serif'); + label.style = new ConstantProperty(LabelStyle.FILL_AND_OUTLINE); + label.fillColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + label.outlineColor = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + label.outlineWidth = new ConstantProperty(0.5); + label.horizontalOrigin = new ConstantProperty(HorizontalOrigin.CENTER); + label.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM); + label.eyeOffset = new ConstantProperty(new Cartesian3(3.0, 1.0, 2.0)); + label.pixelOffset = new ConstantProperty(new Cartesian2(2, 3)); + label.scale = new ConstantProperty(2.5); + label.show = new ConstantProperty(true); visualizer.update(time); - expect(l.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(l.getPosition()).toEqual(testObject.position.getValue(time)); expect(l.getText()).toEqual(testObject.label.text.getValue(time)); expect(l.getFont()).toEqual(testObject.label.font.getValue(time)); expect(l.getStyle()).toEqual(testObject.label.style.getValue(time)); @@ -199,7 +199,7 @@ defineSuite([ expect(l.getScale()).toEqual(testObject.label.scale.getValue(time)); expect(l.getShow()).toEqual(testObject.label.show.getValue(time)); - label.show = new MockProperty(false); + label.show = new ConstantProperty(false); visualizer.update(time); }); @@ -215,9 +215,9 @@ defineSuite([ var time = new JulianDate(); var label = testObject.label = new DynamicLabel(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - label.show = new MockProperty(true); - label.text = new MockProperty('lorum ipsum'); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + label.show = new ConstantProperty(true); + label.text = new ConstantProperty('lorum ipsum'); visualizer.update(time); expect(labelCollection.getLength()).toEqual(1); @@ -243,9 +243,9 @@ defineSuite([ var time = new JulianDate(); var label = testObject.label = new DynamicLabel(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - label.show = new MockProperty(true); - label.text = new MockProperty('lorum ipsum'); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + label.show = new ConstantProperty(true); + label.text = new ConstantProperty('lorum ipsum'); visualizer.update(time); expect(labelCollection.getLength()).toEqual(1); var l = labelCollection.get(0); @@ -255,17 +255,17 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.label = new DynamicLabel(); - testObject.label.show = new MockProperty(true); - testObject.label.text = new MockProperty('lorum ipsum'); + testObject.label.show = new ConstantProperty(true); + testObject.label.text = new ConstantProperty('lorum ipsum'); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); testObject2.label = new DynamicLabel(); - testObject2.label.show = new MockProperty(true); - testObject2.label.text = new MockProperty('the quick brown'); + testObject2.label.show = new ConstantProperty(true); + testObject2.label.text = new ConstantProperty('the quick brown'); visualizer = new DynamicLabelVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicMaterialPropertySpec.js b/Specs/DynamicScene/DynamicMaterialPropertySpec.js deleted file mode 100644 index 9486eb6713b6..000000000000 --- a/Specs/DynamicScene/DynamicMaterialPropertySpec.js +++ /dev/null @@ -1,121 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/DynamicMaterialProperty', - 'Core/Color', - 'Core/JulianDate', - 'Core/TimeInterval', - 'Scene/Material', - 'Specs/createContext', - 'Specs/destroyContext' - ], function( - DynamicMaterialProperty, - Color, - JulianDate, - TimeInterval, - Material, - createContext, - destroyContext) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var context; - beforeAll(function() { - context = createContext(); - }); - - afterAll(function() { - destroyContext(context); - }); - - var solidColor = Color.fromBytes(255, 0, 0, 77); - - var staticColorCzml = { - solidColor : { - color : { - rgba : [255, 0, 0, 77] - } - } - }; - - var staticImageCzml = { - image : { - image : 'someImage' - } - }; - - var constrainedImageCzml = [{ - interval : '2012-03-15/2012-03-16', - image : { - image : 'someImage' - } - }]; - - it('Supports color materials.', function() { - var property = new DynamicMaterialProperty(); - property.processCzmlIntervals(staticColorCzml, undefined, undefined); - var material = property.getValue(new JulianDate(), context); - expect(material.type).toEqual(Material.ColorType); - expect(material.uniforms.color).toEqual(solidColor); - }); - - it('Supports image materials.', function() { - var property = new DynamicMaterialProperty(); - property.processCzmlIntervals(staticImageCzml, undefined, undefined); - var material = property.getValue(new JulianDate(), context); - expect(material.type).toEqual(Material.ImageType); - expect(material.uniforms.image).toEqual(staticImageCzml.image.image); - }); - - it('Constrains data to CZML defined Interval', function() { - var property = new DynamicMaterialProperty(); - property.processCzmlIntervals(constrainedImageCzml, undefined, undefined); - - var interval = TimeInterval.fromIso8601(constrainedImageCzml[0].interval); - - var material = property.getValue(interval.stop.addSeconds(1), context); - expect(material).toBeUndefined(); - - material = property.getValue(interval.start, context); - expect(material.type).toEqual(Material.ImageType); - expect(material.uniforms.image).toEqual(constrainedImageCzml[0].image.image); - - material = property.getValue(interval.start.addSeconds(-1), context); - expect(material).toBeUndefined(); - - material = property.getValue(interval.stop, context); - expect(material.type).toEqual(Material.ImageType); - expect(material.uniforms.image).toEqual(constrainedImageCzml[0].image.image); - }); - - it('Works with different materials over time.', function() { - var property = new DynamicMaterialProperty(); - property.processCzmlIntervals(staticColorCzml, TimeInterval.fromIso8601('2012-03-15/2012-03-16'), undefined); - property.processCzmlIntervals(staticImageCzml, TimeInterval.fromIso8601('2012-03-16/2012-03-17'), undefined); - - var material = property.getValue(JulianDate.fromIso8601('2012-03-16'), context); - expect(material.type).toEqual(Material.ImageType); - expect(material.uniforms.image).toEqual(staticImageCzml.image.image); - - material = property.getValue(JulianDate.fromIso8601('2012-03-15'), context, material); - expect(material.type).toEqual(Material.ColorType); - expect(material.uniforms.color).toEqual(solidColor); - - material = property.getValue(JulianDate.fromIso8601('2012-03-18'), context); - expect(material).toBeUndefined(); - }); - - it('Incrementally processing CZML can replace existing material intervals.', function() { - var property = new DynamicMaterialProperty(); - var date = new JulianDate(); - - property.processCzmlIntervals(staticColorCzml, undefined, undefined); - var material = property.getValue(date, context, material); - expect(material.type).toEqual(Material.ColorType); - expect(material.uniforms.color).toEqual(solidColor); - - property.processCzmlIntervals(staticImageCzml, undefined, undefined); - material = property.getValue(date, context); - expect(material.type).toEqual(Material.ImageType); - expect(material.uniforms.image).toEqual(staticImageCzml.image.image); - }); -}, 'WebGL'); diff --git a/Specs/DynamicScene/DynamicObjectSpec.js b/Specs/DynamicScene/DynamicObjectSpec.js index 2084fe965d78..253c4c6d8b04 100644 --- a/Specs/DynamicScene/DynamicObjectSpec.js +++ b/Specs/DynamicScene/DynamicObjectSpec.js @@ -40,132 +40,16 @@ defineSuite([ expect(object.id).toNotEqual(object2.id); }); - it('processCzmlPacketPosition works.', function() { - var packet = { - 'position' : { - 'cartesian' : [1.0, 2.0, 3.0] - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketPosition(dynamicObject, packet)).toEqual(true); - expect(dynamicObject.position.getValueCartesian(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - }); - - it('processCzmlPacketPosition returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketPosition(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.position).toBeUndefined(); - }); - - it('processCzmlPacketOrientation works.', function() { - var packet = { - 'orientation' : { - 'unitQuaternion' : [0.0, 0.0, 0.0, 1.0] - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketOrientation(dynamicObject, packet)).toEqual(true); - expect(dynamicObject.orientation.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Quaternion(0.0, 0.0, 0.0, 1.0)); - }); - - it('processCzmlPacketOrientation returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketOrientation(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.orientation).toBeUndefined(); - }); - - it('processCzmlPacketVertexPositions works.', function() { - var packet = { - 'vertexPositions' : { - 'cartesian' : [1.0, 2.0, 3.0, 5.0, 6.0, 7.0] - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketVertexPositions(dynamicObject, packet)).toEqual(true); - expect(dynamicObject.vertexPositions.getValueCartesian(Iso8601.MINIMUM_VALUE)).toEqual([new Cartesian3(1.0, 2.0, 3.0), new Cartesian3(5.0, 6.0, 7.0)]); - }); - - it('processCzmlPacketVertexPositions returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketVertexPositions(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.vertexPositions).toBeUndefined(); - }); - - it('processCzmlPacketViewFrom works.', function() { - var packet = { - 'viewFrom' : { - 'cartesian' : [1.0, 2.0, 3.0] - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketViewFrom(dynamicObject, packet)).toEqual(true); - expect(dynamicObject.viewFrom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Cartesian3(1.0, 2.0, 3.0)); - }); - - it('processCzmlPacketViewFrom returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketViewFrom(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.viewFrom).toBeUndefined(); - }); - - - it('processCzmlPacketAvailability works.', function() { - var packet = { - availability : '2000-01-01/2001-01-01' - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketAvailability(dynamicObject, packet)).toEqual(true); - - var interval = TimeInterval.fromIso8601(packet.availability); - expect(dynamicObject.availability).toEqual(interval); - }); - - it('processCzmlPacketAvailability returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicObject.processCzmlPacketAvailability(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.availability).toBeUndefined(); - }); - it('isAvailable works.', function() { - var packet = { - availability : '2000-01-01/2001-01-01' - }; - var dynamicObject = new DynamicObject('dynamicObject'); - DynamicObject.processCzmlPacketAvailability(dynamicObject, packet); - - var interval = TimeInterval.fromIso8601(packet.availability); + var interval = TimeInterval.fromIso8601('2000-01-01/2001-01-01'); + dynamicObject._setAvailability(interval); expect(dynamicObject.isAvailable(interval.start.addSeconds(-1))).toEqual(false); expect(dynamicObject.isAvailable(interval.start)).toEqual(true); expect(dynamicObject.isAvailable(interval.stop)).toEqual(true); expect(dynamicObject.isAvailable(interval.stop.addSeconds(1))).toEqual(false); }); - it('isAvailable caching works.', function() { - var packet = { - availability : '2000-01-01/2001-01-01' - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - DynamicObject.processCzmlPacketAvailability(dynamicObject, packet); - - var interval = TimeInterval.fromIso8601(packet.availability); - expect(dynamicObject.isAvailable(interval.start)).toEqual(true); - expect(dynamicObject.isAvailable(interval.start)).toEqual(true); - expect(dynamicObject.isAvailable(interval.stop)).toEqual(true); - expect(dynamicObject.isAvailable(interval.stop)).toEqual(true); - }); - it('mergeProperties does not change a fully configured billboard', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.position = 1; diff --git a/Specs/DynamicScene/DynamicObjectViewSpec.js b/Specs/DynamicScene/DynamicObjectViewSpec.js index 66668b16ab5d..b708c0588fe8 100644 --- a/Specs/DynamicScene/DynamicObjectViewSpec.js +++ b/Specs/DynamicScene/DynamicObjectViewSpec.js @@ -1,18 +1,20 @@ /*global defineSuite*/ defineSuite([ 'DynamicScene/DynamicObjectView', + 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/JulianDate', 'DynamicScene/DynamicObject', - 'Specs/MockProperty', + 'DynamicScene/ConstantPositionProperty', 'Specs/createScene', 'Specs/destroyScene' ], function( DynamicObjectView, + Cartesian3, Ellipsoid, JulianDate, DynamicObject, - MockProperty, + ConstantPositionProperty, createScene, destroyScene) { "use strict"; @@ -46,7 +48,7 @@ defineSuite([ it('update throws without time parameter', function() { var dynamicObject = new DynamicObject(); - dynamicObject.position = new MockProperty(); + dynamicObject.position = new ConstantPositionProperty(Cartesian3.ZERO); var view = new DynamicObjectView(dynamicObject, scene); expect(function() { view.update(undefined); @@ -63,7 +65,7 @@ defineSuite([ it('update throws without scene property', function() { var dynamicObject = new DynamicObject(); - dynamicObject.position = new MockProperty(); + dynamicObject.position = new ConstantPositionProperty(Cartesian3.ZERO); var view = new DynamicObjectView(dynamicObject, undefined); expect(function() { view.update(new JulianDate()); @@ -72,7 +74,7 @@ defineSuite([ it('update throws without ellipsoid property', function() { var dynamicObject = new DynamicObject(); - dynamicObject.position = new MockProperty(); + dynamicObject.position = new ConstantPositionProperty(Cartesian3.ZERO); var view = new DynamicObjectView(dynamicObject, scene); view.ellipsoid = undefined; expect(function() { diff --git a/Specs/DynamicScene/DynamicPathSpec.js b/Specs/DynamicScene/DynamicPathSpec.js index 6e0dc40c5a84..d50dcdf71c0e 100644 --- a/Specs/DynamicScene/DynamicPathSpec.js +++ b/Specs/DynamicScene/DynamicPathSpec.js @@ -16,89 +16,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite path.', function() { - var pathPacket = { - path : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - resolution : 23.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - leadTime : 2.0, - trailTime : 3.0, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPath.processCzmlPacket(dynamicObject, pathPacket)).toEqual(true); - - expect(dynamicObject.path).toBeDefined(); - expect(dynamicObject.path.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.width); - expect(dynamicObject.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.resolution); - expect(dynamicObject.path.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.path.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.outlineWidth); - expect(dynamicObject.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.leadTime); - expect(dynamicObject.path.trailTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.trailTime); - expect(dynamicObject.path.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained path.', function() { - var pathPacket = { - path : { - interval : '2000-01-01/2001-01-01', - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - resolution : 23.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - leadTime : 2.0, - trailTime : 3.0, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(pathPacket.path.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPath.processCzmlPacket(dynamicObject, pathPacket)).toEqual(true); - - expect(dynamicObject.path).toBeDefined(); - expect(dynamicObject.path.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.path.width.getValue(validTime)).toEqual(pathPacket.path.width); - expect(dynamicObject.path.resolution.getValue(validTime)).toEqual(pathPacket.path.resolution); - expect(dynamicObject.path.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.path.outlineWidth.getValue(validTime)).toEqual(pathPacket.path.outlineWidth); - expect(dynamicObject.path.leadTime.getValue(validTime)).toEqual(pathPacket.path.leadTime); - expect(dynamicObject.path.trailTime.getValue(validTime)).toEqual(pathPacket.path.trailTime); - expect(dynamicObject.path.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.path.color.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.width.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.outlineColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.outlineWidth.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.leadTime.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.trailTime.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPath.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.path).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured path', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.path = new DynamicPath(); diff --git a/Specs/DynamicScene/DynamicPathVisualizerSpec.js b/Specs/DynamicScene/DynamicPathVisualizerSpec.js index 5713697f25f3..8f59a0339ec1 100644 --- a/Specs/DynamicScene/DynamicPathVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPathVisualizerSpec.js @@ -3,22 +3,24 @@ defineSuite([ 'DynamicScene/DynamicPathVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'Core/Cartesian3', 'Core/Color', 'Core/JulianDate', 'DynamicScene/DynamicObjectCollection', - 'DynamicScene/DynamicPath' + 'DynamicScene/DynamicPath', + 'DynamicScene/SampledPositionProperty' ], function( DynamicPathVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, Cartesian3, Color, JulianDate, DynamicObjectCollection, - DynamicPath) { + DynamicPath, + SampledPositionProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -77,7 +79,7 @@ defineSuite([ visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); + testObject.position = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -88,14 +90,16 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var path = testObject.path = new DynamicPath(); - path.show = new MockProperty(true); + path.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); it('A DynamicPath causes a primtive to be created and updated.', function() { - var time = new JulianDate(); + var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; + var updateTime = new JulianDate(0.5, 0); + var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); @@ -103,73 +107,73 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); + var position = new SampledPositionProperty(); + testObject.position = position; + position.addSamples(times, positions); var path = testObject.path = new DynamicPath(); - path.show = new MockProperty(true); - path.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - path.width = new MockProperty(12.5); - path.outlineColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - path.outlineWidth = new MockProperty(2.5); - path.leadTime = new MockProperty(25); - path.trailTime = new MockProperty(10); + path.show = new ConstantProperty(true); + path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.width = new ConstantProperty(12.5); + path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path.outlineWidth = new ConstantProperty(2.5); + path.leadTime = new ConstantProperty(25); + path.trailTime = new ConstantProperty(10); - visualizer.update(time); + visualizer.update(updateTime); expect(scene.getPrimitives().getLength()).toEqual(1); var polylineCollection = scene.getPrimitives().get(0); var primitive = polylineCollection.get(0); - expect(testObject.position.lastStart).toEqual(time.addSeconds(-path.trailTime.getValue())); - expect(testObject.position.lastStop).toEqual(time.addSeconds(path.leadTime.getValue())); - expect(primitive.getShow()).toEqual(testObject.path.show.getValue(time)); - expect(primitive.getPositions()).toEqual(testObject.position.getValueRangeCartesian(time)); - expect(primitive.getWidth()).toEqual(testObject.path.width.getValue(time)); + expect(primitive.getPositions()[0]).toEqual(testObject.position.getValue(updateTime.addSeconds(-path.trailTime.getValue()))); + expect(primitive.getPositions()[1]).toEqual(testObject.position.getValue(updateTime)); + expect(primitive.getPositions()[2]).toEqual(testObject.position.getValue(updateTime.addSeconds(path.leadTime.getValue()))); + expect(primitive.getShow()).toEqual(testObject.path.show.getValue(updateTime)); + expect(primitive.getWidth()).toEqual(testObject.path.width.getValue(updateTime)); var material = primitive.getMaterial(); - expect(material.uniforms.color).toEqual(testObject.path.color.getValue(time)); - expect(material.uniforms.outlineColor).toEqual(testObject.path.outlineColor.getValue(time)); - expect(material.uniforms.outlineWidth).toEqual(testObject.path.outlineWidth.getValue(time)); - - testObject.position = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); - path.color = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - path.width = new MockProperty(2.5); - path.outlineColor = new MockProperty(new Color(0.5, 0.6, 0.7, 0.8)); - path.outlineWidth = new MockProperty(12.5); - - visualizer.update(time); - expect(primitive.getShow()).toEqual(testObject.path.show.getValue(time)); - expect(primitive.getPositions()).toEqual(testObject.position.getValueRangeCartesian(time)); - expect(primitive.getWidth()).toEqual(testObject.path.width.getValue(time)); - - expect(material.uniforms.color).toEqual(testObject.path.color.getValue(time)); - expect(material.uniforms.outlineColor).toEqual(testObject.path.outlineColor.getValue(time)); - expect(material.uniforms.outlineWidth).toEqual(testObject.path.outlineWidth.getValue(time)); - - path.show = new MockProperty(false); - visualizer.update(time); - expect(primitive.getShow()).toEqual(testObject.path.show.getValue(time)); + expect(material.uniforms.color).toEqual(testObject.path.color.getValue(updateTime)); + expect(material.uniforms.outlineColor).toEqual(testObject.path.outlineColor.getValue(updateTime)); + expect(material.uniforms.outlineWidth).toEqual(testObject.path.outlineWidth.getValue(updateTime)); + + path.show = new ConstantProperty(false); + visualizer.update(updateTime); + expect(primitive.getShow()).toEqual(testObject.path.show.getValue(updateTime)); }); it('clear hides primitives.', function() { + var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; + var updateTime = new JulianDate(0.5, 0); + var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; + var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); + expect(scene.getPrimitives().getLength()).toEqual(0); + var testObject = dynamicObjectCollection.getOrCreateObject('test'); - var time = new JulianDate(); + var position = new SampledPositionProperty(); + testObject.position = position; + position.addSamples(times, positions); - testObject.position = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); var path = testObject.path = new DynamicPath(); - path.show = new MockProperty(true); - path.leadTime = new MockProperty(5); - path.trailTime = new MockProperty(5); - visualizer.update(time); + path.show = new ConstantProperty(true); + path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.width = new ConstantProperty(12.5); + path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path.outlineWidth = new ConstantProperty(2.5); + path.leadTime = new ConstantProperty(25); + path.trailTime = new ConstantProperty(10); + + visualizer.update(updateTime); + + expect(scene.getPrimitives().getLength()).toEqual(1); var polylineCollection = scene.getPrimitives().get(0); - expect(polylineCollection.getLength()).toEqual(1); var primitive = polylineCollection.get(0); - visualizer.update(time); + visualizer.update(updateTime); //Clearing won't actually remove the primitive because of the //internal cache used by the visualizer, instead it just hides it. dynamicObjectCollection.clear(); @@ -177,50 +181,76 @@ defineSuite([ }); it('Visualizer sets dynamicObject property.', function() { + var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; + var updateTime = new JulianDate(0.5, 0); + var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; + var dynamicObjectCollection = new DynamicObjectCollection(); visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); expect(scene.getPrimitives().getLength()).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); + var position = new SampledPositionProperty(); + testObject.position = position; + position.addSamples(times, positions); - var time = new JulianDate(); var path = testObject.path = new DynamicPath(); - - testObject.position = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); - path.show = new MockProperty(true); - path.leadTime = new MockProperty(5); - path.trailTime = new MockProperty(5); - - visualizer.update(time); + path.show = new ConstantProperty(true); + path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.width = new ConstantProperty(12.5); + path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path.outlineWidth = new ConstantProperty(2.5); + path.leadTime = new ConstantProperty(25); + path.trailTime = new ConstantProperty(10); + + visualizer.update(updateTime); var polylineCollection = scene.getPrimitives().get(0); - expect(polylineCollection.getLength()).toEqual(1); var primitive = polylineCollection.get(0); expect(primitive.dynamicObject).toEqual(testObject); }); it('setDynamicObjectCollection removes old objects and add new ones.', function() { + var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; + var updateTime = new JulianDate(0.5, 0); + var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); + + expect(scene.getPrimitives().getLength()).toEqual(0); + var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); - testObject.path = new DynamicPath(); - testObject.path.show = new MockProperty(true); - testObject.path.leadTime = new MockProperty(5); - testObject.path.trailTime = new MockProperty(5); + var position = new SampledPositionProperty(); + testObject.position = position; + position.addSamples(times, positions); - var dynamicObjectCollection2 = new DynamicObjectCollection(); - var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); - testObject2.path = new DynamicPath(); - testObject2.path.show = new MockProperty(true); - testObject2.path.leadTime = new MockProperty(5); - testObject2.path.trailTime = new MockProperty(5); + var path = testObject.path = new DynamicPath(); + path.show = new ConstantProperty(true); + path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.width = new ConstantProperty(12.5); + path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path.outlineWidth = new ConstantProperty(2.5); + path.leadTime = new ConstantProperty(25); + path.trailTime = new ConstantProperty(10); - visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); + visualizer.update(updateTime); - var time = new JulianDate(); + var dynamicObjectCollection2 = new DynamicObjectCollection(); + var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); + var position2 = new SampledPositionProperty(); + testObject2.position = position; + position2.addSamples(times, positions); + + var path2 = testObject2.path = new DynamicPath(); + path2.show = new ConstantProperty(true); + path2.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path2.width = new ConstantProperty(12.5); + path2.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path2.outlineWidth = new ConstantProperty(2.5); + path2.leadTime = new ConstantProperty(25); + path2.trailTime = new ConstantProperty(10); - visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); var polylineCollection = scene.getPrimitives().get(0); expect(polylineCollection.getLength()).toEqual(1); @@ -228,7 +258,7 @@ defineSuite([ expect(primitive.dynamicObject).toEqual(testObject); visualizer.setDynamicObjectCollection(dynamicObjectCollection2); - visualizer.update(time); + visualizer.update(updateTime); expect(scene.getPrimitives().getLength()).toEqual(1); polylineCollection = scene.getPrimitives().get(0); primitive = polylineCollection.get(0); diff --git a/Specs/DynamicScene/DynamicPointSpec.js b/Specs/DynamicScene/DynamicPointSpec.js index 81ce867d5e1a..0a55041abed9 100644 --- a/Specs/DynamicScene/DynamicPointSpec.js +++ b/Specs/DynamicScene/DynamicPointSpec.js @@ -14,75 +14,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite point.', function() { - var pointPacket = { - point : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - pixelSize : 1.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPoint.processCzmlPacket(dynamicObject, pointPacket)).toEqual(true); - - expect(dynamicObject.point).toBeDefined(); - expect(dynamicObject.point.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.point.pixelSize.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.pixelSize); - expect(dynamicObject.point.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.point.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pointPacket.point.outlineWidth); - expect(dynamicObject.point.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained point.', function() { - var pointPacket = { - point : { - interval : '2000-01-01/2001-01-01', - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - pixelSize : 1.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(pointPacket.point.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPoint.processCzmlPacket(dynamicObject, pointPacket)).toEqual(true); - - expect(dynamicObject.point).toBeDefined(); - expect(dynamicObject.point.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.point.pixelSize.getValue(validTime)).toEqual(pointPacket.point.pixelSize); - expect(dynamicObject.point.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.point.outlineWidth.getValue(validTime)).toEqual(pointPacket.point.outlineWidth); - expect(dynamicObject.point.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.point.color.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.point.pixelSize.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.point.outlineColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.point.outlineWidth.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.point.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPoint.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.point).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured point', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.point = new DynamicPoint(); diff --git a/Specs/DynamicScene/DynamicPointVisualizerSpec.js b/Specs/DynamicScene/DynamicPointVisualizerSpec.js index 037042d6e2e8..cbd4529b56a6 100644 --- a/Specs/DynamicScene/DynamicPointVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPointVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicPointVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicPoint', 'DynamicScene/DynamicObjectCollection', 'Core/JulianDate', @@ -14,7 +14,7 @@ defineSuite([ DynamicPointVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, DynamicPoint, DynamicObjectCollection, JulianDate, @@ -81,7 +81,7 @@ defineSuite([ visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); visualizer.update(new JulianDate()); var billboardCollection = scene.getPrimitives().get(0); expect(billboardCollection.getLength()).toEqual(0); @@ -93,7 +93,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var point = testObject.point = new DynamicPoint(); - point.show = new MockProperty(true); + point.show = new ConstantProperty(true); visualizer.update(new JulianDate()); var billboardCollection = scene.getPrimitives().get(0); @@ -110,14 +110,14 @@ defineSuite([ expect(billboardCollection.getLength()).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var point = testObject.point = new DynamicPoint(); - point.show = new MockProperty(true); - point.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - point.pixelSize = new MockProperty(12.5); - point.outlineColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - point.outlineWidth = new MockProperty(2.5); + point.show = new ConstantProperty(true); + point.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + point.pixelSize = new ConstantProperty(12.5); + point.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + point.outlineWidth = new ConstantProperty(2.5); visualizer.update(time); @@ -127,7 +127,7 @@ defineSuite([ visualizer.update(time); expect(bb.getShow()).toEqual(testObject.point.show.getValue(time)); - expect(bb.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(bb.getPosition()).toEqual(testObject.position.getValue(time)); expect(bb._visualizerColor).toEqual(testObject.point.color.getValue(time)); expect(bb._visualizerOutlineColor).toEqual(testObject.point.outlineColor.getValue(time)); expect(bb._visualizerOutlineWidth).toEqual(testObject.point.outlineWidth.getValue(time)); @@ -144,13 +144,13 @@ defineSuite([ visualizer.update(time); expect(bb.getShow()).toEqual(testObject.point.show.getValue(time)); - expect(bb.getPosition()).toEqual(testObject.position.getValueCartesian(time)); + expect(bb.getPosition()).toEqual(testObject.position.getValue(time)); expect(bb._visualizerColor).toEqual(testObject.point.color.getValue(time)); expect(bb._visualizerOutlineColor).toEqual(testObject.point.outlineColor.getValue(time)); expect(bb._visualizerOutlineWidth).toEqual(testObject.point.outlineWidth.getValue(time)); expect(bb._visualizerPixelSize).toEqual(testObject.point.pixelSize.getValue(time)); - point.show = new MockProperty(false); + point.show = new ConstantProperty(false); visualizer.update(time); expect(bb.getShow()).toEqual(testObject.point.show.getValue(time)); }); @@ -163,9 +163,9 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var time = new JulianDate(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var point = testObject.point = new DynamicPoint(); - point.show = new MockProperty(true); + point.show = new ConstantProperty(true); visualizer.update(time); expect(billboardCollection.getLength()).toEqual(1); @@ -190,8 +190,8 @@ defineSuite([ var time = new JulianDate(); var point = testObject.point = new DynamicPoint(); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - point.show = new MockProperty(true); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + point.show = new ConstantProperty(true); visualizer.update(time); expect(billboardCollection.getLength()).toEqual(1); @@ -202,15 +202,15 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.point = new DynamicPoint(); - testObject.point.show = new MockProperty(true); + testObject.point.show = new ConstantProperty(true); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); testObject2.point = new DynamicPoint(); - testObject2.point.show = new MockProperty(true); + testObject2.point.show = new ConstantProperty(true); visualizer = new DynamicPointVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicPolygonSpec.js b/Specs/DynamicScene/DynamicPolygonSpec.js index 92b3a1f2b530..71141d98e06c 100644 --- a/Specs/DynamicScene/DynamicPolygonSpec.js +++ b/Specs/DynamicScene/DynamicPolygonSpec.js @@ -14,64 +14,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite polygon.', function() { - var polygonPacket = { - polygon : { - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolygon.processCzmlPacket(dynamicObject, polygonPacket)).toEqual(true); - - expect(dynamicObject.polygon).toBeDefined(); - expect(dynamicObject.polygon.material.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.polygon.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained polygon.', function() { - var polygonPacket = { - polygon : { - interval : '2000-01-01/2001-01-01', - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(polygonPacket.polygon.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolygon.processCzmlPacket(dynamicObject, polygonPacket)).toEqual(true); - - expect(dynamicObject.polygon).toBeDefined(); - expect(dynamicObject.polygon.material.getValue(validTime).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.polygon.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.polygon.material.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.polygon.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolygon.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.polygon).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured polygon', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.polygon = new DynamicPolygon(); diff --git a/Specs/DynamicScene/DynamicPolygonVisualizerSpec.js b/Specs/DynamicScene/DynamicPolygonVisualizerSpec.js index 27837fa2a20e..82f8231f7c96 100644 --- a/Specs/DynamicScene/DynamicPolygonVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPolygonVisualizerSpec.js @@ -3,26 +3,26 @@ defineSuite([ 'DynamicScene/DynamicPolygonVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'Core/Cartesian3', 'Core/Color', 'Core/JulianDate', 'DynamicScene/DynamicEllipse', 'DynamicScene/DynamicPolygon', 'DynamicScene/DynamicObjectCollection', - 'Scene/Material' + 'DynamicScene/ColorMaterialProperty' ], function( DynamicPolygonVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, Cartesian3, Color, JulianDate, DynamicEllipse, DynamicPolygon, DynamicObjectCollection, - Material) { + ColorMaterialProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -81,7 +81,7 @@ defineSuite([ visualizer = new DynamicPolygonVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -92,7 +92,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); + polygon.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -105,7 +105,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.ellipse = new DynamicEllipse(); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); + polygon.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -116,10 +116,10 @@ defineSuite([ visualizer = new DynamicPolygonVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.ellipse = new DynamicEllipse(); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); + polygon.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -135,17 +135,15 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); - var colorMaterial = Material.fromType(scene.getContext(), Material.ColorType); - colorMaterial.uniforms.color = new Color(0.7, 0.6, 0.5, 0.4); - polygon.material = new MockProperty(colorMaterial); + polygon.show = new ConstantProperty(true); + polygon.material = new ColorMaterialProperty(); var ellipse = testObject.ellipse = new DynamicEllipse(); - ellipse.bearing = new MockProperty(0); - ellipse.semiMajorAxis = new MockProperty(1000); - ellipse.semiMinorAxis = new MockProperty(1000); + ellipse.bearing = new ConstantProperty(0); + ellipse.semiMajorAxis = new ConstantProperty(1000); + ellipse.semiMinorAxis = new ConstantProperty(1000); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -154,7 +152,7 @@ defineSuite([ visualizer.update(time); expect(primitive.show).toEqual(testObject.polygon.show.getValue(time)); - expect(primitive.material).toEqual(testObject.polygon.material.getValue(time)); + expect(primitive.material.uniforms).toEqual(testObject.polygon.material.getValue(time)); expect(primitive.getPositions().length > 0); }); @@ -168,13 +166,11 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(0); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); - var colorMaterial = Material.fromType(scene.getContext(), Material.ColorType); - colorMaterial.uniforms.color = new Color(0.7, 0.6, 0.5, 0.4); - polygon.material = new MockProperty(colorMaterial); + polygon.show = new ConstantProperty(true); + polygon.material = new ColorMaterialProperty(); visualizer.update(time); @@ -184,18 +180,16 @@ defineSuite([ visualizer.update(time); expect(primitive.show).toEqual(testObject.polygon.show.getValue(time)); - expect(primitive.material).toEqual(testObject.polygon.material.getValue(time)); + expect(primitive.material.uniforms).toEqual(testObject.polygon.material.getValue(time)); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); - colorMaterial = Material.fromType(scene.getContext(), Material.ColorType); - colorMaterial.uniforms.color = new Color(0.1, 0.2, 0.4, 0.3); - polygon.material = new MockProperty(colorMaterial); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); + polygon.material = new ColorMaterialProperty(); visualizer.update(time); expect(primitive.show).toEqual(testObject.polygon.show.getValue(time)); - expect(primitive.material).toEqual(testObject.polygon.material.getValue(time)); + expect(primitive.material.uniforms).toEqual(testObject.polygon.material.getValue(time)); - polygon.show = new MockProperty(false); + polygon.show = new ConstantProperty(false); visualizer.update(time); expect(primitive.show).toEqual(testObject.polygon.show.getValue(time)); }); @@ -207,9 +201,9 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var time = new JulianDate(); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); var polygon = testObject.polygon = new DynamicPolygon(); - polygon.show = new MockProperty(true); + polygon.show = new ConstantProperty(true); visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -233,8 +227,8 @@ defineSuite([ var time = new JulianDate(); var polygon = testObject.polygon = new DynamicPolygon(); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); - polygon.show = new MockProperty(true); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); + polygon.show = new ConstantProperty(true); visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -245,15 +239,15 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112), new Cartesian3(1234, 5678, 910111)]); testObject.polygon = new DynamicPolygon(); - testObject.polygon.show = new MockProperty(true); + testObject.polygon.show = new ConstantProperty(true); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); + testObject2.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 910111)]); testObject2.polygon = new DynamicPolygon(); - testObject2.polygon.show = new MockProperty(true); + testObject2.polygon.show = new ConstantProperty(true); visualizer = new DynamicPolygonVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicPolylineSpec.js b/Specs/DynamicScene/DynamicPolylineSpec.js index edc604901a64..9d01220aceb6 100644 --- a/Specs/DynamicScene/DynamicPolylineSpec.js +++ b/Specs/DynamicScene/DynamicPolylineSpec.js @@ -16,75 +16,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite polyline.', function() { - var polylinePacket = { - polyline : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolyline.processCzmlPacket(dynamicObject, polylinePacket)).toEqual(true); - - expect(dynamicObject.polyline).toBeDefined(); - expect(dynamicObject.polyline.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.polyline.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.width); - expect(dynamicObject.polyline.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.polyline.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(polylinePacket.polyline.outlineWidth); - expect(dynamicObject.polyline.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained polyline.', function() { - var polylinePacket = { - polyline : { - interval : '2000-01-01/2001-01-01', - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - outlineColor : { - rgbaf : [0.2, 0.2, 0.2, 0.2] - }, - outlineWidth : 1.0, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(polylinePacket.polyline.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolyline.processCzmlPacket(dynamicObject, polylinePacket)).toEqual(true); - - expect(dynamicObject.polyline).toBeDefined(); - expect(dynamicObject.polyline.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.polyline.width.getValue(validTime)).toEqual(polylinePacket.polyline.width); - expect(dynamicObject.polyline.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.polyline.outlineWidth.getValue(validTime)).toEqual(polylinePacket.polyline.outlineWidth); - expect(dynamicObject.polyline.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.polyline.color.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.polyline.width.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.polyline.outlineColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.polyline.outlineWidth.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.polyline.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPolyline.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.polyline).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured polyline', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.polyline = new DynamicPolyline(); diff --git a/Specs/DynamicScene/DynamicPolylineVisualizerSpec.js b/Specs/DynamicScene/DynamicPolylineVisualizerSpec.js index bbc37a717174..e81646a01730 100644 --- a/Specs/DynamicScene/DynamicPolylineVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPolylineVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicPolylineVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicEllipse', 'DynamicScene/DynamicPolyline', 'DynamicScene/DynamicObjectCollection', @@ -17,7 +17,7 @@ defineSuite([ DynamicPolylineVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, DynamicEllipse, DynamicPolyline, DynamicObjectCollection, @@ -85,7 +85,7 @@ defineSuite([ visualizer = new DynamicPolylineVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); var polylineCollection = scene.getPrimitives().get(0); @@ -98,7 +98,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); + polyline.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -113,7 +113,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); testObject.ellipse = new DynamicEllipse(); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); + polyline.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -126,10 +126,10 @@ defineSuite([ visualizer = new DynamicPolylineVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject.ellipse = new DynamicEllipse(); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); + polyline.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -146,14 +146,14 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(1); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); + polyline.show = new ConstantProperty(true); var ellipse = testObject.ellipse = new DynamicEllipse(); - ellipse.bearing = new MockProperty(0); - ellipse.semiMajorAxis = new MockProperty(1000); - ellipse.semiMinorAxis = new MockProperty(1000); + ellipse.bearing = new ConstantProperty(0); + ellipse.semiMajorAxis = new ConstantProperty(1000); + ellipse.semiMinorAxis = new ConstantProperty(1000); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -181,14 +181,14 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(1); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); - polyline.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - polyline.width = new MockProperty(12.5); - polyline.outlineColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - polyline.outlineWidth = new MockProperty(2.5); + polyline.show = new ConstantProperty(true); + polyline.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + polyline.width = new ConstantProperty(12.5); + polyline.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + polyline.outlineWidth = new ConstantProperty(2.5); visualizer.update(time); @@ -198,7 +198,7 @@ defineSuite([ var primitive = polylineCollection.get(0); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.polyline.show.getValue(time)); - expect(primitive.getPositions()).toEqual(testObject.vertexPositions.getValueCartesian(time)); + expect(primitive.getPositions()).toEqual(testObject.vertexPositions.getValue(time)); expect(primitive.getWidth()).toEqual(testObject.polyline.width.getValue(time)); var material = primitive.getMaterial(); @@ -206,15 +206,15 @@ defineSuite([ expect(material.uniforms.outlineColor).toEqual(testObject.polyline.outlineColor.getValue(time)); expect(material.uniforms.outlineWidth).toEqual(testObject.polyline.outlineWidth.getValue(time)); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); - polyline.color = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - polyline.width = new MockProperty(2.5); - polyline.outlineColor = new MockProperty(new Color(0.5, 0.6, 0.7, 0.8)); - polyline.outlineWidth = new MockProperty(12.5); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); + polyline.color = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + polyline.width = new ConstantProperty(2.5); + polyline.outlineColor = new ConstantProperty(new Color(0.5, 0.6, 0.7, 0.8)); + polyline.outlineWidth = new ConstantProperty(12.5); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.polyline.show.getValue(time)); - expect(primitive.getPositions()).toEqual(testObject.vertexPositions.getValueCartesian(time)); + expect(primitive.getPositions()).toEqual(testObject.vertexPositions.getValue(time)); expect(primitive.getWidth()).toEqual(testObject.polyline.width.getValue(time)); material = primitive.getMaterial(); @@ -222,7 +222,7 @@ defineSuite([ expect(material.uniforms.outlineColor).toEqual(testObject.polyline.outlineColor.getValue(time)); expect(material.uniforms.outlineWidth).toEqual(testObject.polyline.outlineWidth.getValue(time)); - polyline.show = new MockProperty(false); + polyline.show = new ConstantProperty(false); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.polyline.show.getValue(time)); }); @@ -234,9 +234,9 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var time = new JulianDate(); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); var polyline = testObject.polyline = new DynamicPolyline(); - polyline.show = new MockProperty(true); + polyline.show = new ConstantProperty(true); visualizer.update(time); var polylineCollection = scene.getPrimitives().get(0); @@ -261,8 +261,8 @@ defineSuite([ var time = new JulianDate(); var polyline = testObject.polyline = new DynamicPolyline(); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); - polyline.show = new MockProperty(true); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); + polyline.show = new ConstantProperty(true); visualizer.update(time); var polylineCollection = scene.getPrimitives().get(0); @@ -274,15 +274,15 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.vertexPositions = new MockProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); + testObject.vertexPositions = new ConstantProperty([new Cartesian3(5678, 1234, 1101112), new Cartesian3(1234, 5678, 9101112)]); testObject.polyline = new DynamicPolyline(); - testObject.polyline.show = new MockProperty(true); + testObject.polyline.show = new ConstantProperty(true); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.vertexPositions = new MockProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); + testObject2.vertexPositions = new ConstantProperty([new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]); testObject2.polyline = new DynamicPolyline(); - testObject2.polyline.show = new MockProperty(true); + testObject2.polyline.show = new ConstantProperty(true); visualizer = new DynamicPolylineVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicPositionPropertySpec.js b/Specs/DynamicScene/DynamicPositionPropertySpec.js deleted file mode 100644 index 2cda571dc87d..000000000000 --- a/Specs/DynamicScene/DynamicPositionPropertySpec.js +++ /dev/null @@ -1,301 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/DynamicPositionProperty', - 'Core/JulianDate', - 'Core/Ellipsoid', - 'Core/Cartesian3', - 'Core/Cartographic', - 'Core/Math' - ], function( - DynamicPositionProperty, - JulianDate, - Ellipsoid, - Cartesian3, - Cartographic, - CesiumMath) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var cartesianInterval = { - epoch : '2012-04-18T15:59:00Z', - cartesian : [0, 100000, 100001, 100002, 3600, 100010, 100011, 100012, 7200, 100020, 100021, 100022], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - - var cartographicInterval = { - cartographicRadians: ['2012-04-18T15:59:00Z', 0.1, 0.2, 1000, '2012-04-18T16:59:00Z', 0.3, 0.4, 500, '2012-04-18T17:59:00Z', 0.5, 0.6, 750], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - - var epoch = JulianDate.fromIso8601(cartesianInterval.epoch); - - it('getValueCartesian returns undefined if no data exists', function() { - var property = new DynamicPositionProperty(); - expect(property.getValueCartesian(new JulianDate())).toBeUndefined(); - }); - - it('getValueCartesian throw if no time supplied', function() { - var property = new DynamicPositionProperty(); - expect(function() { - property.getValueCartesian(); - }).toThrow(); - }); - - it('getValueCartesian works for cartesian data', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianInterval); - - var result = property.getValueCartesian(epoch); - expect(result.x).toEqual(100000); - expect(result.y).toEqual(100001); - expect(result.z).toEqual(100002); - }); - - it('getValueCartographic returns undefined if no data exists', function() { - var property = new DynamicPositionProperty(); - expect(property.getValueCartographic(new JulianDate())).toBeUndefined(); - }); - - it('getValueCartographic throw if no time supplied', function() { - var property = new DynamicPositionProperty(); - expect(function() { - property.getValueCartographic(); - }).toThrow(); - }); - - it('getValueCartographic works for cartesian data', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianInterval); - - var cartographic = Ellipsoid.WGS84.cartesianToCartographic(property.getValueCartesian(epoch)); - var result = property.getValueCartographic(epoch); - expect(result.longitude).toEqual(cartographic.longitude); - expect(result.latitude).toEqual(cartographic.latitude); - expect(result.height).toEqual(cartographic.height); - }); - - it('getValueCartographic works for cartographic data', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartographicInterval); - - var result = property.getValueCartographic(epoch); - expect(result.longitude).toEqualEpsilon(0.1, CesiumMath.EPSILON16); - expect(result.latitude).toEqualEpsilon(0.2, CesiumMath.EPSILON16); - expect(result.height).toEqualEpsilon(1000, CesiumMath.EPSILON8); - }); - - it('getValueCartesian works for cartographic data', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartographicInterval); - - var cartesian = Ellipsoid.WGS84.cartographicToCartesian(property.getValueCartographic(epoch)); - var result = property.getValueCartesian(epoch); - expect(result.x).toEqualEpsilon(cartesian.x, CesiumMath.EPSILON9); - expect(result.y).toEqualEpsilon(cartesian.y, CesiumMath.EPSILON9); - expect(result.z).toEqualEpsilon(cartesian.z, CesiumMath.EPSILON9); - }); - - var cartesian0 = new Cartesian3(0.0, 0.0, 0.0); - var cartesian1 = new Cartesian3(1.0, 1.0, 1.0); - var cartesian2 = new Cartesian3(2.0, 2.0, 2.0); - var cartographic3 = new Cartographic(0.3, 0.3, 0.3); - var cartographic4 = new Cartographic(0.4, 0.4, 0.4); - var cartographic5 = new Cartographic(0.5, 0.5, 0.5); - var cartesian6 = new Cartesian3(6.0, 6.0, 6.0); - var cartographic7 = new Cartographic(0.7, 0.7, 0.7); - - var cartesianForgetValueRangeCartesian = { - interval : '2012-08-01T00:00:00Z/2012-08-01T00:00:02Z', - epoch : '2012-08-01T00:00:00Z', - cartesian : [0, cartesian0.x, cartesian0.y, cartesian0.z, 1, cartesian1.x, cartesian1.y, cartesian1.z, 2, cartesian2.x, cartesian2.y, cartesian2.z], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - - var cartographicForgetValueRangeCartesian = { - interval : '2012-08-01T00:00:02Z/2012-08-01T00:00:04Z', - epoch : '2012-08-01T00:00:02Z', - cartographicRadians : [0, cartographic3.longitude, cartographic3.latitude, cartographic3.height, 1, cartographic4.longitude, cartographic4.latitude, cartographic4.height, 2, cartographic5.longitude, cartographic5.latitude, cartographic5.height], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - - var staticIntervalCartesian = { - interval : '2012-08-01T00:00:05Z/2012-08-01T00:00:06Z', - cartesian : [cartesian6.x, cartesian6.y, cartesian6.z] - }; - - var staticIntervalCartographic = { - interval : '2012-08-01T00:00:05Z/2012-08-01T00:00:06Z', - cartographicRadians : [cartographic7.longitude, cartographic7.latitude, cartographic7.height] - }; - - it('getValueRangeCartesian works with single cartesian interval', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(0); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(2); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(cartesian0); - expect(result[1]).toEqual(cartesian1); - expect(result[2]).toEqual(cartesian2); - }); - - it('getValueRangeCartesian works with single cartesian interval and currentTime', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(0); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(2); - var currentTime = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(1.5); - var result = property.getValueRangeCartesian(start, stop, currentTime); - expect(result.length).toEqual(4); - expect(result[0]).toEqual(cartesian0); - expect(result[1]).toEqual(cartesian1); - expect(result[2]).toEqual(Cartesian3.lerp(cartesian1, cartesian2, 0.5)); - expect(result[3]).toEqual(cartesian2); - }); - - it('getValueRangeCartesian works with a result parameter', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(0); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(2); - var existingCartesian0 = new Cartesian3(); - var existingCartesian1 = new Cartesian3(); - var existingCartesian2 = new Cartesian3(); - var result = [existingCartesian0, existingCartesian1, existingCartesian2, new Cartesian3(), new Cartesian3()]; - - var returnedResult = property.getValueRangeCartesian(start, stop, undefined, result); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(cartesian0); - expect(result[1]).toEqual(cartesian1); - expect(result[2]).toEqual(cartesian2); - expect(returnedResult).toBe(result); - expect(result[0]).toBe(existingCartesian0); - expect(result[1]).toBe(existingCartesian1); - expect(result[2]).toBe(existingCartesian2); - }); - - it('getValueRangeCartesian does not sample currentTime outside of start/stop time', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(0); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(2); - var currentTime = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(30); - var result = property.getValueRangeCartesian(start, stop, currentTime); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(cartesian0); - expect(result[1]).toEqual(cartesian1); - expect(result[2]).toEqual(cartesian2); - }); - - it('getValueRangeCartesian does not sample start/stop if outside of data', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(-100); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(+200); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(cartesian0); - expect(result[1]).toEqual(cartesian1); - expect(result[2]).toEqual(cartesian2); - }); - - it('getValueRangeCartesian works with single cartographic interval', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartographicForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartographicForgetValueRangeCartesian.epoch).addSeconds(0); - var stop = JulianDate.fromIso8601(cartographicForgetValueRangeCartesian.epoch).addSeconds(2); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic3)); - expect(result[1]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic4)); - expect(result[2]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic5)); - }); - - it('getValueRangeCartesian works across intervals', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals([cartesianForgetValueRangeCartesian, cartographicForgetValueRangeCartesian]); - - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(1); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(3); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(cartesian1); - expect(result[1]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic3)); - expect(result[2]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic4)); - }); - - it('getValueRangeCartesian works across non-sampled intervals', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals([cartesianForgetValueRangeCartesian, cartographicForgetValueRangeCartesian, staticIntervalCartesian]); - - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(1); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(6); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(6); - expect(result[0]).toEqual(cartesian1); - expect(result[1]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic3)); - expect(result[2]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic4)); - expect(result[3]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic5)); - expect(result[4]).toEqual(cartesian6); - expect(result[5]).toEqual(cartesian6); - }); - - it('getValueRangeCartesian works across non-sampled cartographic intervals', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals([cartesianForgetValueRangeCartesian, cartographicForgetValueRangeCartesian, staticIntervalCartographic]); - - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(1); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(5); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(5); - expect(result[0]).toEqual(cartesian1); - expect(result[1]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic3)); - expect(result[2]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic4)); - expect(result[3]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic5)); - expect(result[4]).toEqual(Ellipsoid.WGS84.cartographicToCartesian(cartographic7)); - }); - - it('getValueRangeCartesian works with no data', function() { - var property = new DynamicPositionProperty(); - var result = property.getValueRangeCartesian(new JulianDate(), new JulianDate()); - expect(result.length).toEqual(0); - }); - - it('getValueRangeCartesian works if requested interval is before any data.', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(-10); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(-5); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(0); - }); - - it('getValueRangeCartesian works if requested interval is after all data.', function() { - var property = new DynamicPositionProperty(); - property.processCzmlIntervals(cartesianForgetValueRangeCartesian); - var start = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(10); - var stop = JulianDate.fromIso8601(cartesianForgetValueRangeCartesian.epoch).addSeconds(5); - var result = property.getValueRangeCartesian(start, stop); - expect(result.length).toEqual(0); - }); - - it('getValueRangeCartesian throws with no start time', function() { - var property = new DynamicPositionProperty(); - expect(function() { - property.getValueRangeCartesian(undefined, new JulianDate()); - }).toThrow(); - }); - - it('getValueRangeCartesian throws with no stop time', function() { - var property = new DynamicPositionProperty(); - expect(function() { - property.getValueRangeCartesian(new JulianDate(), undefined); - }).toThrow(); - }); -}); diff --git a/Specs/DynamicScene/DynamicPropertySpec.js b/Specs/DynamicScene/DynamicPropertySpec.js deleted file mode 100644 index 0589910028fa..000000000000 --- a/Specs/DynamicScene/DynamicPropertySpec.js +++ /dev/null @@ -1,334 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/DynamicProperty', - 'Core/JulianDate', - 'DynamicScene/CzmlBoolean', - 'DynamicScene/CzmlNumber', - 'DynamicScene/CzmlUnitQuaternion', - 'Core/Quaternion', - 'Core/Math', - 'Core/LinearApproximation', - 'Core/HermitePolynomialApproximation', - 'Core/LagrangePolynomialApproximation' - ], function( - DynamicProperty, - JulianDate, - CzmlBoolean, - CzmlNumber, - CzmlUnitQuaternion, - Quaternion, - CesiumMath, - LinearApproximation, - HermitePolynomialApproximation, - LagrangePolynomialApproximation) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - it('Works with uninterpolatable value types.', function() { - var dynamicProperty = new DynamicProperty(CzmlBoolean); - - var booleanConstant = true; - - var booleanVerbose = { - boolean : false - }; - - var booleanInterval = { - interval : '2012-04-18T16:00:00Z/2012-04-19T16:00:00Z', - boolean : true - }; - - var booleanIntervalArray = [{ - interval : '2012-04-18T17:00:00Z/2012-04-18T18:00:00Z', - boolean : true - }, { - interval : '2012-04-18T16:00:00Z/2012-04-18T16:05:00Z', - boolean : true - }]; - - dynamicProperty.processCzmlIntervals(booleanConstant); - expect(dynamicProperty.getValue(new JulianDate())).toEqual(true); - - dynamicProperty.processCzmlIntervals(booleanVerbose); - expect(dynamicProperty.getValue(new JulianDate())).toEqual(false); - - dynamicProperty.processCzmlIntervals(booleanInterval); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-18T15:59:00Z'))).toEqual(false); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-18T16:00:00Z'))).toEqual(true); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-19T16:00:00Z'))).toEqual(true); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-19T16:01:00Z'))).toEqual(false); - - dynamicProperty.processCzmlIntervals(booleanIntervalArray); - dynamicProperty.processCzmlIntervals(booleanVerbose); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-18T16:00:00Z'))).toEqual(false); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-18T17:30:00Z'))).toEqual(false); - expect(dynamicProperty.getValue(JulianDate.fromIso8601('2012-04-18T16:06:00Z'))).toEqual(false); - }); - - it('Works with interpolatable values (default linear interpolator).', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlNumber); - var czmlInterval = { - epoch : iso8601Epoch, - number : [0, 0, 10, 10, 20, 20] - }; - property.processCzmlIntervals(czmlInterval); - - expect(property.getValue(epoch)).toEqual(0); - expect(property.getValue(epoch.addSeconds(4))).toEqual(4); - //Look inside to verify it's using LinearApproximation - expect(property._intervals.get(0).data.interpolationAlgorithm).toEqual(LinearApproximation); - }); - - it('Works with interpolatable value types (specified linear interpolator).', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlNumber); - var czmlInterval = { - epoch : iso8601Epoch, - number : [0, 0, 10, 10, 20, 20], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - property.processCzmlIntervals(czmlInterval); - - expect(property.getValue(epoch)).toEqual(0); - expect(property.getValue(epoch.addSeconds(4))).toEqual(4); - //Look inside to verify it's using LinearApproximation - expect(property._intervals.get(0).data.interpolationAlgorithm).toEqual(LinearApproximation); - }); - - it('Works with interpolatable value types (specified lagrange interpolator).', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlNumber); - var czmlInterval = { - epoch : iso8601Epoch, - number : [0, 0, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50], - interpolationAlgorithm : 'LAGRANGE', - interpolationDegree : 5 - }; - property.processCzmlIntervals(czmlInterval); - - expect(property.getValue(epoch)).toEqual(0); - expect(property.getValue(epoch.addSeconds(5))).toEqual(5); - - //Look inside to verify it's using LaGrange - expect(property._intervals.get(0).data.interpolationAlgorithm).toEqual(LagrangePolynomialApproximation); - }); - - - it('Works with interpolatable value types (specified hermite interpolator).', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlNumber); - var czmlInterval = { - epoch : iso8601Epoch, - number : [0, 0, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50], - interpolationAlgorithm : 'HERMITE', - interpolationDegree : 3 - }; - property.processCzmlIntervals(czmlInterval); - - expect(property.getValue(epoch)).toEqual(0); - expect(property.getValue(epoch.addSeconds(4))).toEqual(4); - - //Look inside to verify it's using Hermite - expect(property._intervals.get(0).data.interpolationAlgorithm).toEqual(HermitePolynomialApproximation); - }); - - it('Works with custom packed value types.', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlUnitQuaternion); - - var czmlInterval = { - epoch : iso8601Epoch, - unitQuaternion : [0, 1, 0, 0, 0, 10, 0, 1, 0, 0], - interpolationAlgorithm : 'LINEAR', - interpolationDegree : 1 - }; - property.processCzmlIntervals(czmlInterval); - - var result = property.getValue(epoch); - expect(result.x).toEqual(1); - expect(result.y).toEqual(0); - expect(result.z).toEqual(0); - expect(result.w).toEqual(0); - - result = property.getValue(epoch.addSeconds(5)); - var expected = new Quaternion(0.707106781186547, 0.707106781186548, 0, 0); - expect(new Quaternion(result.x, result.y, result.z, result.w)).toEqualEpsilon(expected, CesiumMath.EPSILON15); - - result = property.getValue(epoch.addSeconds(10)); - expect(result.x).toEqual(0); - expect(result.y).toEqual(1); - expect(result.z).toEqual(0); - expect(result.w).toEqual(0); - }); - - it('Returns undefined if trying to interpolate with less than two samples.', function() { - var iso8601Epoch = '2012-04-18T15:59:00Z'; - var epoch = JulianDate.fromIso8601(iso8601Epoch); - - var property = new DynamicProperty(CzmlNumber); - var czmlInterval = { - epoch : iso8601Epoch, - number : [0, 0] - }; - property.processCzmlIntervals(czmlInterval); - - expect(property.getValue(epoch)).toEqual(0); - expect(property.getValue(epoch.addSeconds(4))).toBeUndefined(); - }); - - it('_mergeNewSamples works with huge data sets.', function() { - var times = []; - var values = []; - var epoch = new JulianDate(); - - var data = []; - var expectedTimes = []; - var expectedValues = []; - - for ( var i = 0; i < 200000; i++) { - data.push(i); - data.push(i); - expectedTimes.push(epoch.addSeconds(i)); - expectedValues.push(i); - } - - DynamicProperty._mergeNewSamples(epoch, times, values, data, 1); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - it('_mergeNewSamples works for sorted non-intersecting data.', function() { - var times = []; - var values = []; - var epoch = new JulianDate(); - - var newData = [0, 'a', 1, 'b', 2, 'c']; - var newData2 = [3, 'd', 4, 'e', 5, 'f']; - - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; - var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; - - DynamicProperty._mergeNewSamples(epoch, times, values, newData, 1); - DynamicProperty._mergeNewSamples(epoch, times, values, newData2, 1); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - it('_mergeNewSamples works for ISO8601 dates', function() { - var times = []; - var values = []; - var epoch = JulianDate.fromIso8601('2010-01-01T12:00:00'); - - var newData = ['2010-01-01T12:00:00', 'a', '2010-01-01T12:00:01', 'b', '2010-01-01T12:00:02', 'c']; - var newData2 = ['2010-01-01T12:00:03', 'd', '2010-01-01T12:00:04', 'e', '2010-01-01T12:00:05', 'f']; - - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; - var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; - - DynamicProperty._mergeNewSamples(undefined, times, values, newData, 1); - DynamicProperty._mergeNewSamples(undefined, times, values, newData2, 1); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - it('_mergeNewSamples works for elements of size 2.', function() { - var times = []; - var values = []; - var epoch = new JulianDate(); - - var newData = [1, 'b', 'b', 4, 'e', 'e', 0, 'a', 'a']; - var newData2 = [2, 'c', 'c', 3, 'd', 'd']; - - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4)]; - var expectedValues = ['a', 'a', 'b', 'b', 'c', 'c', 'd', 'd', 'e', 'e']; - - DynamicProperty._mergeNewSamples(epoch, times, values, newData, 2); - DynamicProperty._mergeNewSamples(epoch, times, values, newData2, 2); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - it('_mergeNewSamples works for unsorted intersecting data.', function() { - var times = []; - var values = []; - var epoch = new JulianDate(); - - var newData = [1, 'b', 4, 'e', 0, 'a']; - var newData2 = [5, 'f', 2, 'c', 3, 'd']; - - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; - var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; - - DynamicProperty._mergeNewSamples(epoch, times, values, newData, 1); - DynamicProperty._mergeNewSamples(epoch, times, values, newData2, 1); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - it('_mergeNewSamples works for data with repeated values.', function() { - var times = []; - var values = []; - var epoch = new JulianDate(); - - var newData = [0, 'a', 1, 'b', 1, 'c', 0, 'd', 4, 'e', 5, 'f']; - var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(4), epoch.addSeconds(5)]; - var expectedValues = ['d', 'c', 'e', 'f']; - DynamicProperty._mergeNewSamples(epoch, times, values, newData, 1); - - expect(times).toEqual(expectedTimes, JulianDate.compare); - expect(values).toEqual(expectedValues); - }); - - var interwovenData = [{ - epoch : JulianDate.fromIso8601("20130205T150405.704999999999927Z"), - values : [0.0, 1, - 120.0, 2, - 240.0, 3, - 360.0, 4, - 480.0, 6, - 600.0, 8, - 720.0, 10, - 840.0, 12, - 960.0, 14, - 1080.0, 16] - }, { - epoch : JulianDate.fromIso8601("20130205T151151.60499999999956Z"), - values : [0.0, 5, - 120.0, 7, - 240.0, 9, - 360.0, 11, - 480.0, 13, - 600.0, 15, - 720.0, 17, - 840.0, 18, - 960.0, 19, - 1080.0, 20] - }]; - - it('_mergeNewSamples works with interwoven data', function() { - var times = []; - var values = []; - DynamicProperty._mergeNewSamples(interwovenData[0].epoch, times, values, interwovenData[0].values, 1); - DynamicProperty._mergeNewSamples(interwovenData[1].epoch, times, values, interwovenData[1].values, 1); - for ( var i = 0; i < values.length; i++) { - expect(values[i]).toBe(i + 1); - } - }); -}); diff --git a/Specs/DynamicScene/DynamicPyramidSpec.js b/Specs/DynamicScene/DynamicPyramidSpec.js index 0eb751864cb4..7eb288a3080f 100644 --- a/Specs/DynamicScene/DynamicPyramidSpec.js +++ b/Specs/DynamicScene/DynamicPyramidSpec.js @@ -18,101 +18,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite pyramid.', function() { - var pyramidPacket = { - pyramid : { - directions : { - unitSpherical : [1.0, 2.0, 3.0, 4.0] - }, - radius : 2.0, - show : true, - showIntersection : false, - intersectionWidth : 7.0, - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - intersectionColor : { - rgbaf : [0.5, 0.5, 0.5, 0.5] - } - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPyramid.processCzmlPacket(dynamicObject, pyramidPacket)).toEqual(true); - - expect(dynamicObject.pyramid).toBeDefined(); - expect(dynamicObject.pyramid.directions.getValueSpherical(Iso8601.MINIMUM_VALUE)).toEqual( - [new Spherical(pyramidPacket.pyramid.directions.unitSpherical[0], pyramidPacket.pyramid.directions.unitSpherical[1]), - new Spherical(pyramidPacket.pyramid.directions.unitSpherical[2], pyramidPacket.pyramid.directions.unitSpherical[3])]); - expect(dynamicObject.pyramid.radius.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.radius); - expect(dynamicObject.pyramid.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.show); - expect(dynamicObject.pyramid.showIntersection.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pyramidPacket.pyramid.showIntersection); - expect(dynamicObject.pyramid.material.getValue(Iso8601.MINIMUM_VALUE).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.pyramid.intersectionColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); - expect(dynamicObject.pyramid.intersectionWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(7.0); - }); - - it('processCzmlPacket adds data for constrained pyramid.', function() { - var pyramidPacket = { - pyramid : { - interval : '2000-01-01/2001-01-01', - directions : { - unitSpherical : [1.0, 2.0, 3.0, 4.0] - }, - radius : 2.0, - show : true, - showIntersection : false, - intersectionWidth : 8.0, - material : { - solidColor : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - } - } - }, - intersectionColor : { - rgbaf : [0.5, 0.5, 0.5, 0.5] - } - } - }; - - var validTime = TimeInterval.fromIso8601(pyramidPacket.pyramid.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPyramid.processCzmlPacket(dynamicObject, pyramidPacket)).toEqual(true); - - expect(dynamicObject.pyramid).toBeDefined(); - expect(dynamicObject.pyramid.directions.getValueSpherical(validTime)).toEqual( - [new Spherical(pyramidPacket.pyramid.directions.unitSpherical[0], pyramidPacket.pyramid.directions.unitSpherical[1]), - new Spherical(pyramidPacket.pyramid.directions.unitSpherical[2], pyramidPacket.pyramid.directions.unitSpherical[3])]); - expect(dynamicObject.pyramid.radius.getValue(validTime)).toEqual(pyramidPacket.pyramid.radius); - expect(dynamicObject.pyramid.show.getValue(validTime)).toEqual(pyramidPacket.pyramid.show); - expect(dynamicObject.pyramid.showIntersection.getValue(validTime)).toEqual(pyramidPacket.pyramid.showIntersection); - expect(dynamicObject.pyramid.material.getValue(validTime).uniforms.color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.pyramid.intersectionColor.getValue(validTime)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); - expect(dynamicObject.pyramid.intersectionWidth.getValue(validTime)).toEqual(8.0); - - expect(dynamicObject.pyramid.directions.getValueSpherical(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.radius.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.show.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.showIntersection.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.material.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.intersectionColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.pyramid.intersectionWidth.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicPyramid.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.pyramid).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured pyramid', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.pyramid = new DynamicPyramid(); diff --git a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js index 35b320c82324..d3bdb0eb85fa 100644 --- a/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPyramidVisualizerSpec.js @@ -3,7 +3,7 @@ defineSuite([ 'DynamicScene/DynamicPyramidVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'Core/Color', 'Core/JulianDate', 'Core/Matrix3', @@ -13,12 +13,12 @@ defineSuite([ 'Core/Spherical', 'DynamicScene/DynamicPyramid', 'DynamicScene/DynamicObjectCollection', - 'Scene/Material' + 'DynamicScene/ColorMaterialProperty' ], function( DynamicPyramidVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, Color, JulianDate, Matrix3, @@ -28,7 +28,7 @@ defineSuite([ Spherical, DynamicPyramid, DynamicObjectCollection, - Material) { + ColorMaterialProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -86,8 +86,8 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -97,9 +97,9 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -109,9 +109,9 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(0); }); @@ -122,19 +122,17 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); - pyramid.intersectionColor = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - pyramid.intersectionWidth = new MockProperty(0.5); - pyramid.showIntersection = new MockProperty(true); - pyramid.radius = new MockProperty(123.5); - pyramid.show = new MockProperty(true); - var redMaterial = Material.fromType(scene.getContext(), Material.ColorType); - redMaterial.uniforms.color = Color.RED; - pyramid.material = new MockProperty(redMaterial); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.intersectionColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + pyramid.intersectionWidth = new ConstantProperty(0.5); + pyramid.showIntersection = new ConstantProperty(true); + pyramid.radius = new ConstantProperty(123.5); + pyramid.show = new ConstantProperty(true); + pyramid.material = new ColorMaterialProperty(); visualizer.update(time); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -144,8 +142,8 @@ defineSuite([ expect(p.showIntersection).toEqual(testObject.pyramid.showIntersection.getValue(time)); expect(p.radius).toEqual(testObject.pyramid.radius.getValue(time)); expect(p.show).toEqual(testObject.pyramid.show.getValue(time)); - expect(p.material).toEqual(testObject.pyramid.material.getValue(time)); - expect(p.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValueCartesian(time))); + expect(p.material.uniforms).toEqual(testObject.pyramid.material.getValue(time)); + expect(p.modelMatrix).toEqual(Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(testObject.orientation.getValue(time).conjugate()), testObject.position.getValue(time))); pyramid.show.value = false; visualizer.update(time); @@ -157,10 +155,10 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); var time = new JulianDate(); expect(scene.getPrimitives().getLength()).toEqual(0); @@ -178,10 +176,10 @@ defineSuite([ visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); var time = new JulianDate(); visualizer.update(time); @@ -191,17 +189,17 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); - testObject.orientation = new MockProperty(new Quaternion(0, 0, 0, 1)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.orientation = new ConstantProperty(new Quaternion(0, 0, 0, 1)); var pyramid = testObject.pyramid = new DynamicPyramid(); - pyramid.directions = new MockProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); + pyramid.directions = new ConstantProperty([new Spherical(0, 0, 0), new Spherical(1, 0, 0), new Spherical(2, 0, 0), new Spherical(3, 0, 0)]); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(5678, 9101112, 1234)); - testObject2.orientation = new MockProperty(new Quaternion(1, 0, 0, 0)); + testObject2.position = new ConstantProperty(new Cartesian3(5678, 9101112, 1234)); + testObject2.orientation = new ConstantProperty(new Quaternion(1, 0, 0, 0)); var pyramid2 = testObject2.pyramid = new DynamicPyramid(); - pyramid2.directions = new MockProperty([new Spherical(3, 0, 0), new Spherical(2, 0, 0), new Spherical(1, 0, 0), new Spherical(0.5, 0, 0)]); + pyramid2.directions = new ConstantProperty([new Spherical(3, 0, 0), new Spherical(2, 0, 0), new Spherical(1, 0, 0), new Spherical(0.5, 0, 0)]); visualizer = new DynamicPyramidVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicVectorSpec.js b/Specs/DynamicScene/DynamicVectorSpec.js index f22b7165750a..947654b96ee7 100644 --- a/Specs/DynamicScene/DynamicVectorSpec.js +++ b/Specs/DynamicScene/DynamicVectorSpec.js @@ -7,7 +7,7 @@ defineSuite([ 'Core/Color', 'Core/Iso8601', 'Core/TimeInterval', - 'Specs/MockProperty' + 'DynamicScene/ConstantProperty' ], function( DynamicVector, DynamicObject, @@ -16,95 +16,24 @@ defineSuite([ Color, Iso8601, TimeInterval, - MockProperty) { + ConstantProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('processCzmlPacket adds data for infinite vector.', function() { - var direction = new Cartesian3(1, 2, 3).normalize(); - var vectorPacket = { - vector : { - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - length : 10.0, - direction : { - unitCartesian : [direction.x, direction.y, direction.z] - }, - show : true - } - }; - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicVector.processCzmlPacket(dynamicObject, vectorPacket)).toEqual(true); - - expect(dynamicObject.vector).toBeDefined(); - expect(dynamicObject.vector.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.vector.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(vectorPacket.vector.width); - expect(dynamicObject.vector.direction.getValue(Iso8601.MINIMUM_VALUE)).toEqual(direction); - expect(dynamicObject.vector.length.getValue(Iso8601.MINIMUM_VALUE)).toEqual(vectorPacket.vector.length); - expect(dynamicObject.vector.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); - }); - - it('processCzmlPacket adds data for constrained vector.', function() { - var direction = new Cartesian3(1, 2, 3).normalize(); - var vectorPacket = { - vector : { - interval : '2000-01-01/2001-01-01', - color : { - rgbaf : [0.1, 0.1, 0.1, 0.1] - }, - width : 1.0, - length : 10.0, - direction : { - unitCartesian : [direction.x, direction.y, direction.z] - }, - show : true - } - }; - - var validTime = TimeInterval.fromIso8601(vectorPacket.vector.interval).start; - var invalidTime = validTime.addSeconds(-1); - - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicVector.processCzmlPacket(dynamicObject, vectorPacket)).toEqual(true); - - expect(dynamicObject.vector).toBeDefined(); - expect(dynamicObject.vector.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); - expect(dynamicObject.vector.width.getValue(validTime)).toEqual(vectorPacket.vector.width); - expect(dynamicObject.vector.direction.getValue(validTime)).toEqual(direction); - expect(dynamicObject.vector.length.getValue(validTime)).toEqual(vectorPacket.vector.length); - expect(dynamicObject.vector.show.getValue(validTime)).toEqual(true); - - expect(dynamicObject.vector.color.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.vector.width.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.vector.direction.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.vector.length.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.vector.show.getValue(invalidTime)).toBeUndefined(); - }); - - it('processCzmlPacket returns false if no data.', function() { - var packet = {}; - var dynamicObject = new DynamicObject('dynamicObject'); - expect(DynamicVector.processCzmlPacket(dynamicObject, packet)).toEqual(false); - expect(dynamicObject.vector).toBeUndefined(); - }); - it('mergeProperties does not change a fully configured vector', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.vector = new DynamicVector(); - objectToMerge.vector.color = new MockProperty(); - objectToMerge.vector.width = new MockProperty(); - objectToMerge.vector.length = new MockProperty(); - objectToMerge.vector.direction = new MockProperty(); - objectToMerge.vector.show = new MockProperty(); - - var color = new MockProperty(); - var width = new MockProperty(); - var length = new MockProperty(); - var direction = new MockProperty(); - var show = new MockProperty(); + objectToMerge.vector.color = new ConstantProperty(Color.WHITE); + objectToMerge.vector.width = new ConstantProperty(1); + objectToMerge.vector.length = new ConstantProperty(2); + objectToMerge.vector.direction = new ConstantProperty(new Cartesian3(1, 0, 0)); + objectToMerge.vector.show = new ConstantProperty(true); + + var color = new ConstantProperty(Color.RED); + var width = new ConstantProperty(2); + var length = new ConstantProperty(10); + var direction = new ConstantProperty(new Cartesian3(0, 0, 1)); + var show = new ConstantProperty(false); var targetObject = new DynamicObject('targetObject'); targetObject.vector = new DynamicVector(); @@ -126,11 +55,11 @@ defineSuite([ it('mergeProperties creates and configures an undefined vector', function() { var objectToMerge = new DynamicObject('objectToMerge'); objectToMerge.vector = new DynamicVector(); - objectToMerge.vector.color = new MockProperty(); - objectToMerge.vector.width = new MockProperty(); - objectToMerge.vector.length = new MockProperty(); - objectToMerge.vector.direction = new MockProperty(); - objectToMerge.vector.show = new MockProperty(); + objectToMerge.vector.color = new ConstantProperty(Color.WHITE); + objectToMerge.vector.width = new ConstantProperty(1); + objectToMerge.vector.length = new ConstantProperty(10); + objectToMerge.vector.direction = new ConstantProperty(new Cartesian3(0, 0, 1)); + objectToMerge.vector.show = new ConstantProperty(true); var targetObject = new DynamicObject('targetObject'); @@ -146,11 +75,11 @@ defineSuite([ it('mergeProperties does not change when used with an undefined vector', function() { var objectToMerge = new DynamicObject('objectToMerge'); - var color = new MockProperty(); - var width = new MockProperty(); - var length = new MockProperty(); - var direction = new MockProperty(); - var show = new MockProperty(); + var color = new ConstantProperty(Color.WHITE); + var width = new ConstantProperty(1); + var length = new ConstantProperty(10); + var direction = new ConstantProperty(new Cartesian3(0, 0, 1)); + var show = new ConstantProperty(true); var targetObject = new DynamicObject('targetObject'); targetObject.vector = new DynamicVector(); diff --git a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js index a41e9ba74b09..8c34bc886faa 100644 --- a/Specs/DynamicScene/DynamicVectorVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicVectorVisualizerSpec.js @@ -3,7 +3,8 @@ defineSuite([ 'DynamicScene/DynamicVectorVisualizer', 'Specs/createScene', 'Specs/destroyScene', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', + 'DynamicScene/ConstantPositionProperty', 'DynamicScene/DynamicEllipse', 'DynamicScene/DynamicVector', 'DynamicScene/DynamicObjectCollection', @@ -17,7 +18,8 @@ defineSuite([ DynamicVectorVisualizer, createScene, destroyScene, - MockProperty, + ConstantProperty, + ConstantPositionProperty, DynamicEllipse, DynamicVector, DynamicObjectCollection, @@ -85,7 +87,7 @@ defineSuite([ visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); var polylineCollection = scene.getPrimitives().get(0); @@ -98,7 +100,7 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var vector = testObject.vector = new DynamicVector(); - vector.show = new MockProperty(true); + vector.show = new ConstantProperty(true); visualizer.update(new JulianDate()); expect(scene.getPrimitives().getLength()).toEqual(1); @@ -115,14 +117,14 @@ defineSuite([ expect(scene.getPrimitives().getLength()).toEqual(1); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject.position = new ConstantPositionProperty(new Cartesian3(1234, 5678, 9101112)); var vector = testObject.vector = new DynamicVector(); - vector.show = new MockProperty(true); - vector.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - vector.width = new MockProperty(12.5); - vector.length = new MockProperty(13.5); - vector.direction = new MockProperty(new Cartesian3(1, 2, 3)); + vector.show = new ConstantProperty(true); + vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + vector.width = new ConstantProperty(12.5); + vector.length = new ConstantProperty(13.5); + vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer.update(time); @@ -132,26 +134,26 @@ defineSuite([ var primitive = polylineCollection.get(0); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.vector.show.getValue(time)); - expect(primitive.getPositions()).toEqual([testObject.position.value, testObject.position.value.add(vector.direction.value.normalize().multiplyByScalar(vector.length.value))]); + expect(primitive.getPositions()).toEqual([testObject.position.getValue(time), testObject.position.getValue(time).add(vector.direction.getValue(time).normalize().multiplyByScalar(vector.length.getValue(time)))]); expect(primitive.getWidth()).toEqual(testObject.vector.width.getValue(time)); var material = primitive.getMaterial(); expect(material.uniforms.color).toEqual(testObject.vector.color.getValue(time)); - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1101112)); - vector.color = new MockProperty(new Color(0.1, 0.2, 0.3, 0.4)); - vector.width = new MockProperty(2.5); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); + vector.color = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + vector.width = new ConstantProperty(2.5); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.vector.show.getValue(time)); - expect(primitive.getPositions()).toEqual([testObject.position.value, testObject.position.value.add(vector.direction.value.normalize().multiplyByScalar(vector.length.value))]); + expect(primitive.getPositions()).toEqual([testObject.position.getValue(time), testObject.position.getValue(time).add(vector.direction.getValue(time).normalize().multiplyByScalar(vector.length.getValue(time)))]); expect(primitive.getWidth()).toEqual(testObject.vector.width.getValue(time)); material = primitive.getMaterial(); expect(material.uniforms.color).toEqual(testObject.vector.color.getValue(time)); - vector.show = new MockProperty(false); + vector.show = new ConstantProperty(false); visualizer.update(time); expect(primitive.getShow()).toEqual(testObject.vector.show.getValue(time)); }); @@ -163,13 +165,13 @@ defineSuite([ var testObject = dynamicObjectCollection.getOrCreateObject('test'); var time = new JulianDate(); - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1101112)); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); var vector = testObject.vector = new DynamicVector(); - vector.show = new MockProperty(true); - vector.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - vector.width = new MockProperty(12.5); - vector.length = new MockProperty(13.5); - vector.direction = new MockProperty(new Cartesian3(1, 2, 3)); + vector.show = new ConstantProperty(true); + vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + vector.width = new ConstantProperty(12.5); + vector.length = new ConstantProperty(13.5); + vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer.update(time); var polylineCollection = scene.getPrimitives().get(0); @@ -194,12 +196,12 @@ defineSuite([ var time = new JulianDate(); var vector = testObject.vector = new DynamicVector(); - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1101112)); - vector.show = new MockProperty(true); - vector.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - vector.width = new MockProperty(12.5); - vector.length = new MockProperty(13.5); - vector.direction = new MockProperty(new Cartesian3(1, 2, 3)); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); + vector.show = new ConstantProperty(true); + vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + vector.width = new ConstantProperty(12.5); + vector.length = new ConstantProperty(13.5); + vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer.update(time); var polylineCollection = scene.getPrimitives().get(0); @@ -211,23 +213,23 @@ defineSuite([ it('setDynamicObjectCollection removes old objects and add new ones.', function() { var dynamicObjectCollection = new DynamicObjectCollection(); var testObject = dynamicObjectCollection.getOrCreateObject('test'); - testObject.position = new MockProperty(new Cartesian3(5678, 1234, 1101112)); + testObject.position = new ConstantProperty(new Cartesian3(5678, 1234, 1101112)); testObject.vector = new DynamicVector(); - testObject.vector.show = new MockProperty(true); - testObject.vector.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - testObject.vector.width = new MockProperty(12.5); - testObject.vector.length = new MockProperty(13.5); - testObject.vector.direction = new MockProperty(new Cartesian3(1, 2, 3)); + testObject.vector.show = new ConstantProperty(true); + testObject.vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + testObject.vector.width = new ConstantProperty(12.5); + testObject.vector.length = new ConstantProperty(13.5); + testObject.vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); var dynamicObjectCollection2 = new DynamicObjectCollection(); var testObject2 = dynamicObjectCollection2.getOrCreateObject('test2'); - testObject2.position = new MockProperty(new Cartesian3(1234, 5678, 9101112)); + testObject2.position = new ConstantProperty(new Cartesian3(1234, 5678, 9101112)); testObject2.vector = new DynamicVector(); - testObject2.vector.show = new MockProperty(true); - testObject2.vector.color = new MockProperty(new Color(0.8, 0.7, 0.6, 0.5)); - testObject2.vector.width = new MockProperty(12.5); - testObject2.vector.length = new MockProperty(13.5); - testObject2.vector.direction = new MockProperty(new Cartesian3(1, 2, 3)); + testObject2.vector.show = new ConstantProperty(true); + testObject2.vector.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + testObject2.vector.width = new ConstantProperty(12.5); + testObject2.vector.length = new ConstantProperty(13.5); + testObject2.vector.direction = new ConstantProperty(new Cartesian3(1, 2, 3)); visualizer = new DynamicVectorVisualizer(scene, dynamicObjectCollection); diff --git a/Specs/DynamicScene/DynamicVertexPositionsPropertySpec.js b/Specs/DynamicScene/DynamicVertexPositionsPropertySpec.js index 28fcb0aac30c..a3fe97d2efa8 100644 --- a/Specs/DynamicScene/DynamicVertexPositionsPropertySpec.js +++ b/Specs/DynamicScene/DynamicVertexPositionsPropertySpec.js @@ -2,14 +2,16 @@ defineSuite([ 'DynamicScene/DynamicVertexPositionsProperty', 'DynamicScene/DynamicObjectCollection', - 'DynamicScene/processCzml', + 'DynamicScene/CzmlDataSource', + 'Core/Cartographic', 'Core/JulianDate', 'Core/Math', 'Core/Ellipsoid' ], function( DynamicVertexPositionsProperty, DynamicObjectCollection, - processCzml, + CzmlDataSource, + Cartographic, JulianDate, CesiumMath, Ellipsoid) { @@ -50,22 +52,22 @@ defineSuite([ references : ['test1.position', 'test2.position', 'test3.position'] }; - it('getValueCartesian returns undefined if no data exists', function() { + it('getValue returns undefined if no data exists', function() { var property = new DynamicVertexPositionsProperty(); - expect(property.getValueCartesian(new JulianDate())).toBeUndefined(); + expect(property.getValue(new JulianDate())).toBeUndefined(); }); - it('getValueCartesian throw if no time supplied', function() { + it('getValue throw if no time supplied', function() { var property = new DynamicVertexPositionsProperty(); expect(function() { - property.getValueCartesian(); + property.getValue(); }).toThrow(); }); - it('getValueCartesian works for cartesian data', function() { + it('getValue works for cartesian data', function() { var property = new DynamicVertexPositionsProperty(); property.processCzmlIntervals(cartesianInterval); - var result = property.getValueCartesian(new JulianDate()); + var result = property.getValue(new JulianDate()); expect(result.length).toEqual(3); expect(result[0].x).toEqual(cartesianInterval.cartesian[0]); expect(result[0].y).toEqual(cartesianInterval.cartesian[1]); @@ -80,12 +82,12 @@ defineSuite([ expect(result[2].z).toEqual(cartesianInterval.cartesian[8]); }); - it('getValueCartesian works for cartographic degrees data', function() { + it('getValue works for cartographic degrees data', function() { var property = new DynamicVertexPositionsProperty(); property.processCzmlIntervals(cartographicDegreesInterval); - var result = property.getValueCartesian(new JulianDate()); + var result = property.getValue(new JulianDate()); - var expected = Ellipsoid.WGS84.cartographicArrayToCartesianArray(property.getValueCartographic(new JulianDate())); + var expected = Ellipsoid.WGS84.cartographicArrayToCartesianArray([new Cartographic(CesiumMath.toRadians(10.1), CesiumMath.toRadians(10.2), 10.3), new Cartographic(CesiumMath.toRadians(10.4), CesiumMath.toRadians(10.5), 10.6), new Cartographic(CesiumMath.toRadians(10.7), CesiumMath.toRadians(10.8), 10.9)]); expect(result.length).toEqual(3); expect(result[0].x).toEqual(expected[0].x); @@ -101,12 +103,12 @@ defineSuite([ expect(result[2].z).toEqual(expected[2].z); }); - it('getValueCartesian works for cartographic radians data', function() { + it('getValue works for cartographic radians data', function() { var property = new DynamicVertexPositionsProperty(); property.processCzmlIntervals(cartographicRadiansInterval); - var result = property.getValueCartesian(new JulianDate()); + var result = property.getValue(new JulianDate()); - var expected = Ellipsoid.WGS84.cartographicArrayToCartesianArray(property.getValueCartographic(new JulianDate())); + var expected = Ellipsoid.WGS84.cartographicArrayToCartesianArray([new Cartographic(1.1, 1.2, 1.3), new Cartographic(1.4, 1.5, 1.6), new Cartographic(1.7, 1.8, 1.9)]); expect(result.length).toEqual(3); expect(result[0].x).toEqual(expected[0].x); @@ -122,104 +124,9 @@ defineSuite([ expect(result[2].z).toEqual(expected[2].z); }); - it('getValueCartographic works for cartesian data', function() { - var property = new DynamicVertexPositionsProperty(); - property.processCzmlIntervals(cartesianInterval); - var result = property.getValueCartographic(new JulianDate()); - - var expected = Ellipsoid.WGS84.cartesianArrayToCartographicArray(property.getValueCartesian(new JulianDate())); - - expect(result.length).toEqual(3); - expect(result[0].longitude).toEqual(expected[0].longitude); - expect(result[0].latitude).toEqual(expected[0].latitude); - expect(result[0].height).toEqual(expected[0].height); - - expect(result[1].longitude).toEqual(expected[1].longitude); - expect(result[1].latitude).toEqual(expected[1].latitude); - expect(result[1].height).toEqual(expected[1].height); - - expect(result[2].longitude).toEqual(expected[2].longitude); - expect(result[2].latitude).toEqual(expected[2].latitude); - expect(result[2].height).toEqual(expected[2].height); - }); - - it('getValueCartographic works for cartographic degrees data', function() { - var property = new DynamicVertexPositionsProperty(); - property.processCzmlIntervals(cartographicDegreesInterval); - var result = property.getValueCartographic(new JulianDate()); - - expect(result.length).toEqual(3); - expect(result[0].longitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[0])); - expect(result[0].latitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[1])); - expect(result[0].height).toEqual(cartographicDegreesInterval.cartographicDegrees[2]); - - expect(result[1].longitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[3])); - expect(result[1].latitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[4])); - expect(result[1].height).toEqual(cartographicDegreesInterval.cartographicDegrees[5]); - - expect(result[2].longitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[6])); - expect(result[2].latitude).toEqual(CesiumMath.toRadians(cartographicDegreesInterval.cartographicDegrees[7])); - expect(result[2].height).toEqual(cartographicDegreesInterval.cartographicDegrees[8]); - }); - - it('getValueCartographic works for cartographic radians data', function() { - var property = new DynamicVertexPositionsProperty(); - property.processCzmlIntervals(cartographicRadiansInterval); - var result = property.getValueCartographic(new JulianDate()); - - expect(result.length).toEqual(3); - expect(result[0].longitude).toEqual(cartographicRadiansInterval.cartographicRadians[0]); - expect(result[0].latitude).toEqual(cartographicRadiansInterval.cartographicRadians[1]); - expect(result[0].height).toEqual(cartographicRadiansInterval.cartographicRadians[2]); - - expect(result[1].longitude).toEqual(cartographicRadiansInterval.cartographicRadians[3]); - expect(result[1].latitude).toEqual(cartographicRadiansInterval.cartographicRadians[4]); - expect(result[1].height).toEqual(cartographicRadiansInterval.cartographicRadians[5]); - - expect(result[2].longitude).toEqual(cartographicRadiansInterval.cartographicRadians[6]); - expect(result[2].latitude).toEqual(cartographicRadiansInterval.cartographicRadians[7]); - expect(result[2].height).toEqual(cartographicRadiansInterval.cartographicRadians[8]); - }); - - it('getValueCartographic returns undefined if no data exists', function() { - var property = new DynamicVertexPositionsProperty(); - expect(property.getValueCartographic(new JulianDate())).toBeUndefined(); - }); - - it('getValueCartographic throws if no time supplied', function() { - var property = new DynamicVertexPositionsProperty(); - expect(function() { - property.getValueCartographic(); - }).toThrow(); - }); - - it('getValueCartographic works for reference data', function() { - var objects = new DynamicObjectCollection(); - processCzml(testObjects, objects); - var test1 = objects.getObject('test1'); - var test2 = objects.getObject('test2'); - var test3 = objects.getObject('test3'); - - var property = new DynamicVertexPositionsProperty(); - property.processCzmlIntervals(referenceInterval, undefined, objects); - - var time = JulianDate.fromIso8601('2011-04-18T15:59:00Z'); - var result = property.getValueCartographic(time); - expect(result.length).toEqual(2); - expect(result[0]).toEqual(test1.position.getValueCartographic(time)); - expect(result[1]).toEqual(test2.position.getValueCartographic(time)); - - time = JulianDate.fromIso8601('2012-04-18T15:59:00Z'); - result = property.getValueCartographic(time); - expect(result.length).toEqual(3); - expect(result[0]).toEqual(test1.position.getValueCartographic(time)); - expect(result[1]).toEqual(test2.position.getValueCartographic(time)); - expect(result[2]).toEqual(test3.position.getValueCartographic(time)); - }); - - it('getValueCartesian works for reference data', function() { + it('getValue works for reference data', function() { var objects = new DynamicObjectCollection(); - processCzml(testObjects, objects); + CzmlDataSource._processCzml(testObjects, objects); var test1 = objects.getObject('test1'); var test2 = objects.getObject('test2'); var test3 = objects.getObject('test3'); @@ -228,16 +135,16 @@ defineSuite([ property.processCzmlIntervals(referenceInterval, undefined, objects); var time = JulianDate.fromIso8601('2011-04-18T15:59:00Z'); - var result = property.getValueCartesian(time); + var result = property.getValue(time); expect(result.length).toEqual(2); - expect(result[0]).toEqual(test1.position.getValueCartesian(time)); - expect(result[1]).toEqual(test2.position.getValueCartesian(time)); + expect(result[0]).toEqual(test1.position.getValue(time)); + expect(result[1]).toEqual(test2.position.getValue(time)); time = JulianDate.fromIso8601('2012-04-18T15:59:00Z'); - result = property.getValueCartesian(time); + result = property.getValue(time); expect(result.length).toEqual(3); - expect(result[0]).toEqual(test1.position.getValueCartesian(time)); - expect(result[1]).toEqual(test2.position.getValueCartesian(time)); - expect(result[2]).toEqual(test3.position.getValueCartesian(time)); + expect(result[0]).toEqual(test1.position.getValue(time)); + expect(result[1]).toEqual(test2.position.getValue(time)); + expect(result[2]).toEqual(test3.position.getValue(time)); }); }); diff --git a/Specs/DynamicScene/GeoJsonDataSourceSpec.js b/Specs/DynamicScene/GeoJsonDataSourceSpec.js index 3026be27d49e..d00c03103229 100644 --- a/Specs/DynamicScene/GeoJsonDataSourceSpec.js +++ b/Specs/DynamicScene/GeoJsonDataSourceSpec.js @@ -228,7 +228,7 @@ defineSuite([ runs(function() { var pointObject = dynamicObjectCollection.getObjects()[0]; expect(pointObject.geoJson).toBe(feature); - expect(pointObject.position.getValueCartesian()).toEqual(coordinatesToCartesian(feature.geometry.coordinates)); + expect(pointObject.position.getValue()).toEqual(coordinatesToCartesian(feature.geometry.coordinates)); expect(pointObject.point).toBeDefined(); }); }); @@ -260,7 +260,7 @@ defineSuite([ runs(function() { var pointObject = dynamicObjectCollection.getObjects()[0]; expect(pointObject.geoJson).toBe(point); - expect(pointObject.position.getValueCartesian()).toEqual(coordinatesToCartesian(point.coordinates)); + expect(pointObject.position.getValue()).toEqual(coordinatesToCartesian(point.coordinates)); expect(pointObject.point).toBeDefined(); }); }); @@ -279,7 +279,7 @@ defineSuite([ for ( var i = 0; i < multiPoint.coordinates.length; i++) { var object = objects[i]; expect(object.geoJson).toBe(multiPoint); - expect(object.position.getValueCartesian()).toEqual(expectedPositions[i]); + expect(object.position.getValue()).toEqual(expectedPositions[i]); expect(object.point).toBeDefined(); } }); @@ -296,7 +296,7 @@ defineSuite([ runs(function() { var object = dynamicObjectCollection.getObjects()[0]; expect(object.geoJson).toBe(lineString); - expect(object.vertexPositions.getValueCartesian()).toEqual(coordinatesArrayToCartesian(lineString.coordinates)); + expect(object.vertexPositions.getValue()).toEqual(coordinatesArrayToCartesian(lineString.coordinates)); expect(object.polyline).toBeDefined(); }); }); @@ -315,7 +315,7 @@ defineSuite([ for ( var i = 0; i < multiLineString.coordinates.length; i++) { var object = objects[i]; expect(object.geoJson).toBe(multiLineString); - expect(object.vertexPositions.getValueCartesian()).toEqual(lines[i]); + expect(object.vertexPositions.getValue()).toEqual(lines[i]); expect(object.polyline).toBeDefined(); } }); @@ -332,7 +332,7 @@ defineSuite([ runs(function() { var object = dynamicObjectCollection.getObjects()[0]; expect(object.geoJson).toBe(polygon); - expect(object.vertexPositions.getValueCartesian()).toEqual(polygonCoordinatesToCartesian(polygon.coordinates)); + expect(object.vertexPositions.getValue()).toEqual(polygonCoordinatesToCartesian(polygon.coordinates)); expect(object.polyline).toBeDefined(); expect(object.polygon).toBeDefined(); }); @@ -349,7 +349,7 @@ defineSuite([ runs(function() { var object = dynamicObjectCollection.getObjects()[0]; expect(object.geoJson).toBe(polygonWithHoles); - expect(object.vertexPositions.getValueCartesian()).toEqual(polygonCoordinatesToCartesian(polygonWithHoles.coordinates)); + expect(object.vertexPositions.getValue()).toEqual(polygonCoordinatesToCartesian(polygonWithHoles.coordinates)); expect(object.polyline).toBeDefined(); expect(object.polygon).toBeDefined(); }); @@ -369,7 +369,7 @@ defineSuite([ for ( var i = 0; i < multiPolygon.coordinates.length; i++) { var object = objects[i]; expect(object.geoJson).toBe(multiPolygon); - expect(object.vertexPositions.getValueCartesian()).toEqual(positions[i]); + expect(object.vertexPositions.getValue()).toEqual(positions[i]); expect(object.polyline).toBeDefined(); expect(object.polygon).toBeDefined(); } @@ -410,12 +410,12 @@ defineSuite([ runs(function() { var object = dynamicObjectCollection.getObjects()[0]; expect(object.geoJson).toBe(geometryCollection); - expect(object.position.getValueCartesian()).toEqual(coordinatesToCartesian(geometryCollection.geometries[0].coordinates)); + expect(object.position.getValue()).toEqual(coordinatesToCartesian(geometryCollection.geometries[0].coordinates)); expect(object.point).toBeDefined(); object = dynamicObjectCollection.getObjects()[1]; expect(object.geoJson).toBe(geometryCollection); - expect(object.vertexPositions.getValueCartesian()).toEqual(coordinatesArrayToCartesian(geometryCollection.geometries[1].coordinates)); + expect(object.vertexPositions.getValue()).toEqual(coordinatesArrayToCartesian(geometryCollection.geometries[1].coordinates)); expect(object.polyline).toBeDefined(); }); }); @@ -430,7 +430,7 @@ defineSuite([ }); runs(function() { var pointObject = dynamicObjectCollection.getObjects()[0]; - expect(pointObject.position.getValueCartesian()).toEqual(coordinatesToCartesian(point.coordinates)); + expect(pointObject.position.getValue()).toEqual(coordinatesToCartesian(point.coordinates)); }); }); @@ -455,7 +455,7 @@ defineSuite([ }); runs(function() { var pointObject = dynamicObjectCollection.getObjects()[0]; - expect(pointObject.position.getValueCartesian()).toEqual(projectedPosition); + expect(pointObject.position.getValue()).toEqual(projectedPosition); }); }); @@ -469,7 +469,7 @@ defineSuite([ }); runs(function() { var pointObject = dynamicObjectCollection.getObjects()[0]; - expect(pointObject.position.getValueCartesian()).toEqual(coordinatesToCartesian(point.coordinates)); + expect(pointObject.position.getValue()).toEqual(coordinatesToCartesian(point.coordinates)); }); }); diff --git a/Specs/DynamicScene/GridMaterialPropertySpec.js b/Specs/DynamicScene/GridMaterialPropertySpec.js new file mode 100644 index 000000000000..7b366458f2d3 --- /dev/null +++ b/Specs/DynamicScene/GridMaterialPropertySpec.js @@ -0,0 +1,107 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/GridMaterialProperty', + 'DynamicScene/ConstantProperty', + 'DynamicScene/TimeIntervalCollectionProperty', + 'Core/Cartesian2', + 'Core/Color', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Specs/UndefinedProperty' + ], function( + GridMaterialProperty, + ConstantProperty, + TimeIntervalCollectionProperty, + Cartesian2, + Color, + JulianDate, + TimeInterval, + UndefinedProperty) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('works with basic types', function() { + var property = new GridMaterialProperty(); + expect(property.color).toBeDefined(); + expect(property.cellAlpha).toBeDefined(); + expect(property.lineCount).toBeDefined(); + expect(property.lineThickness).toBeDefined(); + + expect(property.getType()).toEqual('Grid'); + + var result = property.getValue(); + expect(result.color).toEqual(Color.WHITE); + expect(result.cellAlpha).toEqual(0.1); + expect(result.lineCount).toEqual(new Cartesian2(8, 8)); + expect(result.lineThickness).toEqual(new Cartesian2(1.0, 1.0)); + }); + + it('works with constant values', function() { + var property = new GridMaterialProperty(); + property.color = new ConstantProperty(Color.RED); + property.cellAlpha = new ConstantProperty(1.0); + property.lineCount = new ConstantProperty(new Cartesian2(3.4, 5.0)); + property.lineThickness = new ConstantProperty(new Cartesian2(2, 3)); + + var result = property.getValue(new JulianDate()); + expect(result.color).toEqual(Color.RED); + expect(result.cellAlpha).toEqual(1); + expect(result.lineCount).toEqual(new Cartesian2(3.4, 5.0)); + expect(result.lineThickness).toEqual(new Cartesian2(2, 3)); + }); + + it('works with undefined values', function() { + var property = new GridMaterialProperty(); + property.color = new UndefinedProperty(); + property.cellAlpha = new UndefinedProperty(); + property.lineCount = new UndefinedProperty(); + property.lineThickness = new UndefinedProperty(); + + var result = property.getValue(); + expect(result.hasOwnProperty('color')).toEqual(true); + expect(result.hasOwnProperty('cellAlpha')).toEqual(true); + expect(result.hasOwnProperty('lineCount')).toEqual(true); + expect(result.hasOwnProperty('lineThickness')).toEqual(true); + expect(result.color).toBeUndefined(); + expect(result.cellAlpha).toBeUndefined(); + expect(result.lineCount).toBeUndefined(); + expect(result.lineThickness).toBeUndefined(); + }); + + it('works with dynamic values', function() { + var property = new GridMaterialProperty(); + property.color = new TimeIntervalCollectionProperty(); + property.cellAlpha = new TimeIntervalCollectionProperty(); + property.lineCount = new TimeIntervalCollectionProperty(); + property.lineThickness = new TimeIntervalCollectionProperty(); + + var start = new JulianDate(1, 0); + var stop = new JulianDate(2, 0); + property.color.intervals.addInterval(new TimeInterval(start, stop, true, true, Color.BLUE)); + property.cellAlpha.intervals.addInterval(new TimeInterval(start, stop, true, true, 1.0)); + property.lineCount.intervals.addInterval(new TimeInterval(start, stop, true, true, new Cartesian2(3.4, 5.0))); + property.lineThickness.intervals.addInterval(new TimeInterval(start, stop, true, true, new Cartesian2(2, 3))); + + var result = property.getValue(start); + expect(result.color).toEqual(Color.BLUE); + expect(result.cellAlpha).toEqual(1); + expect(result.lineCount).toEqual(new Cartesian2(3.4, 5.0)); + expect(result.lineThickness).toEqual(new Cartesian2(2, 3)); + }); + + it('works with a result parameter', function() { + var property = new GridMaterialProperty(); + property.color = new ConstantProperty(Color.RED); + property.cellAlpha = new ConstantProperty(1.0); + property.lineCount = new ConstantProperty(new Cartesian2(3.4, 5.0)); + property.lineThickness = new ConstantProperty(new Cartesian2(2, 3)); + + var result = {}; + var returnedResult = property.getValue(new JulianDate(), result); + expect(result).toBe(returnedResult); + expect(result.color).toEqual(Color.RED); + expect(result.cellAlpha).toEqual(1.0); + expect(result.lineCount).toEqual(new Cartesian2(3.4, 5.0)); + expect(result.lineThickness).toEqual(new Cartesian2(2, 3)); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/ImageMaterialPropertySpec.js b/Specs/DynamicScene/ImageMaterialPropertySpec.js new file mode 100644 index 000000000000..4f94c596969a --- /dev/null +++ b/Specs/DynamicScene/ImageMaterialPropertySpec.js @@ -0,0 +1,81 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/ImageMaterialProperty', + 'DynamicScene/ConstantProperty', + 'DynamicScene/TimeIntervalCollectionProperty', + 'Core/Cartesian2', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Specs/UndefinedProperty' + ], function( + ImageMaterialProperty, + ConstantProperty, + TimeIntervalCollectionProperty, + Cartesian2, + JulianDate, + TimeInterval, + UndefinedProperty) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('works with basic types', function() { + var property = new ImageMaterialProperty(); + expect(property.image).toBeUndefined(); + expect(property.repeat).toBeDefined(); + + expect(property.getType()).toEqual('Image'); + + var result = property.getValue(); + expect(result.image).toBeUndefined(); + expect(result.repeat).toEqual(new Cartesian2(1.0, 1.0)); + }); + + it('works with constant values', function() { + var property = new ImageMaterialProperty(); + property.image = new ConstantProperty('http://test.invalid/image.png'); + property.repeat = new ConstantProperty(new Cartesian2(2, 3)); + + var result = property.getValue(new JulianDate()); + expect(result.image).toEqual('http://test.invalid/image.png'); + expect(result.repeat).toEqual(new Cartesian2(2, 3)); + }); + + it('works with undefined values', function() { + var property = new ImageMaterialProperty(); + property.image = new UndefinedProperty(); + property.repeat = new UndefinedProperty(); + + var result = property.getValue(); + expect(result.hasOwnProperty('image')).toEqual(true); + expect(result.hasOwnProperty('repeat')).toEqual(true); + expect(result.image).toBeUndefined(); + expect(result.repeat).toBeUndefined(); + }); + + it('works with dynamic values', function() { + var property = new ImageMaterialProperty(); + property.image = new TimeIntervalCollectionProperty(); + property.repeat = new TimeIntervalCollectionProperty(); + + var start = new JulianDate(1, 0); + var stop = new JulianDate(2, 0); + property.image.intervals.addInterval(new TimeInterval(start, stop, true, true, 'http://test.invalid/image.png')); + property.repeat.intervals.addInterval(new TimeInterval(start, stop, true, true, new Cartesian2(2, 3))); + + var result = property.getValue(start); + expect(result.image).toEqual('http://test.invalid/image.png'); + expect(result.repeat).toEqual(new Cartesian2(2, 3)); + }); + + it('works with a result parameter', function() { + var property = new ImageMaterialProperty(); + property.image = new ConstantProperty('http://test.invalid/image.png'); + property.repeat = new ConstantProperty(new Cartesian2(2, 3)); + + var result = {}; + var returnedResult = property.getValue(new JulianDate(), result); + expect(result).toBe(returnedResult); + expect(result.image).toEqual('http://test.invalid/image.png'); + expect(result.repeat).toEqual(new Cartesian2(2, 3)); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/ReferencePropertySpec.js b/Specs/DynamicScene/ReferencePropertySpec.js index dcd5540c3e12..a65ee09a2e53 100644 --- a/Specs/DynamicScene/ReferencePropertySpec.js +++ b/Specs/DynamicScene/ReferencePropertySpec.js @@ -70,22 +70,7 @@ defineSuite([ it('getValue returned undefined for unresolved property', function() { var property = ReferenceProperty.fromString(new DynamicObjectCollection(), 'object.property'); - expect(property.getValue()).toBeUndefined(); - }); - - it('getValueCartographic returned undefined for unresolved property', function() { - var property = ReferenceProperty.fromString(new DynamicObjectCollection(), 'object.property'); - expect(property.getValueCartographic()).toBeUndefined(); - }); - - it('getValueCartesian returned undefined for unresolved property', function() { - var property = ReferenceProperty.fromString(new DynamicObjectCollection(), 'object.property'); - expect(property.getValueCartesian()).toBeUndefined(); - }); - - it('getValueSpherical returned undefined for unresolved property', function() { - var property = ReferenceProperty.fromString(new DynamicObjectCollection(), 'object.property'); - expect(property.getValueSpherical()).toBeUndefined(); + expect(property.getValue(new JulianDate())).toBeUndefined(); }); it('Resolves getValue property on direct collection', function() { @@ -123,36 +108,14 @@ defineSuite([ expect(property.getValue(invalidTime, result)).toBeUndefined(); }); - it('Resolves getValueCartographic property on direct collection', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - createTestObject(dynamicObjectCollection, 'getValueCartographic'); - var property = ReferenceProperty.fromString(dynamicObjectCollection, testObjectLink); - var result = {}; - expect(property.getValueCartographic(validTime, result)).toEqual(result); - expect(result.expectedValue).toEqual(true); - expect(result.expectedTime).toEqual(validTime); - expect(property.getValueCartographic(invalidTime, result)).toBeUndefined(); - }); - - it('Resolves getValueCartesian property on direct collection', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - createTestObject(dynamicObjectCollection, 'getValueCartesian'); - var property = ReferenceProperty.fromString(dynamicObjectCollection, testObjectLink); - var result = {}; - expect(property.getValueCartesian(validTime, result)).toEqual(result); - expect(result.expectedValue).toEqual(true); - expect(result.expectedTime).toEqual(validTime); - expect(property.getValueCartesian(invalidTime, result)).toBeUndefined(); - }); - - it('Resolves getValueSpherical property on direct collection', function() { + it('Resolves getValue property on direct collection', function() { var dynamicObjectCollection = new DynamicObjectCollection(); - createTestObject(dynamicObjectCollection, 'getValueSpherical'); + createTestObject(dynamicObjectCollection, 'getValue'); var property = ReferenceProperty.fromString(dynamicObjectCollection, testObjectLink); var result = {}; - expect(property.getValueSpherical(validTime, result)).toEqual(result); + expect(property.getValue(validTime, result)).toEqual(result); expect(result.expectedValue).toEqual(true); expect(result.expectedTime).toEqual(validTime); - expect(property.getValueSpherical(invalidTime, result)).toBeUndefined(); + expect(property.getValue(invalidTime, result)).toBeUndefined(); }); }); \ No newline at end of file diff --git a/Specs/DynamicScene/SampledPositionPropertySpec.js b/Specs/DynamicScene/SampledPositionPropertySpec.js new file mode 100644 index 000000000000..f7b0a94b1c5f --- /dev/null +++ b/Specs/DynamicScene/SampledPositionPropertySpec.js @@ -0,0 +1,198 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/SampledPositionProperty', + 'DynamicScene/PositionProperty', + 'Core/Cartesian3', + 'Core/defined', + 'Core/JulianDate', + 'Core/LinearApproximation', + 'Core/ReferenceFrame' + ], function( + SampledPositionProperty, + PositionProperty, + Cartesian3, + defined, + JulianDate, + LinearApproximation, + ReferenceFrame) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('constructor sets expected defaults', function() { + var property = new SampledPositionProperty(); + expect(property.referenceFrame).toEqual(ReferenceFrame.FIXED); + expect(property.interpolationDegree).toEqual(1); + expect(property.interpolationAlgorithm).toEqual(LinearApproximation); + }); + + it('constructor sets expected values', function() { + var property = new SampledPositionProperty(ReferenceFrame.INERTIAL); + expect(property.referenceFrame).toEqual(ReferenceFrame.INERTIAL); + expect(property.interpolationDegree).toEqual(1); + expect(property.interpolationAlgorithm).toEqual(LinearApproximation); + }); + + it('getValue works without a result parameter', function() { + var time = new JulianDate(); + var value = new Cartesian3(1, 2, 3); + var property = new SampledPositionProperty(); + property.addSample(time, value); + + var result = property.getValue(time); + expect(result).not.toBe(value); + expect(result).toEqual(value); + }); + + it('getValue works with a result parameter', function() { + var time = new JulianDate(); + var value = new Cartesian3(1, 2, 3); + var property = new SampledPositionProperty(); + property.addSample(time, value); + + var expected = new Cartesian3(); + var result = property.getValue(time, expected); + expect(result).toBe(expected); + expect(expected).toEqual(value); + }); + + it('getValue returns in fixed frame', function() { + var time = new JulianDate(); + var valueInertial = new Cartesian3(1, 2, 3); + var valueFixed = PositionProperty.convertToReferenceFrame(time, valueInertial, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED); + var property = new SampledPositionProperty(ReferenceFrame.INERTIAL); + property.addSample(time, valueInertial); + + var result = property.getValue(time); + expect(result).toEqual(valueFixed); + }); + + it('getValueInReferenceFrame works without a result parameter', function() { + var time = new JulianDate(); + var value = new Cartesian3(1, 2, 3); + var property = new SampledPositionProperty(); + property.addSample(time, value); + + var result = property.getValueInReferenceFrame(time, ReferenceFrame.INERTIAL); + expect(result).not.toBe(value); + expect(result).toEqual(PositionProperty.convertToReferenceFrame(time, value, ReferenceFrame.FIXED, ReferenceFrame.INERTIAL)); + }); + + it('getValueInReferenceFrame works with a result parameter', function() { + var time = new JulianDate(); + var value = new Cartesian3(1, 2, 3); + var property = new SampledPositionProperty(ReferenceFrame.INERTIAL); + property.addSample(time, value); + + var expected = new Cartesian3(); + var result = property.getValueInReferenceFrame(time, ReferenceFrame.FIXED, expected); + expect(result).toBe(expected); + expect(expected).toEqual(PositionProperty.convertToReferenceFrame(time, value, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED)); + }); + + it('addSamplesPackedArray works', function() { + var data = [0, 7, 8, 9, 1, 8, 9, 10, 2, 9, 10, 11]; + var epoch = new JulianDate(0, 0); + + var property = new SampledPositionProperty(); + property.addSamplesPackedArray(data, epoch); + expect(property.getValue(epoch)).toEqual(new Cartesian3(7, 8, 9)); + expect(property.getValue(new JulianDate(0, 0.5))).toEqual(new Cartesian3(7.5, 8.5, 9.5)); + }); + + it('addSample works', function() { + var values = [new Cartesian3(7, 8, 9), new Cartesian3(8, 9, 10), new Cartesian3(9, 10, 11)]; + var times = [new JulianDate(0, 0), new JulianDate(1, 0), new JulianDate(2, 0)]; + + var property = new SampledPositionProperty(); + property.addSample(times[0], values[0]); + property.addSample(times[1], values[1]); + property.addSample(times[2], values[2]); + + expect(property.getValue(times[0])).toEqual(values[0]); + expect(property.getValue(times[1])).toEqual(values[1]); + expect(property.getValue(times[2])).toEqual(values[2]); + expect(property.getValue(new JulianDate(0.5, 0))).toEqual(new Cartesian3(7.5, 8.5, 9.5)); + }); + + it('addSamples works', function() { + var values = [new Cartesian3(7, 8, 9), new Cartesian3(8, 9, 10), new Cartesian3(9, 10, 11)]; + var times = [new JulianDate(0, 0), new JulianDate(1, 0), new JulianDate(2, 0)]; + + var property = new SampledPositionProperty(); + property.addSamples(times, values); + expect(property.getValue(times[0])).toEqual(values[0]); + expect(property.getValue(times[1])).toEqual(values[1]); + expect(property.getValue(times[2])).toEqual(values[2]); + expect(property.getValue(new JulianDate(0.5, 0))).toEqual(new Cartesian3(7.5, 8.5, 9.5)); + }); + + it('can set interpolationAlgorithm and degree', function() { + var data = [0, 7, 8, 9, 1, 8, 9, 10, 2, 9, 10, 11]; + var epoch = new JulianDate(0, 0); + + var timesCalled = 0; + var MockInterpolation = { + type : 'Mock', + getRequiredDataPoints : function(degree) { + return 3; + }, + + interpolateOrderZero : function(x, xTable, yTable, yStride, result) { + expect(x).toEqual(1); + + expect(xTable.length).toEqual(3); + expect(xTable[0]).toBe(-2); + expect(xTable[1]).toBe(-1); + expect(xTable[2]).toBe(0); + + expect(yTable.length).toEqual(9); + expect(yTable[0]).toBe(7); + expect(yTable[1]).toBe(8); + expect(yTable[2]).toBe(9); + expect(yTable[3]).toBe(8); + expect(yTable[4]).toBe(9); + expect(yTable[5]).toBe(10); + expect(yTable[6]).toBe(9); + expect(yTable[7]).toBe(10); + expect(yTable[8]).toBe(11); + + expect(yStride).toEqual(3); + + expect(result.length).toEqual(3); + + result[0] = 2; + result[1] = 3; + result[2] = 4; + timesCalled++; + return result; + } + }; + + var property = new SampledPositionProperty(); + property.addSamplesPackedArray(data, epoch); + property.interpolationDegree = 2; + property.interpolationAlgorithm = MockInterpolation; + expect(property.getValue(epoch)).toEqual(new Cartesian3(7, 8, 9)); + expect(property.getValue(new JulianDate(0, 3))).toEqual(new Cartesian3(2, 3, 4)); + + expect(timesCalled).toEqual(1); + }); + + it('Returns undefined if trying to interpolate with less than enough samples.', function() { + var value = new Cartesian3(1, 2, 3); + var time = new JulianDate(0, 0); + + var property = new SampledPositionProperty(); + property.addSample(time, value); + + expect(property.getValue(time)).toEqual(value); + expect(property.getValue(time.addSeconds(4))).toBeUndefined(); + }); + + it('throws with no time parameter', function() { + var property = new SampledPositionProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/SampledPropertySpec.js b/Specs/DynamicScene/SampledPropertySpec.js new file mode 100644 index 000000000000..49270c074d6e --- /dev/null +++ b/Specs/DynamicScene/SampledPropertySpec.js @@ -0,0 +1,291 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/SampledProperty', + 'Core/defined', + 'Core/JulianDate', + 'Core/LinearApproximation' + ], function( + SampledProperty, + defined, + JulianDate, + LinearApproximation) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('constructor sets expected defaults', function() { + var property = new SampledProperty(Number); + expect(property.interpolationDegree).toEqual(1); + expect(property.interpolationAlgorithm).toEqual(LinearApproximation); + }); + + it('addSamplesPackedArray works', function() { + var data = [0, 7, 1, 8, 2, 9]; + var epoch = new JulianDate(0, 0); + + var property = new SampledProperty(Number); + property.addSamplesPackedArray(data, epoch); + expect(property.getValue(epoch)).toEqual(7); + expect(property.getValue(new JulianDate(0, 0.5))).toEqual(7.5); + }); + + it('addSample works', function() { + var values = [7, 8, 9]; + var times = [new JulianDate(0, 0), new JulianDate(1, 0), new JulianDate(2, 0)]; + + var property = new SampledProperty(Number); + property.addSample(times[0], values[0]); + property.addSample(times[1], values[1]); + property.addSample(times[2], values[2]); + + expect(property.getValue(times[0])).toEqual(values[0]); + expect(property.getValue(times[1])).toEqual(values[1]); + expect(property.getValue(times[2])).toEqual(values[2]); + expect(property.getValue(new JulianDate(0.5, 0))).toEqual(7.5); + }); + + it('addSamples works', function() { + var values = [7, 8, 9]; + var times = [new JulianDate(0, 0), new JulianDate(1, 0), new JulianDate(2, 0)]; + + var property = new SampledProperty(Number); + property.addSamples(times, values); + expect(property.getValue(times[0])).toEqual(values[0]); + expect(property.getValue(times[1])).toEqual(values[1]); + expect(property.getValue(times[2])).toEqual(values[2]); + expect(property.getValue(new JulianDate(0.5, 0))).toEqual(7.5); + }); + + it('works with PackableForInterpolation', function() { + var CustomType = function(value) { + this.x = value; + }; + + CustomType.packedLength = 1; + + CustomType.packedInterpolationLength = 2; + + CustomType.pack = function(value, array, startingIndex) { + array[startingIndex] = value.x; + }; + + CustomType.unpack = function(array, startingIndex, result) { + return array[startingIndex]; + }; + + CustomType.convertPackedArrayForInterpolation = function(packedArray, startingIndex, lastIndex, result) { + for ( var i = 0, len = lastIndex - startingIndex + 1; i < len; i++) { + var offset = i * 2; + result[offset] = packedArray[i] * 0.5; + result[offset + 1] = packedArray[i] * 0.5; + } + }; + + CustomType.unpackInterpolationResult = function(array, sourceArray, firstIndex, lastIndex, result) { + if (!defined(result)) { + result = new CustomType(); + } + result.x = array[0] + array[1]; + return result; + }; + + var values = [new CustomType(0), new CustomType(2), new CustomType(4)]; + var times = [new JulianDate(0, 0), new JulianDate(1, 0), new JulianDate(2, 0)]; + + var property = new SampledProperty(CustomType); + property.addSample(times[0], values[0]); + property.addSample(times[1], values[1]); + property.addSample(times[2], values[2]); + + expect(property.getValue(new JulianDate(0.5, 0)).x).toEqual(1); + }); + + it('can set interpolationAlgorithm and degree', function() { + var data = [0, 7, 2, 9, 4, 11]; + var epoch = new JulianDate(0, 0); + + var timesCalled = 0; + var MockInterpolation = { + type : 'Mock', + getRequiredDataPoints : function(degree) { + return 3; + }, + + interpolateOrderZero : function(x, xTable, yTable, yStride, result) { + expect(x).toEqual(-1); + + expect(xTable.length).toEqual(3); + expect(xTable[0]).toBe(-4); + expect(xTable[1]).toBe(-2); + expect(xTable[2]).toBe(0); + + expect(yTable.length).toEqual(3); + expect(yTable[0]).toBe(7); + expect(yTable[1]).toBe(9); + expect(yTable[2]).toBe(11); + + expect(yStride).toEqual(1); + + expect(result.length).toEqual(1); + + result[0] = 2; + timesCalled++; + return result; + } + }; + + var property = new SampledProperty(Number); + property.addSamplesPackedArray(data, epoch); + expect(property.getValue(epoch)).toEqual(7); + expect(property.getValue(new JulianDate(0, 1))).toEqual(8); + + property.interpolationDegree = 2; + property.interpolationAlgorithm = MockInterpolation; + expect(property.getValue(epoch)).toEqual(7); + expect(property.getValue(new JulianDate(0, 3))).toEqual(2); + + expect(timesCalled).toEqual(1); + }); + + it('Returns undefined if trying to interpolate with less than enough samples.', function() { + var value = 7; + var time = new JulianDate(0, 0); + + var property = new SampledProperty(Number); + property.addSample(time, value); + + expect(property.getValue(time)).toEqual(value); + expect(property.getValue(time.addSeconds(4))).toBeUndefined(); + }); + + it('mergeNewSamples works with huge data sets.', function() { + var times = []; + var values = []; + var epoch = new JulianDate(); + + var data = []; + var expectedTimes = []; + var expectedValues = []; + + for ( var i = 0; i < 200000; i++) { + data.push(i); + data.push(i); + expectedTimes.push(epoch.addSeconds(i)); + expectedValues.push(i); + } + + SampledProperty._mergeNewSamples(epoch, times, values, data, 1); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + it('mergeNewSamples works for sorted non-intersecting data.', function() { + var times = []; + var values = []; + var epoch = new JulianDate(); + + var newData = [0, 'a', 1, 'b', 2, 'c']; + var newData2 = [3, 'd', 4, 'e', 5, 'f']; + + var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; + + SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); + SampledProperty._mergeNewSamples(epoch, times, values, newData2, 1); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + it('mergeNewSamples works for ISO8601 dates', function() { + var times = []; + var values = []; + var epoch = JulianDate.fromIso8601('2010-01-01T12:00:00'); + + var newData = ['2010-01-01T12:00:00', 'a', '2010-01-01T12:00:01', 'b', '2010-01-01T12:00:02', 'c']; + var newData2 = ['2010-01-01T12:00:03', 'd', '2010-01-01T12:00:04', 'e', '2010-01-01T12:00:05', 'f']; + + var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; + + SampledProperty._mergeNewSamples(undefined, times, values, newData, 1); + SampledProperty._mergeNewSamples(undefined, times, values, newData2, 1); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + it('mergeNewSamples works for elements of size 2.', function() { + var times = []; + var values = []; + var epoch = new JulianDate(); + + var newData = [1, 'b', 'b', 4, 'e', 'e', 0, 'a', 'a']; + var newData2 = [2, 'c', 'c', 3, 'd', 'd']; + + var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4)]; + var expectedValues = ['a', 'a', 'b', 'b', 'c', 'c', 'd', 'd', 'e', 'e']; + + SampledProperty._mergeNewSamples(epoch, times, values, newData, 2); + SampledProperty._mergeNewSamples(epoch, times, values, newData2, 2); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + it('mergeNewSamples works for unsorted intersecting data.', function() { + var times = []; + var values = []; + var epoch = new JulianDate(); + + var newData = [1, 'b', 4, 'e', 0, 'a']; + var newData2 = [5, 'f', 2, 'c', 3, 'd']; + + var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(2), epoch.addSeconds(3), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedValues = ['a', 'b', 'c', 'd', 'e', 'f']; + + SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); + SampledProperty._mergeNewSamples(epoch, times, values, newData2, 1); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + it('mergeNewSamples works for data with repeated values.', function() { + var times = []; + var values = []; + var epoch = new JulianDate(); + + var newData = [0, 'a', 1, 'b', 1, 'c', 0, 'd', 4, 'e', 5, 'f']; + var expectedTimes = [epoch.addSeconds(0), epoch.addSeconds(1), epoch.addSeconds(4), epoch.addSeconds(5)]; + var expectedValues = ['d', 'c', 'e', 'f']; + SampledProperty._mergeNewSamples(epoch, times, values, newData, 1); + + expect(times).toEqual(expectedTimes, JulianDate.compare); + expect(values).toEqual(expectedValues); + }); + + var interwovenData = [{ + epoch : JulianDate.fromIso8601("20130205T150405.704999999999927Z"), + values : [0.0, 1, 120.0, 2, 240.0, 3, 360.0, 4, 480.0, 6, 600.0, 8, 720.0, 10, 840.0, 12, 960.0, 14, 1080.0, 16] + }, { + epoch : JulianDate.fromIso8601("20130205T151151.60499999999956Z"), + values : [0.0, 5, 120.0, 7, 240.0, 9, 360.0, 11, 480.0, 13, 600.0, 15, 720.0, 17, 840.0, 18, 960.0, 19, 1080.0, 20] + }]; + + it('mergeNewSamples works with interwoven data', function() { + var times = []; + var values = []; + SampledProperty._mergeNewSamples(interwovenData[0].epoch, times, values, interwovenData[0].values, 1); + SampledProperty._mergeNewSamples(interwovenData[1].epoch, times, values, interwovenData[1].values, 1); + for ( var i = 0; i < values.length; i++) { + expect(values[i]).toBe(i + 1); + } + }); + + it('constructor throws without type parameter.', function() { + expect(function() { + return new SampledProperty(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js b/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js new file mode 100644 index 000000000000..0ebc8ca2aef3 --- /dev/null +++ b/Specs/DynamicScene/TimeIntervalCollectionPositionPropertySpec.js @@ -0,0 +1,129 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/TimeIntervalCollectionPositionProperty', + 'DynamicScene/PositionProperty', + 'Core/Cartesian3', + 'Core/JulianDate', + 'Core/ReferenceFrame', + 'Core/TimeInterval', + 'Core/TimeIntervalCollection' + ], function( + TimeIntervalCollectionPositionProperty, + PositionProperty, + Cartesian3, + JulianDate, + ReferenceFrame, + TimeInterval, + TimeIntervalCollection) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('default constructor has expected values', function() { + var property = new TimeIntervalCollectionPositionProperty(); + expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); + expect(property.getValue(new JulianDate())).toBeUndefined(); + expect(property.referenceFrame).toBe(ReferenceFrame.FIXED); + }); + + it('getValue works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionPositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(result1).not.toBe(interval1.data); + expect(result1).toEqual(interval1.data); + + var result2 = property.getValue(interval2.stop); + expect(result2).not.toBe(interval2.data); + expect(result2).toEqual(interval2.data); + }); + + it('getValue works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionPositionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = new Cartesian3(); + var result1 = property.getValue(interval1.start, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data); + + var result2 = property.getValue(interval2.stop, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data); + }); + + it('getValue returns in fixed frame', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + + var property = new TimeIntervalCollectionPositionProperty(ReferenceFrame.INERTIAL); + property.intervals.addInterval(interval1); + + var valueInertial = new Cartesian3(1, 2, 3); + var valueFixed = PositionProperty.convertToReferenceFrame(interval1.start, valueInertial, ReferenceFrame.INERTIAL, ReferenceFrame.FIXED); + + var result = property.getValue(interval1.start); + expect(result).toEqual(valueFixed); + }); + + it('getValueInReferenceFrame works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionPositionProperty(ReferenceFrame.FIXED); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var valueInertial = PositionProperty.convertToReferenceFrame(interval1.start, interval1.data, ReferenceFrame.FIXED, ReferenceFrame.INERTIAL); + + var expected = new Cartesian3(); + var result1 = property.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(valueInertial); + + var result2 = property.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data); + }); + + it('getValueInReferenceFrame works without a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionPositionProperty(ReferenceFrame.FIXED); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var valueInertial = PositionProperty.convertToReferenceFrame(interval1.start, interval1.data, ReferenceFrame.FIXED, ReferenceFrame.INERTIAL); + + var result1 = property.getValueInReferenceFrame(interval1.start, ReferenceFrame.INERTIAL); + expect(result1).toEqual(valueInertial); + + var result2 = property.getValueInReferenceFrame(interval2.stop, ReferenceFrame.FIXED); + expect(result2).toEqual(interval2.data); + }); + + it('returns undefined for valid interval without data', function() { + var property = new TimeIntervalCollectionPositionProperty(); + + var interval = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, undefined); + property.intervals.addInterval(interval); + + var result = property.getValue(interval.start); + expect(result).toBeUndefined(); + }); + + it('throws with no time parameter', function() { + var property = new TimeIntervalCollectionPositionProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js b/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js new file mode 100644 index 000000000000..10a46aec9942 --- /dev/null +++ b/Specs/DynamicScene/TimeIntervalCollectionPropertySpec.js @@ -0,0 +1,96 @@ +/*global defineSuite*/ +defineSuite([ + 'DynamicScene/TimeIntervalCollectionProperty', + 'Core/Cartesian3', + 'Core/JulianDate', + 'Core/TimeInterval', + 'Core/TimeIntervalCollection' + ], function( + TimeIntervalCollectionProperty, + Cartesian3, + JulianDate, + TimeInterval, + TimeIntervalCollection) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('default constructor has expected values', function() { + var property = new TimeIntervalCollectionProperty(); + expect(property.intervals).toBeInstanceOf(TimeIntervalCollection); + expect(property.getValue(new JulianDate())).toBeUndefined(); + }); + + it('works with basic types', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, 5); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, 6); + + var property = new TimeIntervalCollectionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + expect(property.getValue(interval1.start)).toBe(interval1.data); + expect(property.getValue(interval2.stop)).toBe(interval2.data); + }); + + it('works with non-clonable objects', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, {}); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, {}); + + var timesCalled = 0; + function noClone(value, result) { + timesCalled++; + return value; + } + + var property = new TimeIntervalCollectionProperty(noClone); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + expect(property.getValue(interval1.start)).toBe(interval1.data); + expect(timesCalled).toEqual(1); + expect(property.getValue(interval2.stop)).toBe(interval2.data); + expect(timesCalled).toEqual(2); + }); + + it('works with clonable objects', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var result1 = property.getValue(interval1.start); + expect(result1).not.toBe(interval1.data); + expect(result1).toEqual(interval1.data); + + var result2 = property.getValue(interval2.stop); + expect(result2).not.toBe(interval2.data); + expect(result2).toEqual(interval2.data); + }); + + it('works with a result parameter', function() { + var interval1 = new TimeInterval(new JulianDate(10, 0), new JulianDate(12, 0), true, true, new Cartesian3(1, 2, 3)); + var interval2 = new TimeInterval(new JulianDate(12, 0), new JulianDate(14, 0), false, true, new Cartesian3(4, 5, 6)); + + var property = new TimeIntervalCollectionProperty(); + property.intervals.addInterval(interval1); + property.intervals.addInterval(interval2); + + var expected = new Cartesian3(); + var result1 = property.getValue(interval1.start, expected); + expect(result1).toBe(expected); + expect(result1).toEqual(interval1.data); + + var result2 = property.getValue(interval2.stop, expected); + expect(result2).toBe(expected); + expect(result2).toEqual(interval2.data); + }); + + it('throws with no time parameter', function() { + var property = new TimeIntervalCollectionProperty(); + expect(function() { + property.getValue(undefined); + }).toThrow(); + }); +}); \ No newline at end of file diff --git a/Specs/DynamicScene/VisualizerCollectionSpec.js b/Specs/DynamicScene/VisualizerCollectionSpec.js index e787f2652bcf..a1b336090db8 100644 --- a/Specs/DynamicScene/VisualizerCollectionSpec.js +++ b/Specs/DynamicScene/VisualizerCollectionSpec.js @@ -2,13 +2,11 @@ defineSuite([ 'DynamicScene/VisualizerCollection', 'Core/JulianDate', - 'DynamicScene/CzmlDefaults', 'Specs/createScene', 'Specs/destroyScene' ], function( VisualizerCollection, JulianDate, - CzmlDefaults, createScene, destroyScene) { "use strict"; @@ -56,28 +54,6 @@ defineSuite([ expect(mockVisualizer.mockCollection).toEqual(mockCollection); }); - it('createCzmlStandardCollection uses CzmlDefaults', function() { - var scene = createScene(); - var visualizers = VisualizerCollection.createCzmlStandardCollection(scene); - var expected = CzmlDefaults.createVisualizers(scene); - - //Simple sanity check to make sure VisualizerCollection is using the correct defaults. - var collection = visualizers.getVisualizers(); - for ( var i = 0; i < expected.length; i++) { - expect(collection[i].prototype).toEqual(expected[i].prototype); - expected[i].destroy(); - } - - visualizers = visualizers && visualizers.destroy(); - destroyScene(scene); - }); - - it('createCzmlStandardCollection throws without a scene', function() { - expect(function() { - return VisualizerCollection.createCzmlStandardCollection(undefined, new MockDynamicObjectCollection()); - }).toThrow(); - }); - it('Constructor assigns expected paramters to properies', function() { var mockVisualizer = new MockVisualizer(); var mockCollection = new MockDynamicObjectCollection(); diff --git a/Specs/DynamicScene/processCzmlSpec.js b/Specs/DynamicScene/processCzmlSpec.js deleted file mode 100644 index 30bbb8fac0c4..000000000000 --- a/Specs/DynamicScene/processCzmlSpec.js +++ /dev/null @@ -1,143 +0,0 @@ -/*global defineSuite*/ -defineSuite([ - 'DynamicScene/processCzml', - 'DynamicScene/DynamicObjectCollection', - 'DynamicScene/DynamicBillboard', - 'Core/JulianDate' - ], function( - processCzml, - DynamicObjectCollection, - DynamicBillboard, - JulianDate) { - "use strict"; - /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - - var czml = { - 'id' : 'test', - 'billboard' : { - 'show' : true - }, - 'label' : { - 'show' : false - } - }; - - var czmlDelete = { - 'id' : 'test', - 'delete': true - }; - - var czmlArray = [{ - 'id' : 'test', - 'billboard' : { - 'show' : true - } - }, { - 'id' : 'test', - 'label' : { - 'show' : false - } - }]; - - var czmlNoId = { - 'billboard' : { - 'show' : true - } - }; - - it('processCzml throws if czml is undefined', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - expect(function() { - processCzml(undefined, dynamicObjectCollection); - }).toThrow(); - }); - - it('processCzml throws if dynamicObjectCollection is undefined', function() { - expect(function() { - processCzml(czml, undefined); - }).toThrow(); - }); - - it('processCzml populates dynamicObjectCollection with expected data for an array of packets', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - processCzml(czmlArray, dynamicObjectCollection); - - var testObject = dynamicObjectCollection.getObject('test'); - expect(testObject).toBeDefined(); - expect(testObject.billboard).toBeDefined(); - expect(testObject.billboard.show).toBeDefined(); - expect(testObject.billboard.show.getValue(new JulianDate())).toEqual(true); - expect(testObject.label).toBeDefined(); - expect(testObject.label.show).toBeDefined(); - expect(testObject.label.show.getValue(new JulianDate())).toEqual(false); - }); - - it('processCzml deletes an existing object.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - processCzml(czml, dynamicObjectCollection); - - var objects = dynamicObjectCollection.getObjects(); - expect(objects.length).toEqual(1); - - processCzml(czmlDelete, dynamicObjectCollection); - expect(dynamicObjectCollection.getObjects().length).toEqual(0); - expect(dynamicObjectCollection.getObject('test')).toBeUndefined(); - }); - - it('processCzml populates dynamicObjectCollection with expected data for a single packet', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - processCzml(czml, dynamicObjectCollection); - - var testObject = dynamicObjectCollection.getObject('test'); - expect(testObject).toBeDefined(); - expect(testObject.billboard).toBeDefined(); - expect(testObject.billboard.show).toBeDefined(); - expect(testObject.billboard.show.getValue(new JulianDate())).toEqual(true); - expect(testObject.label).toBeDefined(); - expect(testObject.label.show).toBeDefined(); - expect(testObject.label.show.getValue(new JulianDate())).toEqual(false); - }); - - it('processCzml uses user-supplied updater functions', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - processCzml(czml, dynamicObjectCollection, undefined, [DynamicBillboard.processCzmlPacket]); - - var testObject = dynamicObjectCollection.getObject('test'); - expect(testObject).toBeDefined(); - expect(testObject.billboard).toBeDefined(); - expect(testObject.billboard.show).toBeDefined(); - expect(testObject.billboard.show.getValue(new JulianDate())).toEqual(true); - expect(testObject.label).toBeUndefined(); - }); - - it('processCzml raises dynamicObjectCollection event', function() { - var eventTriggered = false; - var dynamicObjectCollection = new DynamicObjectCollection(); - dynamicObjectCollection.objectPropertiesChanged.addEventListener(function(dynamicObjectCollectionParam, updatedObjects) { - expect(dynamicObjectCollectionParam).toEqual(dynamicObjectCollection); - expect(updatedObjects.length).toEqual(1); - expect(updatedObjects[0]).toEqual(dynamicObjectCollection.getObject('test')); - expect(eventTriggered).toEqual(false); - eventTriggered = true; - }); - processCzml(czml, dynamicObjectCollection); - waitsFor(function() { - return eventTriggered; - }); - }); - - it('processCzml creates a new object for packets with no id.', function() { - var dynamicObjectCollection = new DynamicObjectCollection(); - processCzml(czmlNoId, dynamicObjectCollection); - - var objects = dynamicObjectCollection.getObjects(); - expect(objects.length).toEqual(1); - var testObject = objects[0]; - expect(testObject).toBeDefined(); - expect(testObject.id).toBeDefined(); - expect(testObject.billboard).toBeDefined(); - expect(testObject.billboard.show).toBeDefined(); - expect(testObject.billboard.show.getValue(new JulianDate())).toEqual(true); - }); - -}); \ No newline at end of file diff --git a/Specs/MockProperty.js b/Specs/MockProperty.js deleted file mode 100644 index 3537d380317f..000000000000 --- a/Specs/MockProperty.js +++ /dev/null @@ -1,49 +0,0 @@ -/*global define*/ -define([ - 'Core/defined', - 'Core/ReferenceFrame' - ], function( - defined, - ReferenceFrame) { - "use strict"; - - function MockProperty(value) { - this.value = value; - } - - MockProperty.prototype.getValue = function(time, result) { - if (defined(this.value) && typeof this.value.clone === 'function') { - return this.value.clone(result); - } - return this.value; - }; - - MockProperty.prototype.getValueCartesian = function(time, result) { - if (defined(this.value) && typeof this.value.clone === 'function') { - return this.value.clone(result); - } - return this.value; - }; - - MockProperty.prototype.getValueSpherical = function(time, result) { - if (defined(this.value) && typeof this.value.clone === 'function') { - return this.value.clone(result); - } - return this.value; - }; - - MockProperty.prototype._getReferenceFrame = function() { - return ReferenceFrame.FIXED; - }; - - MockProperty.prototype.getValueRangeCartesian = function(start, stop, currentTime, result) { - this.lastStart = start; - this.lastStop = stop; - this.lastCurrentTime = currentTime; - return this.value; - }; - - MockProperty.prototype._getValueRangeInReferenceFrame = MockProperty.prototype.getValueRangeCartesian; - - return MockProperty; -}); \ No newline at end of file diff --git a/Specs/UndefinedProperty.js b/Specs/UndefinedProperty.js new file mode 100644 index 000000000000..2a525029962d --- /dev/null +++ b/Specs/UndefinedProperty.js @@ -0,0 +1,15 @@ +/*global define*/ +define(['../Core/defineProperties'], function(defineProperties) { + "use strict"; + + //A Property that always returns undefined. + + var UndefinedProperty = function() { + }; + + UndefinedProperty.prototype.getValue = function(time, result) { + return undefined; + }; + + return UndefinedProperty; +}); diff --git a/Specs/Widgets/Viewer/viewerDynamicObjectMixinSpec.js b/Specs/Widgets/Viewer/viewerDynamicObjectMixinSpec.js index eeabad1170c3..39b58353dcc2 100644 --- a/Specs/Widgets/Viewer/viewerDynamicObjectMixinSpec.js +++ b/Specs/Widgets/Viewer/viewerDynamicObjectMixinSpec.js @@ -4,14 +4,14 @@ defineSuite([ 'Core/Cartesian3', 'DynamicScene/DynamicObject', 'Scene/CameraFlightPath', - 'Specs/MockProperty', + 'DynamicScene/ConstantProperty', 'Widgets/Viewer/Viewer' ], function( viewerDynamicObjectMixin, Cartesian3, DynamicObject, CameraFlightPath, - MockProperty, + ConstantProperty, Viewer) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -44,7 +44,7 @@ defineSuite([ viewer.extend(viewerDynamicObjectMixin); var dynamicObject = new DynamicObject(); - dynamicObject.position = new MockProperty(new Cartesian3(123456, 123456, 123456)); + dynamicObject.position = new ConstantProperty(new Cartesian3(123456, 123456, 123456)); viewer.trackedObject = dynamicObject; expect(viewer.trackedObject).toBe(dynamicObject); @@ -58,7 +58,7 @@ defineSuite([ viewer.extend(viewerDynamicObjectMixin); var dynamicObject = new DynamicObject(); - dynamicObject.position = new MockProperty(new Cartesian3(123456, 123456, 123456)); + dynamicObject.position = new ConstantProperty(new Cartesian3(123456, 123456, 123456)); viewer.trackedObject = dynamicObject; expect(viewer.trackedObject).toBe(dynamicObject); diff --git a/Specs/createPackableSpecs.js b/Specs/createPackableSpecs.js new file mode 100644 index 000000000000..9d45d1134aaa --- /dev/null +++ b/Specs/createPackableSpecs.js @@ -0,0 +1,53 @@ +/*global define*/ +define(function() { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + function createPackableSpecs(packable, instance, packedInstance) { + it('can pack', function() { + var packedArray = []; + packable.pack(instance, packedArray); + expect(packedArray.length).toEqual(packable.packedLength); + expect(packedArray).toEqual(packedInstance); + }); + + it('can unpack', function() { + var result = packable.unpack(packedInstance); + expect(result).toEqual(instance); + }); + + it('can pack with startingIndex', function() { + var packedArray = [0]; + var expected = packedArray.concat(packedInstance); + packable.pack(instance, packedArray, 1); + expect(packedArray).toEqual(expected); + }); + + it('can unpack with startingIndex', function() { + var packedArray = [0].concat(packedInstance); + var result = packable.unpack(packedArray, 1); + expect(instance).toEqual(result); + }); + + it('pack throws with undefined value', function() { + var array = []; + expect(function() { + packable.pack(undefined, array); + }).toThrow(); + }); + + it('pack throws with undefined array', function() { + expect(function() { + packable.pack(instance, undefined); + }).toThrow(); + }); + + it('unpack throws with undefined array', function() { + expect(function() { + packable.unpack(undefined); + }).toThrow(); + }); + } + + return createPackableSpecs; +});